Skip to content

Commit

Permalink
Merge pull request #344 from bcgov/ss-initforapps
Browse files Browse the repository at this point in the history
Ss initforapps
  • Loading branch information
nikhila-aot authored Mar 31, 2023
2 parents 852a23b + 284c902 commit 148bb8d
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 10 deletions.
111 changes: 106 additions & 5 deletions .github/openshift/deploy.backend-applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand All @@ -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/[email protected]
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

4 changes: 2 additions & 2 deletions .github/workflows/cd-openshift-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
push:
branches:
- 'main'
#- 'ss-249' #test
#- 'dev'
#- 'ss-initforapps' #test
#- 'dev'1

paths:
- 'backend/**'
Expand Down
26 changes: 26 additions & 0 deletions backend/applications/Dockerfile-migrations-openshift
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 1 addition & 1 deletion backend/applications/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion backend/applications/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions backend/applications/start.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 148bb8d

Please sign in to comment.