Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1717 - Segregate db migrations deployment - Part 1 #1932

Merged
merged 103 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 46 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
b874dec
updated
guru-aot May 8, 2023
23e35ba
updated
guru-aot May 8, 2023
5658849
updated
guru-aot May 9, 2023
36c498b
updated
guru-aot May 9, 2023
0cd7530
updated
guru-aot May 9, 2023
6db5524
updated
guru-aot May 9, 2023
c8478d8
updated
guru-aot May 9, 2023
fe84312
updated
guru-aot May 9, 2023
85e844e
updated
guru-aot May 9, 2023
6160a9c
updated
guru-aot May 9, 2023
35eba8b
updated
guru-aot May 9, 2023
64c4026
updated
guru-aot May 9, 2023
85e220c
updated
guru-aot May 9, 2023
a549724
updated
guru-aot May 9, 2023
636511e
updated
guru-aot May 9, 2023
5f013dd
updated
guru-aot May 9, 2023
b80878c
updated
guru-aot May 9, 2023
f576146
updated
guru-aot May 9, 2023
1aee750
updated
guru-aot May 9, 2023
663d4ea
updated
guru-aot May 9, 2023
6059a3d
updated
guru-aot May 9, 2023
ae42e0a
updated
guru-aot May 9, 2023
6ccb2a5
updated
guru-aot May 9, 2023
0e4fed0
updated
guru-aot May 9, 2023
08ce3ef
updated
guru-aot May 9, 2023
c804953
updated
guru-aot May 9, 2023
c119a53
updated
guru-aot May 9, 2023
84cc2fd
updated
guru-aot May 9, 2023
11cd2d8
updated
guru-aot May 9, 2023
07a30d7
updated
guru-aot May 9, 2023
139239a
updated
guru-aot May 9, 2023
48a2338
updated
guru-aot May 9, 2023
be5f93e
updated
guru-aot May 9, 2023
6d0386d
updated
guru-aot May 9, 2023
19c3c87
updated
guru-aot May 9, 2023
d80e056
updated
guru-aot May 9, 2023
5c7aa3c
updated
guru-aot May 9, 2023
a63eea5
updated
guru-aot May 11, 2023
9fa036a
updated
guru-aot May 11, 2023
91bb8d0
updated
guru-aot May 11, 2023
ab5f628
updated
guru-aot May 11, 2023
8f148bf
updated
guru-aot May 11, 2023
69f490f
updated
guru-aot May 11, 2023
f0127c5
updated
guru-aot May 11, 2023
69c1b3a
updated
guru-aot May 11, 2023
dbb9b58
updated
guru-aot May 11, 2023
c485bad
updated
guru-aot May 12, 2023
8024f49
updated
guru-aot May 12, 2023
5df71e3
updated
guru-aot May 12, 2023
82540e0
updated
guru-aot May 12, 2023
749762f
updated
guru-aot May 12, 2023
1e5cc43
updated
guru-aot May 12, 2023
eba989b
updated
guru-aot May 12, 2023
4906fd0
updated
guru-aot May 12, 2023
e9d9d49
updated
guru-aot May 12, 2023
b55c372
updated
guru-aot May 12, 2023
d50b8d9
updated
guru-aot May 12, 2023
2e74da8
updated
guru-aot May 12, 2023
6533b98
updated
guru-aot May 12, 2023
e46946f
updated
guru-aot May 12, 2023
79d3774
updated
guru-aot May 12, 2023
7bf7207
updated
guru-aot May 12, 2023
448d152
Merge branch 'main' into Segregate_DB_Migrations_Deployment
guru-aot May 12, 2023
cfe9d0b
updated
guru-aot May 12, 2023
20e30f4
updated
guru-aot May 12, 2023
769a609
updated
guru-aot May 12, 2023
c937bbf
updated
guru-aot May 12, 2023
a82f967
updated
guru-aot May 12, 2023
d3f2b3b
updated
guru-aot May 12, 2023
7e508ae
updated
guru-aot May 12, 2023
28423ce
updated
guru-aot May 12, 2023
ab90674
updated
guru-aot May 12, 2023
777660f
updated
guru-aot May 15, 2023
e96b907
updated
guru-aot May 15, 2023
a29d664
uodated
guru-aot May 15, 2023
33eaedb
updated
guru-aot May 15, 2023
e527545
updated
guru-aot May 15, 2023
3fe4d26
updated
guru-aot May 15, 2023
69a1ff2
updated
guru-aot May 15, 2023
a254889
updated
guru-aot May 15, 2023
b283186
updated
guru-aot May 15, 2023
ca9f5ae
updated
guru-aot May 15, 2023
a062e62
updated
guru-aot May 15, 2023
ecfb7b4
updated
guru-aot May 15, 2023
9b46136
updated
guru-aot May 15, 2023
f0c8cec
updated
guru-aot May 15, 2023
ef1473d
updated
guru-aot May 15, 2023
823eaf0
updated
guru-aot May 15, 2023
8caa352
updated
guru-aot May 15, 2023
933122f
updated
guru-aot May 15, 2023
8fccecf
updated
guru-aot May 15, 2023
1e3fe58
updated
guru-aot May 16, 2023
7b74466
Merge branch 'main' into Segregate_DB_Migrations_Deployment
guru-aot May 16, 2023
14bef24
updated
guru-aot May 16, 2023
837651d
updated
guru-aot May 16, 2023
88273d0
updated
guru-aot May 16, 2023
acb3b3c
updated
guru-aot May 16, 2023
6472a69
updated
guru-aot May 16, 2023
79173cc
updated
guru-aot May 16, 2023
b0c03ed
updated
guru-aot May 16, 2023
0771332
updated
guru-aot May 16, 2023
531b4d9
updated
guru-aot May 16, 2023
4df3b12
updated
guru-aot May 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 33 additions & 30 deletions .github/workflows/build-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on:
type: choice
required: false
options:
-
- noRelease
- draft
- publish

