Skip to content

Commit

Permalink
chore: GitHub Actions (#15)
Browse files Browse the repository at this point in the history
* Backend: linting, formatting
* Frontend: linting, formatting
* Runner: Docker image build
  • Loading branch information
cbolles authored Nov 20, 2024
1 parent 4053dd2 commit e25190c
Show file tree
Hide file tree
Showing 55 changed files with 1,136 additions and 880 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: backend

on:
workflow_dispatch:
push:
paths:
- 'packages/backend/**'
branches:
- main
tags:
- "v*.*.*"
pull_request:
paths:
- 'packages/backend/**'
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
name: Check for Linting Errors
defaults:
run:
working-directory: packages/backend
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 22

- name: NPM Install
run: npm install --only=dev
shell: bash

- name: Check for Formatting Issues
run: npm run format

- name: Check for Linting Issues
run: npm run lint

build:
runs-on: ubuntu-latest
name: Build Code
defaults:
run:
working-directory: packages/backend
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 22

- name: NPM Install
run: npm install
shell: bash

- name: Build
run: npm run build
66 changes: 66 additions & 0 deletions .github/workflows/frontend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: frontend

on:
workflow_dispatch:
push:
paths:
- 'packages/frontend/**'
branches:
- main
tags:
- "v*.*.*"
pull_request:
paths:
- 'packages/frontend/**'
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
name: Check for Linting Errors
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 22

- name: NPM Install
run: npm install --only=dev
shell: bash

- name: Check for Formatting Issues
run: npm run format

- name: Check for Linting Issues
run: npm run lint

build:
runs-on: ubuntu-latest
name: Build Code
defaults:
run:
working-directory: packages/frontend
steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: 22

- name: NPM Install
run: npm install
shell: bash

- name: Build
run: npm run build
60 changes: 60 additions & 0 deletions .github/workflows/runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: runner

on:
workflow_dispatch:
push:
paths:
- 'packages/runner/**'
branches:
- main
tags:
- "v*.*.*"
pull_request:
paths:
- 'packages/runner/**'
branches:
- main

jobs:
docker:
name: Docker Build and Push
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/runner
steps:
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2

- name: Checkout repository
uses: actions/checkout@v3

- name: Docker Tags
id: meta
uses: docker/metadata-action@v4
with:
images: |
hicsail/comets-runner
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
- name: Login to Docker Hub
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build & Push Docker Build
uses: docker/build-push-action@v4
with:
push: ${{ github.event_name != 'pull_request' }}
context: ./packages/runner
file: ./packages/runner/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=gateway
cache-to: type=gha,mode=max,scope=gateway
13 changes: 12 additions & 1 deletion packages/backend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
Expand All @@ -21,5 +21,16 @@ module.exports = {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn", // or "error"
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
]
},
};
5 changes: 3 additions & 2 deletions packages/backend/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"singleQuote": true,
"trailingComma": "all"
}
"trailingComma": "none",
"printWidth": 120
}
6 changes: 4 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"format": "prettier \"src/**/*.ts\" \"test/**/*.ts\"",
"format:fix": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ExpressAdapter } from '@bull-board/express';
import { S3Module } from './s3/s3.module';
import { EmailModule } from './email/email.module';


@Module({
imports: [
GraphQLModule.forRoot<ApolloDriverConfig>({
Expand Down Expand Up @@ -49,6 +48,6 @@ import { EmailModule } from './email/email.module';
JobModule,
S3Module,
EmailModule
],
]
})
export class AppModule {}
6 changes: 3 additions & 3 deletions packages/backend/src/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class EmailService {
to: email,
subject: 'Your COMETS SI simulation has been completed successfully',
text: `Click here to view the results of your simulation: ${this.frontendURL}/results/${id}`
}
};
await this.transporter.sendMail(mailOptions);
}

Expand All @@ -39,7 +39,7 @@ export class EmailService {
to: email,
subject: 'COMETS Simulation Failed to Run',
text: `Unfortunately your requested simulation has failed to run. We are looking into the issue now!`
}
};
await this.transporter.sendMail(mailOptions);
}

