Reset dev environment #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Reset environment | |
| run-name: "Reset ${{ inputs.environment }} environment" | |
| # FIXME: | |
| # - replace sleep 30 with kubectl wait for job completion | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: "Target environment" | |
| required: true | |
| default: "dev" | |
| type: choice | |
| options: | |
| - demo | |
| - dev | |
| workflow_call: | |
| inputs: | |
| environment: | |
| type: string | |
| jobs: | |
| reset: | |
| environment: ${{ inputs.environment }} | |
| env: | |
| namespace: opencrvs-${{ inputs.environment }} | |
| runs-on: | |
| - self-hosted | |
| - k8s | |
| - ${{ inputs.environment }} | |
| steps: | |
| - name: Get helm release values and Quote specific fields that are commonly numeric | |
| run: | | |
| helm get values opencrvs -n ${namespace} -ojson | \ | |
| jq ' | |
| # Quote image tags | |
| if has("image") and (.image | has("tag")) and (.image.tag | type == "number") then | |
| .image.tag = (.image.tag | tostring) | |
| else . end | | |
| # Quote version numbers | |
| if has("version") and (.version | type == "number") then | |
| .version = (.version | tostring) | |
| else . end | | |
| # Quote port numbers if needed (optional) | |
| if has("service") and (.service | has("port")) and (.service.port | type == "number") then | |
| .service.port = (.service.port | tostring) | |
| else . end | |
| ' > ${namespace}.json | |
| - name: Cleanup environment | |
| run: | | |
| kubectl delete job -n ${namespace} --ignore-not-found=true data-cleanup | |
| helm template -f ${namespace}.json \ | |
| --set data_cleanup.enabled=true \ | |
| --namespace ${namespace} \ | |
| -s templates/data-cleanup-job.yaml \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - | |
| kubectl wait --for=condition=complete job/data-cleanup -n ${namespace} --timeout=600s; | |
| kubectl logs job/data-cleanup -f --all-containers=true -n ${namespace} || true | |
| - name: Re-run postgres on-update-core | |
| run: | | |
| kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-update-core; | |
| helm template -f ${namespace}.json \ | |
| --namespace ${namespace} \ | |
| -s templates/postgres-on-update-core.yaml \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; | |
| sleep 30; | |
| kubectl logs job/postgres-on-update-core -f --all-containers=true -n ${namespace}; | |
| kubectl wait --for=condition=complete job/postgres-on-update-core -n ${namespace} --timeout=600s; | |
| - name: Re-run postgres-data-migration | |
| run: | | |
| kubectl delete job -n ${namespace} --ignore-not-found=true postgres-data-migration; | |
| helm template -f ${namespace}.json \ | |
| --namespace ${namespace} \ | |
| -s templates/postgres-migration-job.yaml \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; | |
| sleep 30; | |
| kubectl logs job/postgres-data-migration -f --all-containers=true -n ${namespace}; | |
| kubectl wait --for=condition=complete job/postgres-data-migration -n ${namespace} --timeout=600s; | |
| - name: Re-run postgres on-update-analytics | |
| run: | | |
| kubectl delete job -n ${namespace} --ignore-not-found=true postgres-on-update-analytics; | |
| helm template -f ${namespace}.json \ | |
| -s templates/postgres-on-update-analytics.yaml \ | |
| --namespace ${namespace} \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f -; | |
| sleep 30; | |
| kubectl logs job/postgres-on-update-analytics -f --all-containers=true -n ${namespace}; | |
| kubectl wait --for=condition=complete job/postgres-on-update-analytics -n ${namespace} --timeout=600s; | |
| - name: Migration | |
| run: | | |
| kubectl delete job -n ${namespace} --ignore-not-found=true data-migration-on-reset | |
| helm template -f ${namespace}.json \ | |
| --set data_migration.job_name=data-migration-on-reset \ | |
| -s templates/data-migration-job.yaml \ | |
| --namespace ${namespace} \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - | |
| sleep 10; | |
| kubectl logs job/data-migration-on-reset -f -n ${namespace} || true | |
| kubectl wait --for=condition=complete job/data-migration-on-reset -n ${namespace} --timeout=600s; | |
| - name: Seeding data | |
| run: | | |
| kubectl delete job -n ${namespace} --ignore-not-found=true data-seed | |
| kubectl delete pod -n ${namespace} -lapp=events; | |
| kubectl wait --for=condition=ready pod -n ${namespace} -lapp=events --timeout=600s; | |
| helm template -f ${namespace}.json \ | |
| --set data_seed.enabled=true \ | |
| --namespace ${namespace} \ | |
| -s templates/data-seed-job.yaml \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait -f - | |
| sleep 10; | |
| kubectl wait --for=condition=complete job/data-seed -n ${namespace} --timeout=600s; | |
| kubectl logs job/data-seed -f -n ${namespace} || true | |
| kubectl delete pod -n ${namespace} -lapp=events; |