diff --git a/.github/workflows/k8s-deploy.yml b/.github/workflows/k8s-deploy.yml index ee2654cd..b33f1082 100644 --- a/.github/workflows/k8s-deploy.yml +++ b/.github/workflows/k8s-deploy.yml @@ -143,4 +143,5 @@ jobs: uses: ./.github/workflows/k8s-reset-data.yml with: environment: ${{ inputs.environment }} + chart-branch: ${{ inputs.chart-branch }} secrets: inherit diff --git a/.github/workflows/k8s-reset-data.yml b/.github/workflows/k8s-reset-data.yml index b07fafbb..994e655d 100644 --- a/.github/workflows/k8s-reset-data.yml +++ b/.github/workflows/k8s-reset-data.yml @@ -1,16 +1,22 @@ name: Reset environment run-name: "Reset ${{ inputs.environment }} environment" on: - workflow_dispatch: - inputs: - environment: - description: "Target environment" - required: true - type: string - workflow_call: - inputs: - environment: - type: string + workflow_dispatch: + inputs: + environment: + description: "Target environment" + required: true + type: string + chart-branch: + description: 'Helm chart version to deploy' + required: false + default: 'develop' + workflow_call: + inputs: + environment: + type: string + chart-branch: + type: string jobs: prepare: outputs: @@ -58,37 +64,49 @@ jobs: matrix: job-name: - data-cleanup - - postgres-on-update-core - - postgres-on-update-analytics + - postgres-on-deploy + - data-migration-analytics - data-migration - data-seed - elasticsearch-reindex steps: - - name: Download helm release values file into /tmp/opencrvs-${{ inputs.environment }}.json - uses: actions/download-artifact@v4 - with: - name: opencrvs-${{ inputs.environment }}-values-file - path: /tmp - - name: Create job ${{ matrix.job-name }} from helm template and apply it - run: | - kubectl delete job -n ${namespace} --ignore-not-found=true ${{ matrix.job-name }} - helm template -f ${{ needs.prepare.outputs.values-file }} \ - --set data_cleanup.enabled=true \ - --set data_seed.enabled=true \ - --namespace ${namespace} \ - -s templates/${{ matrix.job-name }}-job.yaml \ - oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - - - name: Checking ${{ matrix.job-name }} job status - run: | - while true; do - kubectl wait --for=condition=ready pod -ljob-name=${{ matrix.job-name }} --timeout=300s -n ${namespace} && \ - kubectl logs job/${{ matrix.job-name }} --all-containers -f -n ${namespace} && \ - touch /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt || break; - sleep 1; done & - echo "---------------------- Waiting for job completion ----------------------" - kubectl wait --for=condition=complete job/${{ matrix.job-name }} -n ${namespace} --timeout=600s; status=$? || true - [ $status -ne 0 ] && kubectl get pods -n ${namespace} --show-labels && kubectl describe pod -ljob-name=${job_name} -n ${namespace}; - [ ! -f /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt ] && kubectl logs job/${{ matrix.job-name }} --all-containers -n ${namespace} || \ - rm -vf /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt - kill %1 2>/dev/null && echo "Stopped log streaming" || true - exit $status + - name: Checkout repo + uses: actions/checkout@v5 + # FIXME: Update to charts repository once available + - name: Checkout infrastructure repository + uses: actions/checkout@v5 + with: + repository: opencrvs/infrastructure + path: infrastructure + ref: ${{ inputs.chart-branch }} + - name: Verify branch status ${{ inputs.chart-branch }} + working-directory: infrastructure + run: git status + - name: Download helm release values file into /tmp/opencrvs-${{ inputs.environment }}.json + uses: actions/download-artifact@v4 + with: + name: opencrvs-${{ inputs.environment }}-values-file + path: /tmp + - name: Create job ${{ matrix.job-name }} from helm template and apply it + run: | + kubectl delete job -n ${namespace} --ignore-not-found=true ${{ matrix.job-name }} + helm template -f ${{ needs.prepare.outputs.values-file }} \ + --set data_cleanup.enabled=true \ + --set data_seed.enabled=true \ + --namespace ${namespace} \ + -s templates/${{ matrix.job-name }}-job.yaml \ + infrastructure/charts/opencrvs-services | kubectl apply -n ${namespace} --wait=true -f - + - name: Checking ${{ matrix.job-name }} job status + run: | + while true; do + kubectl wait --for=condition=ready pod -ljob-name=${{ matrix.job-name }} --timeout=300s -n ${namespace} && \ + kubectl logs job/${{ matrix.job-name }} --all-containers -f -n ${namespace} && \ + touch /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt || break; + sleep 1; done & + echo "---------------------- Waiting for job completion ----------------------" + kubectl wait --for=condition=complete job/${{ matrix.job-name }} -n ${namespace} --timeout=600s; status=$? || true + [ $status -ne 0 ] && kubectl get pods -n ${namespace} --show-labels && kubectl describe pod -ljob-name=${job_name} -n ${namespace}; + [ ! -f /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt ] && kubectl logs job/${{ matrix.job-name }} --all-containers -n ${namespace} || \ + rm -vf /tmp/logs_stramed-${namespace}-${{ matrix.job-name }}.txt + kill %1 2>/dev/null && echo "Stopped log streaming" || true + exit $status