From 3173decc4f0961db2eb42b0521ec2c3393580f0b Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 10:58:15 -0700 Subject: [PATCH 1/9] feat: adding health check --- .github/workflows/merge-main.yml | 8 +-- .github/workflows/pr-open.yml | 4 +- backend/package-lock.json | 84 ------------------------------ backend/src/app.controller.spec.ts | 4 +- backend/src/app.controller.ts | 10 +++- backend/src/app.service.ts | 27 +++++++++- 6 files changed, 42 insertions(+), 95 deletions(-) diff --git a/.github/workflows/merge-main.yml b/.github/workflows/merge-main.yml index 83bab110..7c93393f 100644 --- a/.github/workflows/merge-main.yml +++ b/.github/workflows/merge-main.yml @@ -85,7 +85,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.2 + uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: file: .github/openshift/deploy.database.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} @@ -107,7 +107,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.2 + uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: file: .github/openshift/deploy.backend.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} @@ -138,7 +138,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.2 + uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: file: .github/openshift/deploy.database.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} @@ -161,7 +161,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.2 + uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: file: .github/openshift/deploy.backend.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 748995b8..ecbd7b59 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -118,7 +118,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.2 + uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: file: .github/openshift/deploy.database.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} @@ -138,7 +138,7 @@ jobs: - uses: actions/checkout@v3 - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.2 + uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: file: .github/openshift/deploy.backend.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} diff --git a/backend/package-lock.json b/backend/package-lock.json index 2da5183d..7f1f6508 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -39,23 +39,13 @@ "@types/jest": "^29.4.0", "@types/node": "^18.14.1", "@types/supertest": "^2.0.12", -<<<<<<< HEAD "@typescript-eslint/eslint-plugin": "^5.54.1", - "@typescript-eslint/parser": "^5.53.0", -======= - "@typescript-eslint/eslint-plugin": "^5.39.0", "@typescript-eslint/parser": "^5.54.1", ->>>>>>> 70b9d6b (Backend(deps-dev): Bump @typescript-eslint/parser in /backend) "eslint": "^8.24.0", "eslint-config-prettier": "^8.5.0", "eslint-plugin-prettier": "^4.2.1", -<<<<<<< HEAD "jest": "^29.5.0", - "prettier": "^2.7.1", -======= - "jest": "^29.4.3", "prettier": "^2.8.4", ->>>>>>> 438672e (Backend(deps-dev): Bump prettier from 2.7.1 to 2.8.4 in /backend) "source-map-support": "^0.5.21", "supertest": "^6.3.0", "ts-jest": "^29.0.3", @@ -2488,23 +2478,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/scope-manager": { - "version": "5.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.54.0.tgz", - "integrity": "sha512-VTPYNZ7vaWtYna9M4oD42zENOBrb+ZYyCNdFs949GcN8Miwn37b8b7eMj+EZaq7VK9fx0Jd+JhmkhjFhvnovhg==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "5.54.0", - "@typescript-eslint/visitor-keys": "5.54.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@typescript-eslint/type-utils": { "version": "5.54.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.54.1.tgz", @@ -2589,46 +2562,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/types": { - "version": "5.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.54.0.tgz", - "integrity": "sha512-nExy+fDCBEgqblasfeE3aQ3NuafBUxZxgxXcYfzYRZFHdVvk5q60KhCSkG0noHgHRo/xQ/BOzURLZAafFpTkmQ==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, - "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.54.0.tgz", - "integrity": "sha512-X2rJG97Wj/VRo5YxJ8Qx26Zqf0RRKsVHd4sav8NElhbZzhpBI8jU54i6hfo9eheumj4oO4dcRN1B/zIVEqR/MQ==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "5.54.0", - "@typescript-eslint/visitor-keys": "5.54.0", - "debug": "^4.3.4", - "globby": "^11.1.0", - "is-glob": "^4.0.3", - "semver": "^7.3.7", - "tsutils": "^3.21.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } - } - }, "node_modules/@typescript-eslint/utils": { "version": "5.54.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.54.1.tgz", @@ -2729,23 +2662,6 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.54.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.54.0.tgz", - "integrity": "sha512-xu4wT7aRCakGINTLGeyGqDn+78BwFlggwBjnHa1ar/KaGagnmwLYmlrXIrgAaQ3AE1Vd6nLfKASm7LrFHNbKGA==", - "dev": true, - "dependencies": { - "@typescript-eslint/types": "5.54.0", - "eslint-visitor-keys": "^3.3.0" - }, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" - } - }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.1.tgz", diff --git a/backend/src/app.controller.spec.ts b/backend/src/app.controller.spec.ts index d22f3890..974888ed 100644 --- a/backend/src/app.controller.spec.ts +++ b/backend/src/app.controller.spec.ts @@ -15,8 +15,8 @@ describe('AppController', () => { }); describe('root', () => { - it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); + it('should return "Ok"', () => { + expect(appController.getHello()).toBe('Ok'); }); }); }); diff --git a/backend/src/app.controller.ts b/backend/src/app.controller.ts index cce879ee..5016445a 100644 --- a/backend/src/app.controller.ts +++ b/backend/src/app.controller.ts @@ -3,10 +3,18 @@ import { AppService } from './app.service'; @Controller() export class AppController { - constructor(private readonly appService: AppService) {} + constructor(private readonly appService: AppService) { } @Get() getHello(): string { return this.appService.getHello(); } + + @Get('check') + getCheck(): string { + return this.appService.getToken().then((response) => { + console.log(response); + return 'Ok'; + }); + } } diff --git a/backend/src/app.service.ts b/backend/src/app.service.ts index 927d7cca..27504d97 100644 --- a/backend/src/app.service.ts +++ b/backend/src/app.service.ts @@ -1,8 +1,31 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; +import axios from 'axios'; +const oauth = require('axios-oauth-client'); @Injectable() export class AppService { getHello(): string { - return 'Hello World!'; + return 'Ok'; + } + + getToken() { + const getClientCredentials = oauth.client(axios.create(), { + url: process.env.CHES_TOKEN_URL, + grant_type: 'client_credentials', + client_id: process.env.CHES_CLIENT_ID, + client_secret: process.env.CHES_CLIENT_SECRET, + }); + + return getClientCredentials() + .then((res) => { + if (res && res.access_token) return res.access_token; + else return null; + }) + .catch((e) => { + throw new HttpException( + `Failed to get email auth token from API: ${e}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + }); } } From 8c1a00fb37270679aef04bccf29e0c9e21b51b3e Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Tue, 25 Apr 2023 11:44:01 -0700 Subject: [PATCH 2/9] Improved code --- backend/src/app.service.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/backend/src/app.service.ts b/backend/src/app.service.ts index 27504d97..8621c3e5 100644 --- a/backend/src/app.service.ts +++ b/backend/src/app.service.ts @@ -9,17 +9,24 @@ export class AppService { } getToken() { + const tokenUrl = process.env.CHES_TOKEN_URL; + const clientId = process.env.CHES_CLIENT_ID; + const clientSecret = process.env.CHES_CLIENT_SECRET; + const getClientCredentials = oauth.client(axios.create(), { - url: process.env.CHES_TOKEN_URL, + url: tokenUrl, grant_type: 'client_credentials', - client_id: process.env.CHES_CLIENT_ID, - client_secret: process.env.CHES_CLIENT_SECRET, + client_id: clientId, + client_secret: clientSecret, }); return getClientCredentials() .then((res) => { - if (res && res.access_token) return res.access_token; - else return null; + if (res && res.access_token) { + return res.access_token; + } else { + return null; + } }) .catch((e) => { throw new HttpException( From 98ea8017ac9fba4c62205cdacc6763dcc741a41a Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 12:05:44 -0700 Subject: [PATCH 3/9] fix: fixing tests and dups --- backend/src/app.controller.spec.ts | 3 +- backend/src/app.controller.ts | 5 +- backend/src/app.module.ts | 5 +- backend/src/app.service.ts | 33 ++---- backend/src/email/email.module.ts | 5 +- backend/src/email/services/email.service.ts | 107 +------------------- backend/test/app.e2e-spec.ts | 2 +- 7 files changed, 20 insertions(+), 140 deletions(-) diff --git a/backend/src/app.controller.spec.ts b/backend/src/app.controller.spec.ts index 974888ed..d45f7067 100644 --- a/backend/src/app.controller.spec.ts +++ b/backend/src/app.controller.spec.ts @@ -1,6 +1,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AppController } from './app.controller'; import { AppService } from './app.service'; +import { ChesService } from './ches/services/ches.service'; describe('AppController', () => { let appController: AppController; @@ -8,7 +9,7 @@ describe('AppController', () => { beforeEach(async () => { const app: TestingModule = await Test.createTestingModule({ controllers: [AppController], - providers: [AppService], + providers: [AppService, ChesService], }).compile(); appController = app.get(AppController); diff --git a/backend/src/app.controller.ts b/backend/src/app.controller.ts index 5016445a..f0998ebc 100644 --- a/backend/src/app.controller.ts +++ b/backend/src/app.controller.ts @@ -12,9 +12,6 @@ export class AppController { @Get('check') getCheck(): string { - return this.appService.getToken().then((response) => { - console.log(response); - return 'Ok'; - }); + return this.appService.getToken(); } } diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index c7227fab..a076aca1 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -5,6 +5,7 @@ import { ScheduleModule } from '@nestjs/schedule'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { FormModule } from './form/form.module'; +import { ChesService } from './ches/services/ches.service'; @Module({ imports: [ @@ -23,6 +24,6 @@ import { FormModule } from './form/form.module'; FormModule, ], controllers: [AppController], - providers: [AppService], + providers: [AppService, ChesService], }) -export class AppModule {} +export class AppModule { } diff --git a/backend/src/app.service.ts b/backend/src/app.service.ts index 8621c3e5..3ba2df72 100644 --- a/backend/src/app.service.ts +++ b/backend/src/app.service.ts @@ -1,38 +1,17 @@ -import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; -import axios from 'axios'; -const oauth = require('axios-oauth-client'); +import { Injectable } from '@nestjs/common'; +import { ChesService } from './ches/services/ches.service'; @Injectable() export class AppService { + constructor(private chesService: ChesService) { } getHello(): string { return 'Ok'; } getToken() { - const tokenUrl = process.env.CHES_TOKEN_URL; - const clientId = process.env.CHES_CLIENT_ID; - const clientSecret = process.env.CHES_CLIENT_SECRET; - - const getClientCredentials = oauth.client(axios.create(), { - url: tokenUrl, - grant_type: 'client_credentials', - client_id: clientId, - client_secret: clientSecret, + return this.chesService.getToken().then((response) => { + console.log(response); + return 'Ok'; }); - - return getClientCredentials() - .then((res) => { - if (res && res.access_token) { - return res.access_token; - } else { - return null; - } - }) - .catch((e) => { - throw new HttpException( - `Failed to get email auth token from API: ${e}`, - HttpStatus.INTERNAL_SERVER_ERROR, - ); - }); } } diff --git a/backend/src/email/email.module.ts b/backend/src/email/email.module.ts index 8c542152..0e21958d 100644 --- a/backend/src/email/email.module.ts +++ b/backend/src/email/email.module.ts @@ -2,11 +2,12 @@ import { Module } from '@nestjs/common'; import { HttpModule } from '@nestjs/axios'; import { EmailService } from './services/email.service'; import { EmailController } from './controllers/email.controller'; +import { ChesService } from '../ches/services/ches.service'; @Module({ imports: [HttpModule], controllers: [EmailController], - providers: [EmailService], + providers: [EmailService, ChesService], exports: [EmailService], }) -export class EmailModule {} +export class EmailModule { } diff --git a/backend/src/email/services/email.service.ts b/backend/src/email/services/email.service.ts index f1d9bfe7..dfcad06b 100644 --- a/backend/src/email/services/email.service.ts +++ b/backend/src/email/services/email.service.ts @@ -1,111 +1,12 @@ -import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; -import { HttpService } from '@nestjs/axios'; -import axios from 'axios'; +import { Injectable } from '@nestjs/common'; import { EmailEntity } from '../model/email.entity'; - -const oauth = require('axios-oauth-client'); +import { ChesService } from '../../ches/services/ches.service'; @Injectable() export class EmailService { - constructor(private httpService: HttpService) {} - - getToken() { - const getClientCredentials = oauth.client(axios.create(), { - url: process.env.CHES_TOKEN_URL, - grant_type: 'client_credentials', - client_id: process.env.CHES_CLIENT_ID, - client_secret: process.env.CHES_CLIENT_SECRET, - }); - - return getClientCredentials() - .then((res) => { - if (res && res.access_token) return res.access_token; - else return null; - }) - .catch((e) => { - throw new HttpException( - `Failed to get email auth token from API: ${e}`, - HttpStatus.INTERNAL_SERVER_ERROR, - ); - }); - } + constructor(private chesService: ChesService) { } sendEmail(email: EmailEntity) { - const emailTo = email.emailTo; - const emailFrom = email.emailFrom || process.env.CHES_EMAIL_FROM; - const emailSubject = email.emailSubject || 'test email'; - const emailBody = email.emailBody || 'hello world'; - const emailBodyType = email.emailBodyType || 'text'; - const emailAttachments = email.emailAttachments || []; - - if ( - !process.env.CHES_TOKEN_URL || - !process.env.CHES_API_URL || - !process.env.CHES_EMAIL_FROM - ) { - throw new HttpException( - 'Failed to config email, server side missing config of authentication url' + - 'or CHES email server url or from email address', - HttpStatus.BAD_REQUEST, - ); - } - - if (!emailTo) { - throw new HttpException( - 'Failed to send email, missing required emailTo parameter', - HttpStatus.BAD_REQUEST, - ); - } - - return this.getToken() - .then((access_token) => { - if (access_token) { - if (process.env.NODE_ENV == 'production') { - return axios - .post( - `${process.env.CHES_API_URL}/email`, - { - bcc: [], - bodyType: emailBodyType, - body: emailBody, - cc: [], - delayTS: 0, - encoding: 'utf-8', - from: emailFrom, - priority: 'normal', - subject: emailSubject, - to: emailTo, - attachments: emailAttachments, - }, - { - headers: { - Authorization: `Bearer ${access_token}`, - }, - }, - ) - .then((r) => { - return { status: r.status, data: r.data }; - }) - .catch((e) => { - throw new HttpException( - `Failed to post email to API: ${e}`, - HttpStatus.INTERNAL_SERVER_ERROR, - ); - }); - } else { - return { - status: 200, - data: 'Not send email in dev deployment', - }; - } - } - throw new HttpException( - 'Failed to get email auth token: response or response access token is null', - HttpStatus.BAD_REQUEST, - ); - }) - .catch((e) => { - throw new HttpException(e, HttpStatus.INTERNAL_SERVER_ERROR); - }); + return this.chesService.sendEmail(email); } } diff --git a/backend/test/app.e2e-spec.ts b/backend/test/app.e2e-spec.ts index 50cda623..a347697f 100644 --- a/backend/test/app.e2e-spec.ts +++ b/backend/test/app.e2e-spec.ts @@ -19,6 +19,6 @@ describe('AppController (e2e)', () => { return request(app.getHttpServer()) .get('/') .expect(200) - .expect('Hello World!'); + .expect('Ok'); }); }); From 6d18806b584ad1d9ddb13ed36aa18b17ba415aca Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 12:07:42 -0700 Subject: [PATCH 4/9] fix: fixing tests and dups --- backend/src/ches/ches.module.ts | 10 ++ backend/src/ches/services/ches.service.ts | 110 ++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 backend/src/ches/ches.module.ts create mode 100644 backend/src/ches/services/ches.service.ts diff --git a/backend/src/ches/ches.module.ts b/backend/src/ches/ches.module.ts new file mode 100644 index 00000000..6571e76b --- /dev/null +++ b/backend/src/ches/ches.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { HttpModule } from '@nestjs/axios'; +import { ChesService } from './services/ches.service'; + +@Module({ + imports: [HttpModule], + providers: [ChesService], + exports: [ChesService], +}) +export class ChesModule { } diff --git a/backend/src/ches/services/ches.service.ts b/backend/src/ches/services/ches.service.ts new file mode 100644 index 00000000..98b4122a --- /dev/null +++ b/backend/src/ches/services/ches.service.ts @@ -0,0 +1,110 @@ +import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; +import axios from 'axios'; +import { EmailEntity } from '../../email/model/email.entity'; + +const oauth = require('axios-oauth-client'); + +@Injectable() +export class ChesService { + constructor() { } + + getToken() { + const getClientCredentials = oauth.client(axios.create(), { + url: process.env.CHES_TOKEN_URL, + grant_type: 'client_credentials', + client_id: process.env.CHES_CLIENT_ID, + client_secret: process.env.CHES_CLIENT_SECRET, + }); + + return getClientCredentials() + .then((res) => { + if (res && res.access_token) return res.access_token; + else return null; + }) + .catch((e) => { + throw new HttpException( + `Failed to get email auth token from API: ${e}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + }); + } + + sendEmail(email: EmailEntity) { + const emailTo = email.emailTo; + const emailFrom = email.emailFrom || process.env.CHES_EMAIL_FROM; + const emailSubject = email.emailSubject || 'test email'; + const emailBody = email.emailBody || 'hello world'; + const emailBodyType = email.emailBodyType || 'text'; + const emailAttachments = email.emailAttachments || []; + + if ( + !process.env.CHES_TOKEN_URL || + !process.env.CHES_API_URL || + !process.env.CHES_EMAIL_FROM + ) { + throw new HttpException( + 'Failed to config email, server side missing config of authentication url' + + 'or CHES email server url or from email address', + HttpStatus.BAD_REQUEST, + ); + } + + if (!emailTo) { + throw new HttpException( + 'Failed to send email, missing required emailTo parameter', + HttpStatus.BAD_REQUEST, + ); + } + + return this.getToken() + .then((access_token) => { + if (access_token) { + if (process.env.NODE_ENV == 'production') { + return axios + .post( + `${process.env.CHES_API_URL}/email`, + { + bcc: [], + bodyType: emailBodyType, + body: emailBody, + cc: [], + delayTS: 0, + encoding: 'utf-8', + from: emailFrom, + priority: 'normal', + subject: emailSubject, + to: emailTo, + attachments: emailAttachments, + }, + { + headers: { + Authorization: `Bearer ${access_token}`, + }, + }, + ) + .then((r) => { + return { status: r.status, data: r.data }; + }) + .catch((e) => { + throw new HttpException( + `Failed to post email to API: ${e}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + }); + } else { + return { + status: 200, + data: 'Not send email in dev deployment', + }; + } + } + throw new HttpException( + 'Failed to get email auth token: response or response access token is null', + HttpStatus.BAD_REQUEST, + ); + }) + .catch((e) => { + throw new HttpException(e, HttpStatus.INTERNAL_SERVER_ERROR); + }); + } +} From 54a587fe56dc67c8b44f4a564e7ca61b1f176ea7 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 12:17:53 -0700 Subject: [PATCH 5/9] chore: fixing code smell --- backend/src/ches/services/ches.service.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/ches/services/ches.service.ts b/backend/src/ches/services/ches.service.ts index 98b4122a..9b2a8e6f 100644 --- a/backend/src/ches/services/ches.service.ts +++ b/backend/src/ches/services/ches.service.ts @@ -6,8 +6,6 @@ const oauth = require('axios-oauth-client'); @Injectable() export class ChesService { - constructor() { } - getToken() { const getClientCredentials = oauth.client(axios.create(), { url: process.env.CHES_TOKEN_URL, From a81a727fdcf579570e1523ed3e21ca30b20ad240 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 12:33:05 -0700 Subject: [PATCH 6/9] feat: adding cron API checks --- .github/workflows/api-check.yml | 32 ++++++++++++++++++++++ postman/OG.postman_collection.json | 44 ++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 .github/workflows/api-check.yml create mode 100644 postman/OG.postman_collection.json diff --git a/.github/workflows/api-check.yml b/.github/workflows/api-check.yml new file mode 100644 index 00000000..16678632 --- /dev/null +++ b/.github/workflows/api-check.yml @@ -0,0 +1,32 @@ +name: API Validation Check + +on: + schedule: + - cron: '0 6 * * *' + workflow_dispatch: + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + +jobs: + verify-api: + name: Verify API Health + runs-on: ubuntu-22.04 + strategy: + matrix: + package: [ test, prod ] + env: + OS_DOMAIN: apps.silver.devops.gov.bc.ca + GTW_DOMAIN: api.gov.bc.ca + steps: + - uses: actions/checkout@v3 + + - name: Check Health on ${{ matrix.package }} environment + uses: matt-ball/newman-action@master + with: + collection: postman/OG.postman_collection.json + envVar: '[{"key":"URL_OG","value":"https://${{ github.event.repository.name }}-${{ matrix.package }}-backend.${{ env.OS_DOMAIN }}"}]' + reporters: '["cli"]' + folder: '["general"]' + \ No newline at end of file diff --git a/postman/OG.postman_collection.json b/postman/OG.postman_collection.json new file mode 100644 index 00000000..fe6de066 --- /dev/null +++ b/postman/OG.postman_collection.json @@ -0,0 +1,44 @@ +{ + "info": { + "_postman_id": "8a93e7e0-b8e2-4eaf-a5e0-d41bf1b1aa6e", + "name": "nr-old-growth", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "17369587" + }, + "item": [ + { + "name": "Health", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {\r", + " pm.response.to.have.status(200);\r", + "});\r", + "\r", + "pm.test(\"Body matches OK\", function () {\r", + " pm.expect(pm.response.text()).to.include(\"Ok\");\r", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "{{URL_OG}}/check", + "host": [ + "{{URL_OG}}" + ], + "path": [ + "check" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file From 6710cfca0e64f2aa16ea4e0ea215d0ba6fdac356 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 12:33:45 -0700 Subject: [PATCH 7/9] chore: fixing variables --- .github/workflows/api-check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/api-check.yml b/.github/workflows/api-check.yml index 16678632..a5fe9664 100644 --- a/.github/workflows/api-check.yml +++ b/.github/workflows/api-check.yml @@ -18,7 +18,6 @@ jobs: package: [ test, prod ] env: OS_DOMAIN: apps.silver.devops.gov.bc.ca - GTW_DOMAIN: api.gov.bc.ca steps: - uses: actions/checkout@v3 From d7026903871ed92249697b51bb189177c610b6e4 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Tue, 25 Apr 2023 13:50:28 -0700 Subject: [PATCH 8/9] Test --- .github/workflows/pr-open.yml | 291 +++++++++++++++++-------------- .github/workflows/unit-tests.yml | 2 +- 2 files changed, 160 insertions(+), 133 deletions(-) diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index ecbd7b59..ef0534e6 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -9,134 +9,162 @@ concurrency: cancel-in-progress: true jobs: - pr-validation: - name: Pull Request Validation - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - steps: - - uses: actions/checkout@v3 - - - name: Pull request size and stability labels - uses: actions/labeler@v4 - continue-on-error: true - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - - - name: Conventional Label - uses: bcoe/conventional-release-labels@v1 - continue-on-error: true - with: - token: ${{ secrets.GITHUB_TOKEN }} - ignored_types: '["chore","pr"]' - type_labels: '{"feat": "feature", "fix": "fix", "bug": "fix", "doc": "documentation", "ci": "ci", "chore": "chore", "breaking": "breaking", "BREAKING CHANGE": "breaking"}' - - - name: Checkout branch - uses: actions/checkout@v3 - with: - ref: refs/heads/${{ github.head_ref }} - - - name: Conventional Changelog Update - continue-on-error: true - uses: TriPSs/conventional-changelog-action@v3 - id: changelog - with: - github-token: ${{ github.token }} - output-file: "CHANGELOG.md" - skip-version-file: "true" - skip-commit: "true" - git-push: "false" - git-branch: refs/heads/${{ github.head_ref }} - - - name: Checkout pr - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} - - - name: Comment PR - continue-on-error: true - uses: thollander/actions-comment-pull-request@v2 - if: ${{ steps.changelog.outputs.skipped == 'false' }} - with: - message: | - # Current changelog - - ${{ steps.changelog.outputs.clean_changelog }} - comment_tag: "# Current changelog" - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - pr-greeting: - name: PR Greeting + # pr-validation: + # name: Pull Request Validation + # runs-on: ubuntu-latest + # permissions: + # contents: read + # pull-requests: write + # steps: + # - uses: actions/checkout@v3 + + # - name: Pull request size and stability labels + # uses: actions/labeler@v4 + # continue-on-error: true + # with: + # repo-token: "${{ secrets.GITHUB_TOKEN }}" + + # - name: Conventional Label + # uses: bcoe/conventional-release-labels@v1 + # continue-on-error: true + # with: + # token: ${{ secrets.GITHUB_TOKEN }} + # ignored_types: '["chore","pr"]' + # type_labels: '{"feat": "feature", "fix": "fix", "bug": "fix", "doc": "documentation", "ci": "ci", "chore": "chore", "breaking": "breaking", "BREAKING CHANGE": "breaking"}' + + # - name: Checkout branch + # uses: actions/checkout@v3 + # with: + # ref: refs/heads/${{ github.head_ref }} + + # - name: Conventional Changelog Update + # continue-on-error: true + # uses: TriPSs/conventional-changelog-action@v3 + # id: changelog + # with: + # github-token: ${{ github.token }} + # output-file: "CHANGELOG.md" + # skip-version-file: "true" + # skip-commit: "true" + # git-push: "false" + # git-branch: refs/heads/${{ github.head_ref }} + + # - name: Checkout pr + # uses: actions/checkout@v3 + # with: + # ref: ${{ github.ref }} + + # - name: Comment PR + # continue-on-error: true + # uses: thollander/actions-comment-pull-request@v2 + # if: ${{ steps.changelog.outputs.skipped == 'false' }} + # with: + # message: | + # # Current changelog + + # ${{ steps.changelog.outputs.clean_changelog }} + # comment_tag: "# Current changelog" + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + # pr-greeting: + # name: PR Greeting + # env: + # DOMAIN: apps.silver.devops.gov.bc.ca + # PREFIX: ${{ github.event.repository.name }}-${{ github.event.number }} + # runs-on: ubuntu-22.04 + # permissions: + # pull-requests: write + # steps: + # - name: PR Greeting + # uses: bcgov-nr/action-pr-description-add@v0.0.2 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # add_markdown: | + # --- + # Thanks for the PR! + + # Any successful deployments (not always required) will be available below. + # [Backend](https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }}/) available + + # Once merged, code will be promoted and handed off to following workflow run. + # [Main Merge Workflow](https://github.com/${{ github.repository }}/actions/workflows/merge-main.yml) + + # builds: + # name: Image Build + # runs-on: ubuntu-22.04 + # permissions: + # packages: write + # steps: + # - name: Checkout repository + # uses: actions/checkout@v3 + + # - name: Build Image + # uses: bcgov-nr/action-builder-ghcr@v1.1.0 + # with: + # build_context: ./backend + # build_file: ./backend/Dockerfile + # package: backend + # tag: ${{ github.event.number }} + # tag_fallback: test + # token: ${{ secrets.GITHUB_TOKEN }} + # triggers: backend/ + + # deploy-database: + # name: Deploy Database + # needs: + # - builds + # environment: dev + # runs-on: ubuntu-22.04 + # steps: + # - uses: actions/checkout@v3 + # - name: Deploys + # uses: bcgov-nr/action-deployer-openshift@v1.0.3 + # with: + # file: .github/openshift/deploy.database.yml + # oc_namespace: ${{ secrets.OC_NAMESPACE }} + # oc_server: ${{ secrets.OC_SERVER }} + # oc_token: ${{ secrets.OC_TOKEN }} + # overwrite: false + # parameters: + # -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} + + # deploy-backend: + # name: Deploy Backend + # needs: + # - deploy-database + # environment: dev + # runs-on: ubuntu-22.04 + # steps: + # - uses: actions/checkout@v3 + + # - name: Deploys + # uses: bcgov-nr/action-deployer-openshift@v1.0.3 + # with: + # file: .github/openshift/deploy.backend.yml + # oc_namespace: ${{ secrets.OC_NAMESPACE }} + # oc_server: ${{ secrets.OC_SERVER }} + # oc_token: ${{ secrets.OC_TOKEN }} + # overwrite: true + # parameters: + # -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} + # -p PROMOTE=${{ github.repository }}/backend:${{ github.event.number }} + # -p CHES_CLIENT_ID=${{ secrets.CHES_CLIENT_ID }} + # -p CHES_CLIENT_SECRET=${{ secrets.CHES_CLIENT_SECRET }} + # -p CHES_TOKEN_URL='https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' + # -p CHES_API_URL='https://ches-dev.api.gov.bc.ca/api/v1' + # -p NODE_ENV='development' + # -p BCEID_FORM_PASSWORD=${{ secrets.CHEFS_BCEID_FORM_PASSWORD}} + # -p IDIR_FORM_PASSWORD=${{ secrets.CHEFS_IDIR_FORM_PASSWORD}} + + deploy-prod-backend: + name: Deploy Backend on Prod Env env: - DOMAIN: apps.silver.devops.gov.bc.ca - PREFIX: ${{ github.event.repository.name }}-${{ github.event.number }} - runs-on: ubuntu-22.04 - permissions: - pull-requests: write - steps: - - name: PR Greeting - uses: bcgov-nr/action-pr-description-add@v0.0.2 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - add_markdown: | - --- - Thanks for the PR! - - Any successful deployments (not always required) will be available below. - [Backend](https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }}/) available - - Once merged, code will be promoted and handed off to following workflow run. - [Main Merge Workflow](https://github.com/${{ github.repository }}/actions/workflows/merge-main.yml) - - builds: - name: Image Build - runs-on: ubuntu-22.04 - permissions: - packages: write - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Build Image - uses: bcgov-nr/action-builder-ghcr@v1.1.0 - with: - build_context: ./backend - build_file: ./backend/Dockerfile - package: backend - tag: ${{ github.event.number }} - tag_fallback: test - token: ${{ secrets.GITHUB_TOKEN }} - triggers: backend/ - - deploy-database: - name: Deploy Database - needs: - - builds - environment: dev - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v3 - - name: Deploys - uses: bcgov-nr/action-deployer-openshift@v1.0.3 - with: - file: .github/openshift/deploy.database.yml - oc_namespace: ${{ secrets.OC_NAMESPACE }} - oc_server: ${{ secrets.OC_SERVER }} - oc_token: ${{ secrets.OC_TOKEN }} - overwrite: false - parameters: - -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} - - deploy-backend: - name: Deploy Backend - needs: - - deploy-database - environment: dev + PREV: test + ZONE: prod + environment: prod runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - - name: Deploys uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: @@ -144,16 +172,15 @@ jobs: oc_namespace: ${{ secrets.OC_NAMESPACE }} oc_server: ${{ secrets.OC_SERVER }} oc_token: ${{ secrets.OC_TOKEN }} - overwrite: true + overwrite: false + penetration_test: true parameters: - -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} - -p PROMOTE=${{ github.repository }}/backend:${{ github.event.number }} + -p ZONE=${{ env.ZONE }} -p NAME=${{ github.event.repository.name }} + -p PROMOTE=${{ github.repository }}/backend:${{ env.PREV }} -p CHES_CLIENT_ID=${{ secrets.CHES_CLIENT_ID }} -p CHES_CLIENT_SECRET=${{ secrets.CHES_CLIENT_SECRET }} - -p CHES_TOKEN_URL='https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' - -p CHES_API_URL='https://ches-dev.api.gov.bc.ca/api/v1' - -p NODE_ENV='development' + -p CHES_TOKEN_URL='https://loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' + -p CHES_API_URL='https://ches.api.gov.bc.ca/api/v1' + -p NODE_ENV='production' -p BCEID_FORM_PASSWORD=${{ secrets.CHEFS_BCEID_FORM_PASSWORD}} -p IDIR_FORM_PASSWORD=${{ secrets.CHEFS_IDIR_FORM_PASSWORD}} - - \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index adf2a0f6..b5f899bf 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -47,7 +47,7 @@ jobs: delete-old-comments: true github-token: ${{ secrets.GHCR_TOKEN }} lcov-file: ./backend/coverage/lcov.info - + trivy: name: Repository Report if: github.event_name != 'pull_request' || !github.event.pull_request.draft From c30d9112e8a0a6690604b6748bacb8107ab50b89 Mon Sep 17 00:00:00 2001 From: Paulo Gomes da Cruz Junior Date: Tue, 25 Apr 2023 15:19:07 -0700 Subject: [PATCH 9/9] chore: reverting changes --- .github/workflows/pr-open.yml | 289 +++++++++++++++------------------- 1 file changed, 130 insertions(+), 159 deletions(-) diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index ef0534e6..076fd9c2 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -9,178 +9,149 @@ concurrency: cancel-in-progress: true jobs: - # pr-validation: - # name: Pull Request Validation - # runs-on: ubuntu-latest - # permissions: - # contents: read - # pull-requests: write - # steps: - # - uses: actions/checkout@v3 - - # - name: Pull request size and stability labels - # uses: actions/labeler@v4 - # continue-on-error: true - # with: - # repo-token: "${{ secrets.GITHUB_TOKEN }}" - - # - name: Conventional Label - # uses: bcoe/conventional-release-labels@v1 - # continue-on-error: true - # with: - # token: ${{ secrets.GITHUB_TOKEN }} - # ignored_types: '["chore","pr"]' - # type_labels: '{"feat": "feature", "fix": "fix", "bug": "fix", "doc": "documentation", "ci": "ci", "chore": "chore", "breaking": "breaking", "BREAKING CHANGE": "breaking"}' - - # - name: Checkout branch - # uses: actions/checkout@v3 - # with: - # ref: refs/heads/${{ github.head_ref }} - - # - name: Conventional Changelog Update - # continue-on-error: true - # uses: TriPSs/conventional-changelog-action@v3 - # id: changelog - # with: - # github-token: ${{ github.token }} - # output-file: "CHANGELOG.md" - # skip-version-file: "true" - # skip-commit: "true" - # git-push: "false" - # git-branch: refs/heads/${{ github.head_ref }} - - # - name: Checkout pr - # uses: actions/checkout@v3 - # with: - # ref: ${{ github.ref }} - - # - name: Comment PR - # continue-on-error: true - # uses: thollander/actions-comment-pull-request@v2 - # if: ${{ steps.changelog.outputs.skipped == 'false' }} - # with: - # message: | - # # Current changelog - - # ${{ steps.changelog.outputs.clean_changelog }} - # comment_tag: "# Current changelog" - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # pr-greeting: - # name: PR Greeting - # env: - # DOMAIN: apps.silver.devops.gov.bc.ca - # PREFIX: ${{ github.event.repository.name }}-${{ github.event.number }} - # runs-on: ubuntu-22.04 - # permissions: - # pull-requests: write - # steps: - # - name: PR Greeting - # uses: bcgov-nr/action-pr-description-add@v0.0.2 - # with: - # github_token: ${{ secrets.GITHUB_TOKEN }} - # add_markdown: | - # --- - # Thanks for the PR! - - # Any successful deployments (not always required) will be available below. - # [Backend](https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }}/) available - - # Once merged, code will be promoted and handed off to following workflow run. - # [Main Merge Workflow](https://github.com/${{ github.repository }}/actions/workflows/merge-main.yml) - - # builds: - # name: Image Build - # runs-on: ubuntu-22.04 - # permissions: - # packages: write - # steps: - # - name: Checkout repository - # uses: actions/checkout@v3 - - # - name: Build Image - # uses: bcgov-nr/action-builder-ghcr@v1.1.0 - # with: - # build_context: ./backend - # build_file: ./backend/Dockerfile - # package: backend - # tag: ${{ github.event.number }} - # tag_fallback: test - # token: ${{ secrets.GITHUB_TOKEN }} - # triggers: backend/ - - # deploy-database: - # name: Deploy Database - # needs: - # - builds - # environment: dev - # runs-on: ubuntu-22.04 - # steps: - # - uses: actions/checkout@v3 - # - name: Deploys - # uses: bcgov-nr/action-deployer-openshift@v1.0.3 - # with: - # file: .github/openshift/deploy.database.yml - # oc_namespace: ${{ secrets.OC_NAMESPACE }} - # oc_server: ${{ secrets.OC_SERVER }} - # oc_token: ${{ secrets.OC_TOKEN }} - # overwrite: false - # parameters: - # -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} - - # deploy-backend: - # name: Deploy Backend - # needs: - # - deploy-database - # environment: dev - # runs-on: ubuntu-22.04 - # steps: - # - uses: actions/checkout@v3 - - # - name: Deploys - # uses: bcgov-nr/action-deployer-openshift@v1.0.3 - # with: - # file: .github/openshift/deploy.backend.yml - # oc_namespace: ${{ secrets.OC_NAMESPACE }} - # oc_server: ${{ secrets.OC_SERVER }} - # oc_token: ${{ secrets.OC_TOKEN }} - # overwrite: true - # parameters: - # -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} - # -p PROMOTE=${{ github.repository }}/backend:${{ github.event.number }} - # -p CHES_CLIENT_ID=${{ secrets.CHES_CLIENT_ID }} - # -p CHES_CLIENT_SECRET=${{ secrets.CHES_CLIENT_SECRET }} - # -p CHES_TOKEN_URL='https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' - # -p CHES_API_URL='https://ches-dev.api.gov.bc.ca/api/v1' - # -p NODE_ENV='development' - # -p BCEID_FORM_PASSWORD=${{ secrets.CHEFS_BCEID_FORM_PASSWORD}} - # -p IDIR_FORM_PASSWORD=${{ secrets.CHEFS_IDIR_FORM_PASSWORD}} - - deploy-prod-backend: - name: Deploy Backend on Prod Env + pr-validation: + name: Pull Request Validation + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/checkout@v3 + + - name: Pull request size and stability labels + uses: actions/labeler@v4 + continue-on-error: true + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Conventional Label + uses: bcoe/conventional-release-labels@v1 + continue-on-error: true + with: + token: ${{ secrets.GITHUB_TOKEN }} + ignored_types: '["chore","pr"]' + type_labels: '{"feat": "feature", "fix": "fix", "bug": "fix", "doc": "documentation", "ci": "ci", "chore": "chore", "breaking": "breaking", "BREAKING CHANGE": "breaking"}' + + - name: Checkout branch + uses: actions/checkout@v3 + with: + ref: refs/heads/${{ github.head_ref }} + + - name: Conventional Changelog Update + continue-on-error: true + uses: TriPSs/conventional-changelog-action@v3 + id: changelog + with: + github-token: ${{ github.token }} + output-file: "CHANGELOG.md" + skip-version-file: "true" + skip-commit: "true" + git-push: "false" + git-branch: refs/heads/${{ github.head_ref }} + + - name: Checkout pr + uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + + - name: Comment PR + continue-on-error: true + uses: thollander/actions-comment-pull-request@v2 + if: ${{ steps.changelog.outputs.skipped == 'false' }} + with: + message: | + # Current changelog + + ${{ steps.changelog.outputs.clean_changelog }} + comment_tag: "# Current changelog" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + pr-greeting: + name: PR Greeting env: - PREV: test - ZONE: prod - environment: prod + DOMAIN: apps.silver.devops.gov.bc.ca + PREFIX: ${{ github.event.repository.name }}-${{ github.event.number }} + runs-on: ubuntu-22.04 + permissions: + pull-requests: write + steps: + - name: PR Greeting + uses: bcgov-nr/action-pr-description-add@v0.0.2 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + add_markdown: | + --- + Thanks for the PR! + + Any successful deployments (not always required) will be available below. + [Backend](https://${{ env.PREFIX }}-backend.${{ env.DOMAIN }}/) available + + Once merged, code will be promoted and handed off to following workflow run. + [Main Merge Workflow](https://github.com/${{ github.repository }}/actions/workflows/merge-main.yml) + + builds: + name: Image Build + runs-on: ubuntu-22.04 + permissions: + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Build Image + uses: bcgov-nr/action-builder-ghcr@v1.1.0 + with: + build_context: ./backend + build_file: ./backend/Dockerfile + package: backend + tag: ${{ github.event.number }} + tag_fallback: test + token: ${{ secrets.GITHUB_TOKEN }} + triggers: backend/ + + deploy-database: + name: Deploy Database + needs: + - builds + environment: dev runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v3 - name: Deploys uses: bcgov-nr/action-deployer-openshift@v1.0.3 with: - file: .github/openshift/deploy.backend.yml + file: .github/openshift/deploy.database.yml oc_namespace: ${{ secrets.OC_NAMESPACE }} oc_server: ${{ secrets.OC_SERVER }} oc_token: ${{ secrets.OC_TOKEN }} overwrite: false - penetration_test: true parameters: - -p ZONE=${{ env.ZONE }} -p NAME=${{ github.event.repository.name }} - -p PROMOTE=${{ github.repository }}/backend:${{ env.PREV }} + -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} + + deploy-backend: + name: Deploy Backend + needs: + - deploy-database + environment: dev + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: Deploys + uses: bcgov-nr/action-deployer-openshift@v1.0.3 + with: + file: .github/openshift/deploy.backend.yml + oc_namespace: ${{ secrets.OC_NAMESPACE }} + oc_server: ${{ secrets.OC_SERVER }} + oc_token: ${{ secrets.OC_TOKEN }} + overwrite: true + parameters: + -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} + -p PROMOTE=${{ github.repository }}/backend:${{ github.event.number }} -p CHES_CLIENT_ID=${{ secrets.CHES_CLIENT_ID }} -p CHES_CLIENT_SECRET=${{ secrets.CHES_CLIENT_SECRET }} - -p CHES_TOKEN_URL='https://loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' - -p CHES_API_URL='https://ches.api.gov.bc.ca/api/v1' - -p NODE_ENV='production' + -p CHES_TOKEN_URL='https://dev.loginproxy.gov.bc.ca/auth/realms/comsvcauth/protocol/openid-connect/token' + -p CHES_API_URL='https://ches-dev.api.gov.bc.ca/api/v1' + -p NODE_ENV='development' -p BCEID_FORM_PASSWORD=${{ secrets.CHEFS_BCEID_FORM_PASSWORD}} -p IDIR_FORM_PASSWORD=${{ secrets.CHEFS_IDIR_FORM_PASSWORD}}