-
Notifications
You must be signed in to change notification settings - Fork 14
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
Changes from 46 commits
b874dec
23e35ba
5658849
36c498b
0cd7530
6db5524
c8478d8
fe84312
85e844e
6160a9c
35eba8b
64c4026
85e220c
a549724
636511e
5f013dd
b80878c
f576146
1aee750
663d4ea
6059a3d
ae42e0a
6ccb2a5
0e4fed0
08ce3ef
c804953
c119a53
84cc2fd
11cd2d8
07a30d7
139239a
48a2338
be5f93e
6d0386d
19c3c87
d80e056
5c7aa3c
a63eea5
9fa036a
91bb8d0
ab5f628
8f148bf
69f490f
f0127c5
69c1b3a
dbb9b58
c485bad
8024f49
5df71e3
82540e0
749762f
1e5cc43
eba989b
4906fd0
e9d9d49
b55c372
d50b8d9
2e74da8
6533b98
e46946f
79d3774
7bf7207
448d152
cfe9d0b
20e30f4
769a609
c937bbf
a82f967
d3f2b3b
7e508ae
28423ce
ab90674
777660f
e96b907
a29d664
33eaedb
e527545
3fe4d26
69a1ff2
a254889
b283186
ca9f5ae
a062e62
ecfb7b4
9b46136
f0c8cec
ef1473d
823eaf0
8caa352
933122f
8fccecf
1e3fe58
7b74466
14bef24
837651d
88273d0
acb3b3c
6472a69
79173cc
b0c03ed
0771332
531b4d9
4df3b12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ on: | |
type: choice | ||
required: false | ||
options: | ||
- | ||
- noRelease | ||
- draft | ||
- publish | ||
|
||
|
@@ -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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for my info, what happens here There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}) | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
|
@@ -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)" | ||
|
@@ -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)" | ||
|
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 |
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.