11name : Reset environment
22run-name : " Reset ${{ inputs.environment }} environment"
3- # FIXME:
4- # - replace sleep 30 with kubectl wait for job completion
5- # - add status code checks
6- # - refactor multiple git hub steps into job list
7- # instead of having multiple similar steps we may have a matrix job with max-parallel: 1
83on :
94 workflow_dispatch :
105 inputs :
116 environment :
127 description : " Target environment"
138 required : true
14- default : " dev"
159 type : choice
1610 options :
17- - demo
18- - dev
19- - dev-stg
11+ - " "
2012 workflow_call :
2113 inputs :
2214 environment :
2315 type : string
2416jobs :
25- reset :
26- environment : ${{ inputs.environment }}
17+ prepare :
18+ outputs :
19+ values-file : ${{ steps.get-values.outputs.values-file }}
2720 env :
2821 namespace : opencrvs-${{ inputs.environment }}
2922 runs-on :
@@ -32,77 +25,76 @@ jobs:
3225 - ${{ inputs.environment }}
3326 steps :
3427 - name : Get helm release values and Quote specific fields that are commonly numeric
28+ id : get-values
3529 run : |
3630 helm get values opencrvs -n ${namespace} -ojson | \
3731 jq '
32+ # Quote image tags
3833 if has("image") and (.image | has("tag")) and (.image.tag | type == "number") then
3934 .image.tag = (.image.tag | tostring)
4035 else . end |
36+
37+ # Quote version numbers
4138 if has("version") and (.version | type == "number") then
4239 .version = (.version | tostring)
4340 else . end |
41+
42+ # Quote port numbers if needed (optional)
4443 if has("service") and (.service | has("port")) and (.service.port | type == "number") then
4544 .service.port = (.service.port | tostring)
4645 else . end
47- ' > ${namespace}.json
48- - name : Cleanup environment
49- run : |
50- kubectl delete job -n ${namespace} --ignore-not-found=true data-cleanup
51- helm template -f ${namespace}.json \
52- --set data_cleanup.enabled=true \
53- --namespace ${namespace} \
54- -s templates/data-cleanup-job.yaml \
55- oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -
56- kubectl wait --for=condition=complete job/data-cleanup -n ${namespace} --timeout=600s || true
57- kubectl logs job/data-cleanup -f --all-containers=true -n ${namespace} || true
58- - name : Re-run postgres on-update-core
59- run : |
60- kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-update-core;
61- helm template -f ${namespace}.json \
62- --namespace ${namespace} \
63- -s templates/postgres-on-update-core.yaml \
64- oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -;
65- kubectl wait --for=condition=complete job/postgres-on-update-core -n ${namespace} --timeout=600s || true
66- kubectl logs job/postgres-on-update-core -f --all-containers=true -n ${namespace} || true
67- - name : Re-run postgres-data-migration
68- run : |
69- kubectl delete job -n ${namespace} --ignore-not-found=true postgres-data-migration;
70- helm template -f ${namespace}.json \
71- --namespace ${namespace} \
72- -s templates/postgres-migration-job.yaml \
73- oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -;
74- kubectl wait --for=condition=complete job/postgres-data-migration -n ${namespace} --timeout=600s || true
75- kubectl logs job/postgres-data-migration -f --all-containers=true -n ${namespace} || true
76- - name : Re-run postgres on-update-analytics
77- run : |
78- kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-update-analytics;
79- helm template -f ${namespace}.json \
80- -s templates/postgres-on-update-analytics.yaml \
81- --namespace ${namespace} \
82- oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -;
83- kubectl wait --for=condition=complete job/postgres-on-update-analytics -n ${namespace} --timeout=600s || true
84- kubectl logs job/postgres-on-update-analytics -f --all-containers=true -n ${namespace} || true
85- - name : Migration
86- run : |
87- kubectl delete job -n ${namespace} --ignore-not-found=true data-migration-on-reset
88- helm template -f ${namespace}.json \
89- --set data_migration.job_name=data-migration-on-reset \
90- -s templates/data-migration-job.yaml \
91- --namespace ${namespace} \
92- oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -
93- kubectl wait --for=condition=complete job/data-migration-on-reset -n ${namespace} --timeout=600s || true
94- kubectl logs job/data-migration-on-reset -f -n ${namespace} || true
95- - name : Seeding data
96- run : |
97- kubectl delete job -n ${namespace} --ignore-not-found=true data-seed
98- kubectl delete pod -n ${namespace} -lapp=events;
99- kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events --timeout=600s;
100- helm template -f ${namespace}.json \
101- --set data_seed.enabled=true \
102- --namespace ${namespace} \
103- -s templates/data-seed-job.yaml \
104- oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait -f -
105- sleep 10;
106- kubectl wait --for=condition=complete job/data-seed -n ${namespace} --timeout=600s || true
107- kubectl logs job/data-seed -f -n ${namespace} || true
108- kubectl delete pod -n ${namespace} -lapp=events;
46+ ' > /tmp/${namespace}.json
47+ echo "values-file=/tmp/${namespace}.json" >> $GITHUB_OUTPUT
48+ - name : Upload helm release values file /tmp/opencrvs-${{ inputs.environment }}.json
49+ uses : actions/upload-artifact@v4
50+ with :
51+ name : opencrvs-${{ inputs.environment }}-values-file
52+ path : /tmp/opencrvs-${{ inputs.environment }}.json
53+ retention-days : 1
54+ reset :
55+ name : ${{ matrix.job-name }}
56+ needs : prepare
57+ env :
58+ namespace : opencrvs-${{ inputs.environment }}
59+ runs-on : [self-hosted, k8s, e2e]
60+ strategy :
61+ max-parallel : 1 # Ensure jobs run one by one
62+ fail-fast : true # Stop on first failure
63+ matrix :
64+ job-name :
65+ - data-cleanup
66+ - postgres-on-update-core
67+ - postgres-data-migration
68+ - postgres-on-update-analytics
69+ - data-migration
70+ - data-seed
71+ - elasticsearch-reindex
72+ steps :
73+ - name : Download helm release values file into /tmp/opencrvs-${{ inputs.environment }}.json
74+ uses : actions/download-artifact@v4
75+ with :
76+ name : opencrvs-${{ inputs.environment }}-values-file
77+ path : /tmp
78+ - name : Create job ${{ matrix.job-name }} from helm template and apply it
79+ run : |
80+ kubectl delete job -n ${namespace} --ignore-not-found=true ${{ matrix.job-name }}
81+ helm template -f ${{ needs.prepare.outputs.values-file }} \
82+ --set data_cleanup.enabled=true \
83+ --set data_seed.enabled=true \
84+ --namespace ${namespace} \
85+ -s templates/${{ matrix.job-name }}-job.yaml \
86+ oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -
87+ - name : Checking ${{ matrix.job-name }} job status
88+ run : |
89+ while true; do
90+ kubectl wait --for=condition=ready pod -ljob-name=${{ matrix.job-name }} --timeout=300s -n ${namespace} && \
91+ kubectl logs job/${{ matrix.job-name }} --all-containers -f -n ${namespace} && \
92+ touch /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt || break;
93+ sleep 1; done &
94+ echo "---------------------- Waiting for job completion ----------------------"
95+ kubectl wait --for=condition=complete job/${{ matrix.job-name }} -n ${namespace} --timeout=600s; status=$? || true
96+ [ $status -ne 0 ] && kubectl get pods -n ${namespace} --show-labels && kubectl describe pod -ljob-name=${job_name} -n ${namespace};
97+ [ ! -f /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt ] && kubectl logs job/${{ matrix.job-name }} --all-containers -n ${namespace} || \
98+ rm -vf /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt
99+ kill %1 2>/dev/null && echo "Stopped log streaming" || true
100+ exit $status
0 commit comments