Expand All @@ -66,7 +66,7 @@ export class EmailService {
to: this.internalEmail,
subject: 'COMETS Simulation Failed',
text: message
}
};
await this.transporter.sendMail(mailOptions);
}
}
1 change: 0 additions & 1 deletion packages/backend/src/email/transport.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Provider } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Transporter, createTransport } from 'nodemailer';


export const TRANSPORT_PROVIDER = 'TRANSPORT_PROVIDER';

export const transportProvider: Provider<Transporter> = {
Expand Down
14 changes: 6 additions & 8 deletions packages/backend/src/job/converter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
} from './comets-paramters.dto';
import { LayoutType, SimulationRequest } from '../simulation/models/request.model';


@Injectable()
export class RequestConverter {

private readonly GRID_SIZE = 61;
private readonly PETRI_DISH_DIAMETER = 3.0;

Expand All @@ -23,7 +21,7 @@ export class RequestConverter {
globalParams: await this.getGlobalParams(request),
s3Folder: await this.getS3Folder(request),
requestID: await this.getRequestID(request)
}
};
}

private async getLayoutParams(request: SimulationRequest): Promise<CometsLayoutParameters> {
Expand All @@ -39,7 +37,7 @@ export class RequestConverter {
type: request.layoutParams.type,
spaceWidth: spaceWidth,
gridSize: gridSize
}
};
}

private async getMetaboliteParams(request: SimulationRequest): Promise<CometsMetaboliteParameters> {
Expand All @@ -48,15 +46,15 @@ export class RequestConverter {
metaboliteAmount = request.layoutParams.volume * request.metaboliteParams.concentration;
} else {
const spaceWidth = this.PETRI_DISH_DIAMETER / this.GRID_SIZE;
const area = Math.PI * Math.pow(0.5 * this.PETRI_DISH_DIAMETER, 2)
metaboliteAmount = request.metaboliteParams.concentration * request.layoutParams.volume *
Math.pow(spaceWidth, 2) / area;
const area = Math.PI * Math.pow(0.5 * this.PETRI_DISH_DIAMETER, 2);
metaboliteAmount =
(request.metaboliteParams.concentration * request.layoutParams.volume * Math.pow(spaceWidth, 2)) / area;
}

return {
type: request.metaboliteParams.type,
amount: metaboliteAmount
}
};
}

private async getModelParams(request: SimulationRequest): Promise<CometsModelParamters[]> {
Expand Down
15 changes: 11 additions & 4 deletions packages/backend/src/job/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class JobService {
this.jobTemplate.spec.template.spec.restartPolicy = 'Never';
this.jobTemplate.spec.backoffLimit = 0;
this.jobTemplate.spec.template.spec.imagePullSecrets = [new V1LocalObjectReference()];
this.jobTemplate.spec.template.spec.imagePullSecrets![0].name = this.configService.getOrThrow<string>('runner.imagePullSecret')
this.jobTemplate.spec.template.spec.imagePullSecrets[0].name =
this.configService.getOrThrow<string>('runner.imagePullSecret');
}

async triggerJob(request: SimulationRequest): Promise<string> {
Expand Down Expand Up @@ -111,8 +112,14 @@ export class JobService {
}

async getPodLogs(jobName: string): Promise<string> {
const pods = await this.coreClient.listNamespacedPod(this.namespace,
undefined, undefined, undefined, undefined, `batch.kubernetes.io/job-name=${jobName}`);
const pods = await this.coreClient.listNamespacedPod(
this.namespace,
undefined,
undefined,
undefined,
undefined,
`batch.kubernetes.io/job-name=${jobName}`
);
const podName = pods.body!.items[0].metadata!.name;

const logs = await this.coreClient.readNamespacedPodLog(podName!, this.namespace);
Expand Down Expand Up @@ -154,6 +161,6 @@ export class JobService {
`--default-v-max=${parameters.globalParams.defaultVMax}`,
`--default-km=${parameters.globalParams.defaultKm}`,
`--max-cycles=${parameters.globalParams.maxCycles}`
]
];
}
}
Loading

0 comments on commit e25190c

Please sign in to comment.