Expand Down Expand Up @@ -125,23 +125,22 @@ jobs:
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
# Build the images
- name: Build SIMS-API Image
if [ $? -ne 0 ]; then
echo "Failed to log in to OpenShift. Please check the credentials and connection details."
exit 1
fi
# Build the images in parallel.
- name: Build db-migrations, api, workers, queues and web Images in parallel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db-migrations will run first, then rest in parallel right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh.. since it is deployed we are doing everything in parallel?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The make oc-something here, in general, are appended with --wait does it not mean that they will be waiting to be executed one after another?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, if the oc-build-db-migrations target in the make command includes --wait in its command, it does not automatically wait for the other make commands to finish. The --wait option typically applies to the specific build process triggered by that particular make target.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got the point when we talked about the commands concatenation with the "&".
Either way, as per the Team discussion, the approach with the GitHub parallel jobs looks great.

working-directory: "./devops"
run: |
make oc-build-api
- name: Build Workers Image
working-directory: "./devops"
run: |
make oc-build-workers
- name: Build Queue Consumers Image
working-directory: "./devops"
run: |
make oc-build-queue-consumers
- name: Build Web/Frontend Image
working-directory: "./devops"
make oc-build-db-migrations &
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
make oc-build-api &
make oc-build-workers &
make oc-build-queue-consumers &
make oc-build-web
- name: Wait for parallel builds to finish
run: |
make oc-build-web
wait
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my info, what happens here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just waits until all the parallel process is successful


# Deploying all packages
deployDev:
Expand Down Expand Up @@ -197,23 +196,27 @@ jobs:
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
# Deploy SIMS-Api
- name: Deploy SIMS-API
working-directory: "./devops/"
run: |
make oc-deploy-api
# Deploy Workers
- name: Deploy Workers
if [ $? -ne 0 ]; then
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
echo "Failed to log in to OpenShift. Please check the openshift credentials and connection details."
exit 1
fi
# Run db-migrations
- name: Run db-migrations
working-directory: "./devops/"
run: |
make oc-deploy-workers
# Deploy Queue Consumers
- name: Deploy Queue Consumers
make oc-run-db-migrations
if [ $? -ne 0 ]; then
echo "Failed to run DB Migrations."
exit 1
fi
# Deploy SIMS-API, Workers, Queues, and Web/Frontend in parallel after db-migrations.
- name: Deploy SIMS-API, Workers, Queues, and Web/Frontend in parallel
working-directory: "./devops/"
run: |
make oc-deploy-queue-consumers
# Deploy Deploy Web/Frontend
- name: Deploy Web/Frontend
working-directory: "./devops/"
make oc-deploy-api &
make oc-deploy-workers &
make oc-deploy-queue-consumers &
make oc-deploy-web &
- name: Wait for parallel deployments to finish
run: |
make oc-deploy-web
wait
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it wait for all processes to finish or it wait for a certain time? how is it for my info

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for certain time, once the parallel tasks are executed, it just waits like promise.all

