Skip to content

Commit

Permalink
fix path in restore-app-main-db workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ltello committed Jan 31, 2025
1 parent b763846 commit bebd25e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
55 changes: 52 additions & 3 deletions .github/workflows/restore-app-main-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,31 @@ jobs:
- uses: actions/checkout@v4
name: Checkout

- uses: azure/login@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Restore app main database from Azure storage' step
Uses Step
uses 'azure/login' with ref 'v2', not a pinned commit hash
with:
creds: ${{ secrets.azure-credentials || secrets.AZURE_CREDENTIALS }}

- name: Set environment variables
run: |
source global_config/${{ inputs.environment }}.sh
# Load environment-specific configuration
source config/global_config/${{ inputs.environment }}.sh
tf_vars_file=${{ env.TF_VARS_PATH }}/${{ inputs.environment }}.tfvars.json
# Set Azure environment variables
echo "CLUSTER=$(jq -r '.cluster' ${tf_vars_file})" >> $GITHUB_ENV
echo "NAMESPACE=$(jq -r '.namespace' ${tf_vars_file})" >> $GITHUB_ENV
echo "RESOURCE_GROUP_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-rg" >> $GITHUB_ENV
echo "STORAGE_ACCOUNT_NAME=${AZURE_RESOURCE_PREFIX}${SERVICE_SHORT}dbbkp${CONFIG_SHORT}sa" >> $GITHUB_ENV
echo "DB_SERVER=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg" >> $GITHUB_ENV
echo "KEYVAULT_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-inf-kv" >> $GITHUB_ENV
- name: Generate the backup file name
run: |
# Load environment-specific configuration
source config/global_config/${{ inputs.environment }}.sh
TODAY=$(date +"%F")
# Set BACKUP_FILE variable
echo "BACKUP_FILE=${SERVICE_SHORT}_${CONFIG_SHORT}_${TODAY}.sql" >> $GITHUB_ENV
if [ "${{ inputs.backup-file }}" != "" ]; then
BACKUP_FILE=${{ inputs.backup-file }}
Expand All @@ -59,14 +75,47 @@ jobs:
fi
echo "BACKUP_FILE=$BACKUP_FILE" >> $GITHUB_ENV
- name: Fetch secrets from key vault
uses: azure/CLI@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Restore app main database from Azure storage' step
Uses Step: key-vault-secrets
uses 'azure/CLI' with ref 'v2', not a pinned commit hash
id: key-vault-secrets
with:
inlineScript: |
SLACK_WEBHOOK=$(az keyvault secret show --name "SLACK-WEBHOOK" --vault-name ${KEYVAULT_NAME} --query "value" -o tsv)
echo "::add-mask::$SLACK_WEBHOOK"
echo "SLACK_WEBHOOK=$SLACK_WEBHOOK" >> $GITHUB_OUTPUT
- name: Restore ${{ inputs.environment }} postgres
uses: DFE-Digital/github-actions/restore-postgres-backup@master
with:
storage-account: ${{ env.STORAGE_ACCOUNT_NAME }}
storage-account: c
resource-group: ${{ env.RESOURCE_GROUP_NAME }}
app-name: ${{ env.SERVICE_NAME }}-${{ inputs.environment }}
app-name: ${{ env.SERVICE_NAME }}-${{ inputs.environment }}-web
namespace: ${{ env.NAMESPACE }}
cluster: ${{ env.CLUSTER }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
backup-file: ${{ env.BACKUP_FILE }}

- name: Notify Slack channel on job success
if: success()
uses: rtCamp/action-slack-notify@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Restore app main database from Azure storage' step
Uses Step
uses 'rtCamp/action-slack-notify' with ref 'v2', not a pinned commit hash
env:
SLACK_USERNAME: CI Deployment
SLACK_TITLE: ${{ inputs.environment }} database restore succeeded
SLACK_MESSAGE: ${{ env.SERVICE_NAME }}-${{ inputs.environment }}-web - restore main db job from ${{ env.STORAGE_ACCOUNT_NAME }} / database-backup / ${{ env.BACKUP_FILE }} succeeded!
SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK }}
SLACK_COLOR: success
SLACK_FOOTER: Sent from restore-app-main workflow

- name: Notify Slack channel on job failure
if: failure()
uses: rtCamp/action-slack-notify@v2

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Restore app main database from Azure storage' step
Uses Step
uses 'rtCamp/action-slack-notify' with ref 'v2', not a pinned commit hash
env:
SLACK_USERNAME: CI Deployment
SLACK_TITLE: ${{ inputs.environment }} database restore failure
SLACK_MESSAGE: ${{ env.SERVICE_NAME }}-${{ inputs.environment }}-web - restore main db job from ${{ env.STORAGE_ACCOUNT_NAME }} / database-backup / ${{ env.BACKUP_FILE }} failed!
SLACK_WEBHOOK: ${{ env.SLACK_WEBHOOK }}
SLACK_COLOR: failure
SLACK_FOOTER: Sent from restore-app-main workflow
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ endef

# Creates a konduit to the DB and points development to it. The konduit URL is removed when the konduit is closed.
konduit: get-cluster-credentials
$(KONDUIT_CONNECT) ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg -n ${NAMESPACE} -k ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-app-kv npq-registration-${CONFIG_LONG}-web -- psql > "$$tmp_file"
$(KONDUIT_CONNECT) ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg -n ${NAMESPACE} -k ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-app-kv cpd-ec2-${CONFIG_LONG}-web -- psql > "$$tmp_file"
exit 0

# Creates a konduit to the snapshot DB and points development to it. The konduit URL is removed when the konduit is closed.
konduit-snapshot: get-cluster-credentials
$(KONDUIT_CONNECT) ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg-snapshot -n ${NAMESPACE} -k ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-app-kv npq-registration-${CONFIG_LONG}-web -- psql > "$$tmp_file"
$(KONDUIT_CONNECT) ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-pg-snapshot -n ${NAMESPACE} -k ${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-app-kv cpd-ec2-${CONFIG_LONG}-web -- psql > "$$tmp_file"
exit 0

set-namespace:
Expand Down

0 comments on commit bebd25e

Please sign in to comment.