|
1 | | -name: Reset environment (k8s) |
2 | | -run-name: "Reset environment (core: ${{ inputs.core-image-tag }})" |
| 1 | +name: Reset environment |
| 2 | +run-name: "Reset ${{ inputs.environment }} environment (namespace: ${{ inputs.namespace }})" |
3 | 3 | # FIXME: |
4 | 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 |
5 | 7 | on: |
6 | 8 | workflow_dispatch: |
7 | 9 | inputs: |
8 | | - core-image-tag: |
9 | | - description: "Core image tag" |
| 10 | + namespace: |
| 11 | + description: "Target namespace" |
10 | 12 | required: true |
11 | | - default: "develop" |
12 | | - type: string |
| 13 | + type: string |
13 | 14 | environment: |
14 | 15 | description: "Target environment" |
15 | 16 | required: true |
16 | | - default: "demo" |
17 | | - type: choice |
18 | | - options: |
19 | | - - dev |
20 | | - - demo |
| 17 | + type: string |
21 | 18 | workflow_call: |
22 | 19 | inputs: |
23 | | - core-image-tag: |
| 20 | + namespace: |
24 | 21 | type: string |
25 | 22 | environment: |
26 | 23 | type: string |
27 | 24 | jobs: |
28 | 25 | reset: |
| 26 | + environment: ${{ inputs.environment }} |
29 | 27 | env: |
30 | | - ENV: ${{ inputs.environment }} |
31 | | - CORE_IMAGE_TAG: ${{ inputs.core-image-tag }} |
32 | | - runs-on: [self-hosted] |
| 28 | + namespace: ${{ inputs.namespace }} |
| 29 | + runs-on: |
| 30 | + - self-hosted |
33 | 31 | steps: |
34 | | - # FYI: Repository is needed only due to single file: infrastructure/dev/dependenciess/values.yaml |
35 | | - - name: Checkout repo |
36 | | - uses: actions/checkout@v4 |
37 | | - - name: Update k8s-env/opencrvs/values.yaml |
38 | | - run: | |
39 | | - sed -i -e "s#{{STACK}}#${ENV}#g" k8s-env/opencrvs/values.yaml |
| 32 | + - name: Get helm release values |
| 33 | + run: helm get values opencrvs -n ${namespace} > ${namespace}.yaml |
40 | 34 | - name: Cleanup environment |
41 | 35 | run: | |
42 | | - kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-cleanup |
43 | | - helm template -f k8s-env/opencrvs/values.yaml \ |
| 36 | + kubectl delete job -n ${namespace} --ignore-not-found=true data-cleanup |
| 37 | + helm template -f ${namespace}.yaml \ |
44 | 38 | --set data_cleanup.enabled=true \ |
45 | | - --set image.tag="$CORE_IMAGE_TAG" \ |
46 | | - --namespace opencrvs-${ENV} \ |
| 39 | + --namespace ${namespace} \ |
47 | 40 | -s templates/data-cleanup-job.yaml \ |
48 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f - |
| 41 | + oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - |
49 | 42 | sleep 30; |
50 | | - kubectl logs job/data-cleanup -f --all-containers=true -n opencrvs-${ENV} || true |
51 | | - kubectl wait --for=condition=complete job/data-cleanup -n opencrvs-${ENV} --timeout=600s; |
52 | | - kubectl delete pod -n opencrvs-${ENV} -lapp=events; |
53 | | - kubectl wait --for=condition=ready pod -n opencrvs-${ENV} -lapp=events; |
| 43 | + kubectl logs job/data-cleanup -f --all-containers=true -n ${namespace} || true |
| 44 | + kubectl wait --for=condition=complete job/data-cleanup -n ${namespace} --timeout=600s; |
| 45 | + kubectl delete pod -n ${namespace} -lapp=events; |
| 46 | + kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events; |
54 | 47 | - name: Re-run postgres on-deploy |
55 | 48 | run: | |
56 | | - kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true postgres-on-deploy; |
57 | | - helm template -f k8s-env/opencrvs/values.yaml \ |
| 49 | + kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-deploy; |
| 50 | + helm template -f ${namespace}.yaml \ |
58 | 51 | -s templates/postgres-on-update.yaml \ |
59 | | - --set image.tag="$CORE_IMAGE_TAG" \ |
60 | | - --namespace opencrvs-${ENV} \ |
61 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f -; |
| 52 | + --namespace ${namespace} \ |
| 53 | + oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; |
62 | 54 | sleep 30; |
63 | | - kubectl logs job/postgres-on-deploy -f --all-containers=true -n opencrvs-${ENV}; |
64 | | - kubectl wait --for=condition=complete job/postgres-on-deploy -n opencrvs-${ENV} --timeout=600s; |
| 55 | + kubectl logs job/postgres-on-deploy -f --all-containers=true -n ${namespace}; |
| 56 | + kubectl wait --for=condition=complete job/postgres-on-deploy -n ${namespace} --timeout=600s; |
65 | 57 | - name: Migration |
66 | 58 | run: | |
67 | | - kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-migration |
68 | | - helm template -f k8s-env/opencrvs/values.yaml \ |
| 59 | + kubectl delete job -n ${namespace} --ignore-not-found=true data-migration |
| 60 | + helm template -f ${namespace}.yaml \ |
69 | 61 | -s templates/data-migration-job.yaml \ |
70 | | - --set image.tag="$CORE_IMAGE_TAG" \ |
71 | | - --namespace opencrvs-${ENV} \ |
72 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f - |
| 62 | + --namespace ${namespace} \ |
| 63 | + oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - |
73 | 64 | sleep 30; |
74 | | - kubectl logs job/data-migration -f -n opencrvs-${ENV} || true |
75 | | - kubectl wait --for=condition=complete job/data-migration -n opencrvs-${ENV} --timeout=600s; |
| 65 | + kubectl logs job/data-migration -f -n ${namespace} || true |
| 66 | + kubectl wait --for=condition=complete job/data-migration -n ${namespace} --timeout=600s; |
76 | 67 | - name: Re-run postgres on-deploy |
77 | 68 | run: | |
78 | | - kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true postgres-on-deploy; |
79 | | - helm template -f k8s-env/opencrvs/values.yaml \ |
| 69 | + kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-deploy; |
| 70 | + helm template -f ${namespace}.yaml \ |
80 | 71 | -s templates/postgres-on-update.yaml \ |
81 | | - --set image.tag="$CORE_IMAGE_TAG" \ |
82 | | - --namespace opencrvs-${ENV} \ |
83 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f -; |
| 72 | + --namespace ${namespace} \ |
| 73 | + oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; |
84 | 74 | sleep 30; |
85 | | - kubectl logs job/postgres-on-deploy -f --all-containers=true -n opencrvs-${ENV}; |
86 | | - kubectl wait --for=condition=complete job/postgres-on-deploy -n opencrvs-${ENV} --timeout=600s; |
| 75 | + kubectl logs job/postgres-on-deploy -f --all-containers=true -n ${namespace}; |
| 76 | + kubectl wait --for=condition=complete job/postgres-on-deploy -n ${namespace} --timeout=600s; |
87 | 77 | - name: Seeding data |
88 | 78 | run: | |
89 | | - kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-seed |
90 | | - kubectl delete pod -n opencrvs-${ENV} -lapp=events; |
91 | | - kubectl wait --for=condition=ready pod -n opencrvs-${ENV} -lapp=events; |
92 | | - helm template -f k8s-env/opencrvs/values.yaml \ |
| 79 | + kubectl delete job -n ${namespace} --ignore-not-found=true data-seed |
| 80 | + kubectl delete pod -n ${namespace} -lapp=events; |
| 81 | + kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events; |
| 82 | + helm template -f ${namespace}.yaml \ |
93 | 83 | --set data_seed.enabled=true \ |
94 | | - --set image.tag="$CORE_IMAGE_TAG" \ |
95 | | - --namespace opencrvs-${ENV} \ |
| 84 | + --namespace ${namespace} \ |
96 | 85 | -s templates/data-seed-job.yaml \ |
97 | | - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait -f - |
| 86 | + oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait -f - |
98 | 87 | sleep 30; |
99 | | - kubectl logs job/data-seed -f -n opencrvs-${ENV} || true |
100 | | - kubectl wait --for=condition=complete job/data-seed -n opencrvs-${ENV} --timeout=600s; |
101 | | - kubectl delete pod -n opencrvs-${ENV} -lapp=events; |
| 88 | + kubectl logs job/data-seed -f -n ${namespace} || true |
| 89 | + kubectl wait --for=condition=complete job/data-seed -n ${namespace} --timeout=600s; |
| 90 | + kubectl delete pod -n ${namespace} -lapp=events; |
0 commit comments