35 changes: 20 additions & 15 deletions .github/workflows/deploy-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
required: true
default: ""
environment:
description: 'Openshift Environment'
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
required: true
type: environment
deployCamundaDefinitions:
Expand Down Expand Up @@ -79,26 +80,30 @@ jobs:
- name: Log in to OpenShift
run: |
oc login --token=${{ secrets.SA_TOKEN }} --server=https://api.silver.devops.gov.bc.ca:6443
# Deploy SIMS-Api
- name: Deploy SIMS-API
if [ $? -ne 0 ]; then
echo "Failed to log in to OpenShift. Please check the openshift credentials and connection details."
exit 1
fi
# Run db-migrations
- name: Run db-migrations
working-directory: "./devops/"
run: |
make oc-deploy-api
# Deploy Workers
- name: Deploy Workers
make oc-run-db-migrations
if [ $? -ne 0 ]; then
echo "Failed to run DB Migrations."
exit 1
fi
# Deploy SIMS-API, Workers, Queues, and Web/Frontend in parallel after db-migrations.
- name: Deploy SIMS-API, Workers, Queues, and Web/Frontend in parallel
working-directory: "./devops/"
run: |
make oc-deploy-workers
# Deploy Queues
- name: Deploy Queue Consumers
working-directory: "./devops/"
run: |
make oc-deploy-queue-consumers
# Deploy Deploy Web/Frontend
- name: Deploy Web/Frontend
working-directory: "./devops/"
make oc-deploy-api &
make oc-deploy-workers &
make oc-deploy-queue-consumers &
make oc-deploy-web &
- name: Wait for parallel deployments to finish
run: |
make oc-deploy-web
wait
deployCamundaDefinitions:
if: ${{ github.event.inputs.deployCamundaDefinitions == 'true' }}
name: Deploy BPMNs and DMNs to Camunda
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-camunda-definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
workflow_dispatch:
inputs:
environment:
description: 'Openshift Environment'
required: true
type: environment
gitRef:
description: 'Github reference'
required: true
type: string
workflow_call:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-formio-definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
workflow_dispatch:
inputs:
environment:
description: 'Openshift Environment'
required: true
type: environment
gitRef:
description: 'Github reference'
required: true
type: string
workflow_call:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
workflow_dispatch:
inputs:
environment:
description: 'Openshift Environment'
required: true
type: environment
gitRef:
Expand Down
49 changes: 49 additions & 0 deletions devops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export QUEUE_CONSUMERS_PORT := $(or ${QUEUE_CONSUMERS_PORT}, 7000)
export WEB_PORT := $(or ${WEB_PORT}, 3030)
export DATABASE_NAME_KEY := $(or ${DATABASE_NAME_KEY}, database-name)
export DB_NAME := $(or ${DB_NAME}, SIMSDB)
export DB_MIGRATIONS_BUILD_REF := $(or ${DB_MIGRATIONS_BUILD_REF}, db-migrations-${APP_NAME})
export API_BUILD_REF := $(or ${API_BUILD_REF}, api-${APP_NAME})
export WORKERS_BUILD_REF := $(or ${WORKERS_BUILD_REF}, workers-${APP_NAME})
export QUEUE_CONSUMERS_BUILD_REF := $(or ${QUEUE_CONSUMERS_BUILD_REF}, queue-consumers-${APP_NAME})
Expand All @@ -34,6 +35,17 @@ export FORMIO_ROOT_EMAIL := $(or ${FORMIO_ROOT_EMAIL}, [email protected])
export MONGODB_URI := $(or ${MONGODB_URI}, $$MONGODB_URI)
export QUEUE_PREFIX := $(or $(QUEUE_PREFIX), {sims-local})

