From a2f729d7317c7cc4caf287c5b37156ae68d2948a Mon Sep 17 00:00:00 2001 From: Colin Saliceti Date: Wed, 27 Nov 2024 19:53:23 +0000 Subject: [PATCH] fix2 --- .github/workflows/database.yaml | 63 +++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/.github/workflows/database.yaml b/.github/workflows/database.yaml index 9756405c1..edee59b1a 100644 --- a/.github/workflows/database.yaml +++ b/.github/workflows/database.yaml @@ -148,15 +148,58 @@ jobs: source global_config/${GLOBAL_CONFIG}.sh tf_vars_file=${TF_VARS_PATH}/${CONFIG}/variables.tfvars.json echo "CLUSTER=$(jq -r '.cluster' ${tf_vars_file})" >> $GITHUB_ENV - echo "APP_ENVIRONMENT=$(jq -r '.app_environment' ${tf_vars_file})" >> $GITHUB_ENV - echo "SANITISED_FILE_NAME=afqts_sanitised_$(date +"%F")" >> $GITHUB_ENV + APP_ENVIRONMENT=$(jq -r '.app_environment' ${tf_vars_file}) + echo "SANITISED_FILE_NAME=afqts_sanitised_$(date +"%F").sql.gz" >> $GITHUB_ENV + echo "APP_NAME=${SERVICE_NAME}-${APP_ENVIRONMENT}-web" >> $GITHUB_ENV + echo "cluster_rg=s189t01-tsc-ts-rg" >> $GITHUB_ENV + echo "cluster_name=s189t01-tsc-test-aks" >> $GITHUB_ENV - - name: Restore sanitised backup to preproduction postgres - uses: DFE-Digital/github-actions/restore-postgres-backup@master + - uses: azure/login@v2 with: - storage-account: s189t01afqtsdbbkpppsa - resource-group: s189t01-afqts-pp-rg - app-name: ${{ env.SERVICE_NAME }}-${{ env.APP_ENVIRONMENT }}-web - cluster: ${{ env.CLUSTER }} - azure-credentials: ${{ secrets.AZURE_CREDENTIALS }} - backup-file: ${{ env.SANITISED_FILE_NAME }}.sql.gz + creds: ${{ inputs.AZURE_CREDENTIALS_PREPRODUCTION }} + + - name: Set Connection String + run: | + STORAGE_CONN_STR=$(az storage account show-connection-string -g s189t01-afqts-pp-rg -n s189t01afqtsdbbkpppsa --query 'connectionString') + echo "::add-mask::$STORAGE_CONN_STR" + echo "AZURE_STORAGE_CONNECTION_STRING=$STORAGE_CONN_STR" >> $GITHUB_ENV + + - name: Download Backup from Azure Storage + run: | + az config set extension.use_dynamic_install=yes_without_prompt + az config set core.only_show_errors=true + az storage azcopy blob download --container database-backup \ + --source ${{ env.SANITISED_FILE_NAME }} --destination ${{ env.SANITISED_FILE_NAME }} + + - name: Setup postgres client + uses: DFE-Digital/github-actions/install-postgres-client@master + with: + version: 14 + + - name: Install kubectl + uses: DFE-Digital/github-actions/set-kubectl@master + + - uses: DFE-Digital/github-actions/set-kubelogin-environment@master + with: + azure-credentials: ${{ secrets.azure-credentials }} + + - name: K8 setup + run: | + az aks get-credentials --overwrite-existing -g ${cluster_rg} -n ${cluster_name} + kubelogin convert-kubeconfig -l spn + # install konduit + curl -s https://raw.githubusercontent.com/DFE-Digital/teacher-services-cloud/master/scripts/konduit.sh -o ./konduit.sh + chmod +x ./konduit.sh + + - name: Restore backup to aks env database + run: | + ./konduit.sh -i ${SANITISED_FILE_NAME} -c -t 7200 -x ${APP_NAME} -- psql + + - name: Restore Summary + if: success() + run: | + NOW=$(TZ=Europe/London date +"%F %R") + echo 'RESTORE SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY + echo ' APP: ${APP_NAME}' >> $GITHUB_STEP_SUMMARY + echo ' BACKUP FILE RESTORED: s189t01afqtsdbbkpppsa / database-backup / ${SANITISED_FILE_NAME}' >> $GITHUB_STEP_SUMMARY + echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY