diff --git a/.github/openshift/deploy.backend-applications.yml b/.github/openshift/deploy.backend-applications.yml index e007057f..aed39181 100644 --- a/.github/openshift/deploy.backend-applications.yml +++ b/.github/openshift/deploy.backend-applications.yml @@ -44,6 +44,9 @@ parameters: - name: PROMOTE description: Image (namespace/name:tag) to promote/import value: bcgov/nr-epd-digital-services/backend/applications + - name: INIT_IMAGE + description: Image (namespace/name:tag) to promote/import + value: bcgov/nr-epd-digital-services/backend/applications-migration - name: ENV description: The Environment on which it is deployed required: true @@ -64,6 +67,22 @@ objects: name: ${REGISTRY}/${PROMOTE}:${IMAGE_TAG} referencePolicy: type: Local + - apiVersion: v1 + kind: ImageStream + metadata: + labels: + app: ${NAME}-${COMPONENT}-migration + name: ${NAME}-${COMPONENT}-migration + spec: + lookupPolicy: + local: false + tags: + - name: ${IMAGE_TAG} + from: + kind: DockerImage + name: ${REGISTRY}/${INIT_IMAGE}:${IMAGE_TAG} + referencePolicy: + type: Local - apiVersion: v1 kind: DeploymentConfig metadata: @@ -102,21 +121,26 @@ objects: configMapKeyRef: name: ${NAME}-database key: POSTGRESQL_HOST - - name: POSTGRESQL_DATABASE + - name: POSTGRES_DATABASE valueFrom: configMapKeyRef: name: ${NAME}-database key: POSTGRES_DATABASE - - name: POSTGRESQL_PASSWORD + - name: POSTGRES_DB_SCHEMA + valueFrom: + configMapKeyRef: + name: ${NAME}-database + key: POSTGRES_DB_APPLICATION_SCHEMA + - name: POSTGRES_DB_PASSWORD valueFrom: secretKeyRef: name: ${NAME}-database - key: POSTGRES_DB_PASSWORD - - name: POSTGRESQL_USER + key: POSTGRES_DB_APPLICATION_PASSWORD + - name: POSTGRES_DB_USERNAME valueFrom: secretKeyRef: name: ${NAME}-database - key: POSTGRES_DB_USERNAME + key: POSTGRES_DB_APPLICATION_USERNAME - name: KEYCLOCK_AUTH_URL valueFrom: configMapKeyRef: @@ -167,6 +191,83 @@ objects: initialDelaySeconds: 10 periodSeconds: 30 timeoutSeconds: 5 + initContainers: + # - name: init-${NAME}-backend-users-typeorm-migrations + # image: image-registry.openshift-image-registry.svc:5000/${NAME}-${COMPONENT}:${IMAGE_TAG} + # command: ['sh', '-c', 'initContainer.sh'] + # ${NAME}-${COMPONENT}:${IMAGE_TAG} + - name: epd-db-migration-applications + image: "image-registry.openshift-image-registry.svc:5000/e38158-${ENV}/${NAME}-${COMPONENT}-migration:${IMAGE_TAG}" + env: + - name: Typeorm-migration-applications + value: "jdbc:postgresql://${COMPONENT}-postgres:5432/${COMPONENT}" + - name: POSTGRESQL_HOST + valueFrom: + configMapKeyRef: + name: ${NAME}-database + key: POSTGRESQL_HOST + - name: POSTGRESQL_PORT + valueFrom: + configMapKeyRef: + name: ${NAME}-database + key: POSTGRESQL_PORT + - name: POSTGRES_DATABASE + valueFrom: + configMapKeyRef: + name: ${NAME}-database + key: POSTGRES_DATABASE + - name: POSTGRES_DB_SCHEMA + valueFrom: + configMapKeyRef: + name: ${NAME}-database + key: POSTGRES_DB_APPLICATION_SCHEMA + - name: POSTGRES_ADMIN_USERNAME + valueFrom: + secretKeyRef: + name: ${NAME}-database + key: POSTGRES_ADMIN_USERNAME + - name: POSTGRES_ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: ${NAME}-database + key: POSTGRES_ADMIN_PASSWORD + - name: POSTGRES_DB_USERNAME + valueFrom: + secretKeyRef: + name: ${NAME}-database + key: POSTGRES_DB_APPLICATION_USERNAME + - name: POSTGRES_DB_PASSWORD + valueFrom: + secretKeyRef: + name: ${NAME}-database + key: POSTGRES_DB_APPLICATION_PASSWORD + - name: KEYCLOCK_AUTH_URL + valueFrom: + configMapKeyRef: + name: keycloak-config + key: KEYCLOCK_AUTH_URL + - name: KEYCLOCK_REALM + valueFrom: + configMapKeyRef: + name: keycloak-config + key: KEYCLOCK_REALM + - name: KEYCLOCK_APP_CLIENT_ID + valueFrom: + secretKeyRef: + name: keycloak + key: KEYCLOCK_APP_CLIENT_ID + - name: KEYCLOCK_APP_SECRET + valueFrom: + secretKeyRef: + name: keycloak + key: KEYCLOCK_APP_SECRET + resources: + limits: + cpu: 100m + memory: 150Mi + requests: + cpu: 50m + memory: 50Mi - apiVersion: v1 kind: Service metadata: diff --git a/.github/workflows/_build.yml b/.github/workflows/_build.yml index b45e90cd..4c0c2d98 100644 --- a/.github/workflows/_build.yml +++ b/.github/workflows/_build.yml @@ -139,7 +139,7 @@ jobs: # if: inputs.component == 'backend/users-migration' # file: ./backend/users/Dockerfile-migrations-openshift - - name: Build and push Migration image + - name: Build and push Migration image for users if: steps.check.outputs.build == 'true' && inputs.component == 'backend/users' uses: docker/build-push-action@v3.1.1 with: @@ -149,4 +149,15 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max file: ./backend/users/Dockerfile-migrations-openshift + + - name: Build and push Migration image for applications + if: steps.check.outputs.build == 'true' && inputs.component == 'backend/applications' + uses: docker/build-push-action@v3.1.1 + with: + context: ./${{ inputs.component }}/ + push: true + tags: ghcr.io/${{ github.repository }}/backend/applications-migration:${{ inputs.img_build }} + cache-from: type=gha + cache-to: type=gha,mode=max + file: ./backend/applications/Dockerfile-migrations-openshift diff --git a/.github/workflows/cd-openshift-test.yaml b/.github/workflows/cd-openshift-test.yaml index 1fdfb925..826a0a40 100644 --- a/.github/workflows/cd-openshift-test.yaml +++ b/.github/workflows/cd-openshift-test.yaml @@ -5,8 +5,8 @@ on: push: branches: - 'main' - #- 'ss-249' #test - #- 'dev' + #- 'ss-initforapps' #test + #- 'dev'1 paths: - 'backend/**' diff --git a/backend/applications/Dockerfile-migrations-openshift b/backend/applications/Dockerfile-migrations-openshift new file mode 100644 index 00000000..db52dba4 --- /dev/null +++ b/backend/applications/Dockerfile-migrations-openshift @@ -0,0 +1,26 @@ +FROM node:14.5.0-alpine +#FROM artifacts.developer.gov.bc.ca/docker-remote/node:14.17.1-alpine + +# Install packages, build and keep only prod packages +WORKDIR /app + +# A wildcard is used to ensure both package.json AND package-lock.json are copied +COPY package*.json ./ + +# Set NODE_ENV environment variable +#ENV NODE_ENV production + +# Install app dependencies using the `npm ci` command instead of `npm install` +RUN npm ci + +#RUN npm build + +# Bundle app source +COPY . . + +RUN set -x \ + && chmod -R 777 /app/ + +RUN apk add postgresql-client + +ENTRYPOINT [ "sh", "initDB.sh" ] \ No newline at end of file diff --git a/backend/applications/package.json b/backend/applications/package.json index 68dc158c..01358a78 100644 --- a/backend/applications/package.json +++ b/backend/applications/package.json @@ -12,7 +12,7 @@ "start": "nest start", "start:dev": "nest start --watch", "start:debug": "nest start --debug --watch", - "start:prod": "node dist/main", + "start:prod": "node dist/src/main", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", diff --git a/backend/applications/src/app.module.ts b/backend/applications/src/app.module.ts index 30a11096..30dcfd7d 100644 --- a/backend/applications/src/app.module.ts +++ b/backend/applications/src/app.module.ts @@ -40,7 +40,7 @@ import { ExternalUser } from './app/entities/externalUser.entity'; type: 'postgres', host: config.get('POSTGRESQL_HOST') || 'gldatabase', port: parseInt(config.get('POSTGRESQL_PORT')) || 5432, - database: config.get('POSTGRES_DATABASE') || 'xyz', + database: config.get('POSTGRES_DATABASE') || 'epd_dev', username: config.get('POSTGRES_DB_USERNAME') || 'xyzuser', password: config.get('POSTGRES_DB_PASSWORD') || 'xyzuser', autoLoadEntities: true, // Auto load all entities regiestered by typeorm forFeature method. diff --git a/backend/applications/start.sh b/backend/applications/start.sh new file mode 100644 index 00000000..39b01ca1 --- /dev/null +++ b/backend/applications/start.sh @@ -0,0 +1,11 @@ +# create DB dependencies - database, schema +#sh initDB.sh + +# run type orm migrations +#npm run typeorm:run-migrations + +# Creates a "dist" folder with the production build +#npm run build + +# start the API +npm run start:prod \ No newline at end of file