export MAX_WAIT=300 # Maximum wait time in seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this variable is used to check whether the dbmigration job is completed within the specified time

export WAIT_TIME=0 # Initialize wait time to zero

define DB_MIGRATIONS
"$(HOST_PREFIX)db-migrations-$(APP_NAME)"
endef

define DB_MIGRATIONS_JOB_NAME
"db.migrations"
endef

define API
"$(HOST_PREFIX)api-$(APP_NAME)"
endef
Expand Down Expand Up @@ -114,6 +126,8 @@ endef
init-oc: | print-status init-project
oc-build-patroni: | print-status build-patroni
oc-deploy-patroni: | print-status deploy-patroni
oc-build-db-migrations: | print-status build-db-migrations
oc-run-db-migrations: | print-status run-db-migrations wait-for-db-migrations delete-db-migrations
oc-build-api: | print-status build-api
oc-deploy-api: | print-status deploy-api
oc-build-workers: | print-status build-workers
Expand Down Expand Up @@ -221,6 +235,14 @@ init-artifactory-secret-credential:
@oc secrets link default artifactory-secret-credential
@oc secrets link builder artifactory-secret-credential

build-db-migrations:
test -n "$(BUILD_NAMESPACE)"
test -n "$(BUILD_REF)"
test -n "$(DB_MIGRATIONS_BUILD_REF)"
@echo "+\n++ BUILDING DB migrations with tag: $(BUILD_REF)\n+"
@oc -n $(BUILD_NAMESPACE) process -f $(BUILD_TEMPLATE_PATH) -p TAG=$(BUILD_REF) -p SOURCE_REPOSITORY_REF=$(BUILD_REF) -p BASE_IMAGE_NAME="nodejs-16" -p BASE_IMAGE_TAG="1" -p BASE_IMAGE_REPO="artifacts.developer.gov.bc.ca/redhat-docker-remote/ubi8/" -p SOURCE_CONTEXT_DIR=$(SOURCE_CONTEXT_DIR)backend -p DOCKER_FILE_PATH=apps/db-migrations/Dockerfile -p NAME=$(DB_MIGRATIONS_BUILD_REF) | oc -n $(BUILD_NAMESPACE) apply -f -
@oc -n $(BUILD_NAMESPACE) start-build bc/$(DB_MIGRATIONS_BUILD_REF) --wait

build-api:
test -n "$(BUILD_NAMESPACE)"
test -n "$(BUILD_REF)"
Expand Down Expand Up @@ -285,6 +307,33 @@ create-new-db:
@echo "+\n++ Creating DB ($(NEW_DB)) in $(NAMESPACE) patroni db cluster"
@oc -n $(NAMESPACE) process -f openshift/database/createdb-job.yml -p DB_NAME=$(NEW_DB) -p BUILD_NAMESPACE=$(BUILD_NAMESPACE) -p JOB_NAME=$(JOB_NAME) | oc -n $(NAMESPACE) apply -f -

run-db-migrations:
test -n "$(NAMESPACE)"
test -n "$(BUILD_NAMESPACE)"
test -n "$(DB_SERVICE_NAME)"
test -n "$(DB_MIGRATIONS_BUILD_REF)"
test -n "$(BUILD_REF)"
test -n "$(DATABASE_NAME_KEY)"
test -n "$(DB_MIGRATIONS)"
@echo "+\n++ Deploying DB_MIGRATIONS with tag: $(BUILD_REF)\n+"
@oc -n $(NAMESPACE) process -f openshift/db-migrations-deploy.yml \
-p NAME=$(DB_MIGRATIONS) \
-p DB_SERVICE=$(DB_SERVICE_NAME) \
-p BUILD_NAMESPACE=$(BUILD_NAMESPACE) \
-p IMAGE_STREAM_TAG="$(DB_MIGRATIONS_BUILD_REF):$(BUILD_REF)" \
-p BUILD_TAG=$(BUILD_REF) \
-p DATABASE_NAME_KEY=$(DATABASE_NAME_KEY) \
-p JOB_NAME=$(DB_MIGRATIONS_JOB_NAME) \
| oc -n $(NAMESPACE) apply -f -

