|
1 | 1 | name: Reset environment |
2 | | -run-name: "Reset ${{ inputs.environment }} environment (namespace: ${{ inputs.namespace }})" |
3 | | -# FIXME: |
4 | | -# - replace sleep 30 with kubectl wait for job completion |
5 | | -# - only environment variable is required, namespace could be build as "opencrvs-<environment>" |
6 | | -# but namespace is more natural way for kubernetes |
| 2 | +run-name: "Reset ${{ inputs.environment }} environment" |
7 | 3 | on: |
8 | 4 | workflow_dispatch: |
9 | 5 | inputs: |
10 | | - namespace: |
11 | | - description: "Target namespace" |
12 | | - required: true |
13 | | - type: string |
14 | 6 | environment: |
15 | 7 | description: "Target environment" |
16 | 8 | required: true |
17 | 9 | type: string |
18 | 10 | workflow_call: |
19 | 11 | inputs: |
20 | | - namespace: |
21 | | - type: string |
22 | 12 | environment: |
23 | 13 | type: string |
24 | 14 | jobs: |
| 15 | + prepare: |
| 16 | + outputs: |
| 17 | + values-file: ${{ steps.get-values.outputs.values-file }} |
| 18 | + env: |
| 19 | + namespace: opencrvs-${{ inputs.environment }} |
| 20 | + runs-on: [self-hosted, k8s, e2e] |
| 21 | + steps: |
| 22 | + - name: Get helm release values and Quote specific fields that are commonly numeric |
| 23 | + id: get-values |
| 24 | + run: | |
| 25 | + helm get values opencrvs -n ${namespace} -ojson | \ |
| 26 | + jq ' |
| 27 | + # Quote image tags |
| 28 | + if has("image") and (.image | has("tag")) and (.image.tag | type == "number") then |
| 29 | + .image.tag = (.image.tag | tostring) |
| 30 | + else . end | |
| 31 | + |
| 32 | + # Quote version numbers |
| 33 | + if has("version") and (.version | type == "number") then |
| 34 | + .version = (.version | tostring) |
| 35 | + else . end | |
| 36 | + |
| 37 | + # Quote port numbers if needed (optional) |
| 38 | + if has("service") and (.service | has("port")) and (.service.port | type == "number") then |
| 39 | + .service.port = (.service.port | tostring) |
| 40 | + else . end |
| 41 | + ' > /tmp/${namespace}.json |
| 42 | + echo "values-file=/tmp/${namespace}.json" >> $GITHUB_OUTPUT |
| 43 | + - name: Upload helm release values file /tmp/opencrvs-${{ inputs.environment }}.json |
| 44 | + uses: actions/upload-artifact@v4 |
| 45 | + with: |
| 46 | + name: opencrvs-${{ inputs.environment }}-values-file |
| 47 | + path: /tmp/opencrvs-${{ inputs.environment }}.json |
| 48 | + retention-days: 1 |
25 | 49 | reset: |
26 | | - environment: ${{ inputs.environment }} |
| 50 | + name: ${{ matrix.job-name }} |
| 51 | + needs: prepare |
27 | 52 | env: |
28 | | - namespace: ${{ inputs.namespace }} |
| 53 | + namespace: opencrvs-${{ inputs.environment }} |
29 | 54 | runs-on: [self-hosted, k8s, e2e] |
| 55 | + strategy: |
| 56 | + max-parallel: 1 # Ensure jobs run one by one |
| 57 | + fail-fast: true # Stop on first failure |
| 58 | + matrix: |
| 59 | + job-name: |
| 60 | + - data-cleanup |
| 61 | + - postgres-on-update-core |
| 62 | + - postgres-data-migration |
| 63 | + - postgres-on-update-analytics |
| 64 | + - data-migration |
| 65 | + - data-seed |
| 66 | + - elasticsearch-reindex |
30 | 67 | steps: |
31 | | - - name: Get helm release values and Quote specific fields that are commonly numeric |
32 | | - run: | |
33 | | - helm get values opencrvs -n ${namespace} -ojson | \ |
34 | | - jq ' |
35 | | - # Quote image tags |
36 | | - if has("image") and (.image | has("tag")) and (.image.tag | type == "number") then |
37 | | - .image.tag = (.image.tag | tostring) |
38 | | - else . end | |
39 | | - |
40 | | - # Quote version numbers |
41 | | - if has("version") and (.version | type == "number") then |
42 | | - .version = (.version | tostring) |
43 | | - else . end | |
44 | | - |
45 | | - # Quote port numbers if needed (optional) |
46 | | - if has("service") and (.service | has("port")) and (.service.port | type == "number") then |
47 | | - .service.port = (.service.port | tostring) |
48 | | - else . end |
49 | | - ' > ${namespace}.json |
50 | | - - name: Cleanup environment |
| 68 | + - name: Download helm release values file into /tmp/opencrvs-${{ inputs.environment }}.json |
| 69 | + uses: actions/download-artifact@v4 |
| 70 | + with: |
| 71 | + name: opencrvs-${{ inputs.environment }}-values-file |
| 72 | + path: /tmp |
| 73 | + - name: Create job ${{ matrix.job-name }} from helm template and apply it |
51 | 74 | run: | |
52 | | - kubectl delete job -n ${namespace} --ignore-not-found=true data-cleanup |
53 | | - helm template -f ${namespace}.json \ |
| 75 | + kubectl delete job -n ${namespace} --ignore-not-found=true ${{ matrix.job-name }} |
| 76 | + helm template -f ${{ needs.prepare.outputs.values-file }} \ |
54 | 77 | --set data_cleanup.enabled=true \ |
| 78 | + --set data_seed.enabled=true \ |
55 | 79 | --namespace ${namespace} \ |
56 | | - -s templates/data-cleanup-job.yaml \ |
57 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - |
58 | | - sleep 10; |
59 | | - kubectl wait --for=condition=complete job/data-cleanup -n ${namespace} --timeout=600s; |
60 | | - kubectl logs job/data-cleanup -f --all-containers=true -n ${namespace} || true |
61 | | - - name: Re-run postgres on-update-core |
62 | | - run: | |
63 | | - kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-update-core; |
64 | | - helm template -f ${namespace}.json \ |
65 | | - --namespace ${namespace} \ |
66 | | - -s templates/postgres-on-update-core-job.yaml \ |
67 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; |
68 | | - sleep 30; |
69 | | - kubectl logs job/postgres-on-update-core -f --all-containers=true -n ${namespace}; |
70 | | - kubectl wait --for=condition=complete job/postgres-on-update-core -n ${namespace} --timeout=600s; |
71 | | - - name: Re-run postgres-data-migration |
72 | | - run: | |
73 | | - kubectl delete job -n ${namespace} --ignore-not-found=true postgres-data-migration; |
74 | | - helm template -f ${namespace}.json \ |
75 | | - --namespace ${namespace} \ |
76 | | - -s templates/postgres-data-migration-job.yaml \ |
77 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; |
78 | | - sleep 30; |
79 | | - kubectl logs job/postgres-data-migration -f --all-containers=true -n ${namespace}; |
80 | | - kubectl wait --for=condition=complete job/postgres-data-migration -n ${namespace} --timeout=600s; |
81 | | - - name: Re-run postgres on-update-analytics |
82 | | - run: | |
83 | | - kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-update-analytics; |
84 | | - helm template -f ${namespace}.json \ |
85 | | - -s templates/postgres-on-update-analytics-job.yaml \ |
86 | | - --namespace ${namespace} \ |
87 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; |
88 | | - sleep 30; |
89 | | - kubectl logs job/postgres-on-update-analytics -f --all-containers=true -n ${namespace}; |
90 | | - kubectl wait --for=condition=complete job/postgres-on-update-analytics -n ${namespace} --timeout=600s; |
91 | | - - name: Migration |
92 | | - run: | |
93 | | - kubectl delete job -n ${namespace} --ignore-not-found=true data-migration-on-reset |
94 | | - helm template -f ${namespace}.json \ |
95 | | - --set data_migration.job_name=data-migration-on-reset \ |
96 | | - -s templates/data-migration-job.yaml \ |
97 | | - --namespace ${namespace} \ |
| 80 | + -s templates/${{ matrix.job-name }}-job.yaml \ |
98 | 81 | oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - |
99 | | - sleep 10; |
100 | | - kubectl logs job/data-migration-on-reset -f -n ${namespace} || true |
101 | | - kubectl wait --for=condition=complete job/data-migration-on-reset -n ${namespace} --timeout=600s; |
102 | | - - name: Seeding data |
| 82 | + - name: Checking ${{ matrix.job-name }} job status |
103 | 83 | run: | |
104 | | - kubectl delete job -n ${namespace} --ignore-not-found=true data-seed |
105 | | - kubectl delete pod -n ${namespace} -lapp=events; |
106 | | - kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events --timeout=600s; |
107 | | - helm template -f ${namespace}.json \ |
108 | | - --set data_seed.enabled=true \ |
109 | | - --namespace ${namespace} \ |
110 | | - -s templates/data-seed-job.yaml \ |
111 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait -f - |
112 | | - sleep 10; |
113 | | - kubectl wait --for=condition=complete job/data-seed -n ${namespace} --timeout=600s; |
114 | | - kubectl logs job/data-seed -f -n ${namespace} || true |
115 | | - kubectl delete pod -n ${namespace} -lapp=events; |
| 84 | + while true; do |
| 85 | + kubectl wait --for=condition=ready pod -ljob-name=${{ matrix.job-name }} --timeout=300s -n ${namespace} && \ |
| 86 | + kubectl logs job/${{ matrix.job-name }} --all-containers -f -n ${namespace} && \ |
| 87 | + touch /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt || break; |
| 88 | + sleep 1; done & |
| 89 | + echo "---------------------- Waiting for job completion ----------------------" |
| 90 | + kubectl wait --for=condition=complete job/${{ matrix.job-name }} -n ${namespace} --timeout=600s; status=$? || true |
| 91 | + [ $status -ne 0 ] && kubectl get pods -n ${namespace} --show-labels && kubectl describe pod -ljob-name=${job_name} -n ${namespace}; |
| 92 | + [ ! -f /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt ] && kubectl logs job/${{ matrix.job-name }} --all-containers -n ${namespace} || \ |
| 93 | + rm -vf /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt |
| 94 | + kill %1 2>/dev/null && echo "Stopped log streaming" || true |
| 95 | + exit $status |
0 commit comments