Skip to content

Commit 2333aba

Browse files
committed
Add database migration pre-upgrade hook and update Helm values
- Added migration-job.yaml template for pre-upgrade MongoDB migrations - Migration runs as Helm hook before each deployment upgrade - Updated values-dev.yaml with MinIO secret configuration - Updated values-test.yaml with all secret configurations and adjusted resources - Minor whitespace fix in deploy-to-test.yaml The migration job uses the same MongoDB credentials and runs db-migrate up before the main deployment rolls out, ensuring database schema is always up to date.
1 parent 4ac78fb commit 2333aba

File tree

4 files changed

+104
-4
lines changed

4 files changed

+104
-4
lines changed

.github/workflows/deploy-to-test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ jobs:
128128
129129
echo "Deployment successful!"
130130
oc get pods -n ${{ env.OPENSHIFT_NAMESPACE_TEST }} -l app.kubernetes.io/name=${{ env.APP_NAME }}
131+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{{- if .Values.migrations.enabled }}
2+
apiVersion: batch/v1
3+
kind: Job
4+
metadata:
5+
name: {{ include "eagle-api.fullname" . }}-migration-{{ .Release.Revision }}
6+
labels:
7+
{{- include "eagle-api.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: migration
9+
annotations:
10+
# Helm hook configuration - runs before upgrade
11+
"helm.sh/hook": pre-upgrade
12+
"helm.sh/hook-weight": "-5"
13+
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
14+
spec:
15+
ttlSecondsAfterFinished: 300
16+
backoffLimit: 3
17+
template:
18+
metadata:
19+
labels:
20+
{{- include "eagle-api.selectorLabels" . | nindent 8 }}
21+
app.kubernetes.io/component: migration
22+
spec:
23+
restartPolicy: Never
24+
containers:
25+
- name: migration
26+
image: "{{ .Values.migrations.image.repository }}:{{ .Values.migrations.image.tag | default .Values.image.tag }}"
27+
imagePullPolicy: {{ .Values.image.pullPolicy }}
28+
command:
29+
- /bin/sh
30+
- -c
31+
- |
32+
echo "Starting database migration..."
33+
34+
# Create migration config
35+
cat > database_migration.json << EOF
36+
{
37+
"defaultEnv": "local",
38+
"local": {
39+
"driver": "mongodb",
40+
"database": "${MONGODB_DATABASE}",
41+
"user": "${MONGODB_USERNAME}",
42+
"password": "${MONGODB_PASSWORD}",
43+
"host": "${MONGODB_SERVICE_HOST}",
44+
"authSource": "${MONGODB_AUTHSOURCE}",
45+
"port": "27017"
46+
}
47+
}
48+
EOF
49+
50+
echo "Migration config created"
51+
52+
# Run migrations
53+
node ./node_modules/db-migrate/bin/db-migrate up --config database_migration.json --env local
54+
55+
echo "Migration completed successfully"
56+
env:
57+
# MongoDB Configuration from Secret
58+
- name: MONGODB_USERNAME
59+
valueFrom:
60+
secretKeyRef:
61+
name: {{ .Values.secrets.mongodb.name }}
62+
key: {{ .Values.secrets.mongodb.usernameKey }}
63+
- name: MONGODB_PASSWORD
64+
valueFrom:
65+
secretKeyRef:
66+
name: {{ .Values.secrets.mongodb.name }}
67+
key: {{ .Values.secrets.mongodb.passwordKey }}
68+
# MongoDB Configuration from ConfigMap
69+
- name: MONGODB_SERVICE_HOST
70+
value: {{ .Values.env.MONGODB_SERVICE_HOST | quote }}
71+
- name: MONGODB_DATABASE
72+
value: {{ .Values.env.MONGODB_DATABASE | quote }}
73+
- name: MONGODB_AUTHSOURCE
74+
value: {{ .Values.env.MONGODB_AUTHSOURCE | quote }}
75+
resources:
76+
{{- toYaml .Values.migrations.resources | nindent 12 }}
77+
{{- end }}

helm/eagle-api/values-dev.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ secrets:
3333
name: eagle-api-mongodb
3434
usernameKey: MONGODB_USERNAME
3535
passwordKey: MONGODB_PASSWORD
36+
minio:
37+
name: nr-object-store-credential
38+
hostKey: endpoint_url
39+
accessKeyKey: user_account
40+
secretKeyKey: password
41+
bucketKey: bucket_name
3642
ches:
3743
name: getok-secret
3844
clientIdKey: CLIENTID

helm/eagle-api/values-test.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ route:
1010

1111
resources:
1212
limits:
13-
cpu: 1000m
14-
memory: 4Gi
13+
cpu: 500m
14+
memory: 2Gi
1515
requests:
16-
cpu: 1000m
17-
memory: 1Gi
16+
cpu: 250m
17+
memory: 512Mi
1818

1919
env:
2020
API_HOSTNAME: eagle-test.apps.silver.devops.gov.bc.ca
@@ -28,6 +28,22 @@ keycloak:
2828
realm: eagle
2929
clientId: eagle-api-console
3030

31+
secrets:
32+
mongodb:
33+
name: eagle-api-mongodb
34+
usernameKey: MONGODB_USER
35+
passwordKey: MONGODB_PASSWORD
36+
minio:
37+
name: nr-object-store-credential
38+
hostKey: endpoint_url
39+
accessKeyKey: user_account
40+
secretKeyKey: password
41+
bucketKey: bucket_name
42+
ches:
43+
name: getok-secret
44+
clientIdKey: CLIENTID
45+
clientSecretKey: CLIENT_SECRET
46+
3147
persistence:
3248
size: 10Gi
3349

0 commit comments

Comments
 (0)