wait-for-db-migrations:
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
while [ "$$(oc get job $(DB_MIGRATIONS_JOB_NAME) -o=jsonpath='{.status.conditions[?(@.type=="Complete")].status}' || echo "None")" != "True" ] && [ "$$WAIT_TIME" -lt "$$MAX_WAIT" ]; do sleep 5; WAIT_TIME=$$((WAIT_TIME+5)); done

if [ "$$(oc get job $(DB_MIGRATIONS_JOB_NAME) -o=jsonpath='{.status.conditions[?(@.type=="Complete")].status}' || echo "None")" != "True" ]; then echo "Error: Job $(DB_MIGRATIONS_JOB_NAME) failed to complete within the specified timeout"; exit 1; fi

delete-db-migrations:
oc delete job $(DB_MIGRATIONS_JOB_NAME)

deploy-api:
test -n "$(NAMESPACE)"
test -n "$(BUILD_NAMESPACE)"
Expand Down
15 changes: 15 additions & 0 deletions devops/openshift/api-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ objects:
name: ${NAME}
spec:
replicas: "${{REPLICAS}}"
disruptionBudget:
maxUnavailable: 0
minAvailable: "${{REPLICAS}}"
revisionHistoryLimit: 10
selector:
deploymentconfig: ${NAME}
Expand Down Expand Up @@ -245,6 +248,18 @@ objects:
to:
kind: Service
name: ${NAME}
- apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: ${NAME}-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: ReplicationController
name: ${NAME}-rc
minReplicas: "${{REPLICAS}}"
maxReplicas: 10
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
targetCPUUtilizationPercentage: 80
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
parameters:
- name: NAME
required: true
Expand Down
87 changes: 87 additions & 0 deletions devops/openshift/db-migrations-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
apiVersion: template.openshift.io/v1
kind: Template
dheepak-aot marked this conversation as resolved.
Show resolved Hide resolved
metadata:
name: ${NAME}
annotations:
description: "Template for running a job that performs a database migrations"
labels:
project: ${PROJECT}
service: ${SERVICE_NAME}
parameters:
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
- name: NAME
required: true
- name: BUILD_TAG
value: "0"
- name: PROJECT
value: sims
- name: SERVICE_NAME
value: db-migrations
- name: JOB_NAME
description: database.migrations
required: true
value: db-migrations-job
- name: IMAGE_STREAM_TAG
required: true
- name: BUILD_NAMESPACE
required: true
- name: IMAGE_REGISTRY
value: image-registry.openshift-image-registry.svc:5000
- name: DB_SERVICE
value: patroni-master
- name: DB_SECRET_NAME
value: patroni-creds
- name: DB_USERNAME_KEY
value: superuser-username
- name: DB_PASSWORD_KEY
value: superuser-password
- name: DATABASE_NAME_KEY
required: true
- name: CPU_LIMIT
value: "1.0"
- name: MEMORY_LIMIT
value: "2000M"
- name: CPU_REQUEST
value: "0.5"
- name: MEMORY_REQUEST
value: "1000M"
objects:
- apiVersion: batch/v1
kind: Job
metadata:
name: ${JOB_NAME}
spec:
template:
metadata:
name: ${JOB_NAME}
spec:
containers:
- name: db-migrations-container
dheepak-aot marked this conversation as resolved.
Show resolved Hide resolved
image: ${IMAGE_REGISTRY}/${BUILD_NAMESPACE}/${IMAGE_STREAM_TAG}
env:
- name: VERSION
value: ${BUILD_TAG}
- name: POSTGRES_HOST
value: "${DB_SERVICE}"
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
key: ${DB_USERNAME_KEY}
name: ${DB_SECRET_NAME}
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
key: ${DB_PASSWORD_KEY}
name: ${DB_SECRET_NAME}
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
key: ${DATABASE_NAME_KEY}
name: ${DB_SECRET_NAME}
resources:
limits:
cpu: ${CPU_LIMIT}
memory: ${MEMORY_LIMIT}
requests:
cpu: ${CPU_REQUEST}
memory: ${MEMORY_REQUEST}
restartPolicy: Never
Loading