Skip to content

Commit

Permalink
Update workflows with github-actions changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RMcVelia committed Oct 14, 2024
1 parent 1bc3202 commit a1d6882
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 53 deletions.
46 changes: 15 additions & 31 deletions .github/workflows/backup-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Set environment variables
run: |
source global_config/${DEPLOY_ENV}.sh
Expand All @@ -60,8 +64,17 @@ jobs:
echo "BACKUP_FILE=${BACKUP_FILE}" >> $GITHUB_ENV
echo "KEYVAULT_NAME=${AZURE_RESOURCE_PREFIX}-${SERVICE_SHORT}-${CONFIG_SHORT}-inf-kv" >> $GITHUB_ENV
- name: Fetch secrets from key vault
uses: azure/CLI@v2
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: Backup ${{ env.DEPLOY_ENV }} postgres
uses: DFE-Digital/github-actions/backup-postgres@master
uses: DFE-Digital/github-actions/backup-postgres@2082-template-github-action-workflows
with:
storage-account: ${{ env.STORAGE_ACCOUNT_NAME }}
resource-group: ${{ env.RESOURCE_GROUP_NAME }}
Expand All @@ -70,33 +83,4 @@ jobs:
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
backup-file: ${{ env.BACKUP_FILE }}.sql
db-server-name: ${{ inputs.db-server }}

- name: Backup Summary
if: success()
run: |
NOW=$(TZ=Europe/London date +"%F %R")
echo 'BACKUP SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY
echo ' ENV: ${{ env.DEPLOY_ENV }}' >> $GITHUB_STEP_SUMMARY
echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY
echo ' DB SERVER: ${{ inputs.db-server || env.DB_SERVER }}' >> $GITHUB_STEP_SUMMARY
echo ' STORAGE ACCOUNT: ${{ env.STORAGE_ACCOUNT_NAME }}' >> $GITHUB_STEP_SUMMARY
echo ' FILENAME: ${{ env.BACKUP_FILE }}.sql.gz' >> $GITHUB_STEP_SUMMARY
- name: Get Slack webhook
uses: Azure/get-keyvault-secrets@v1
if: failure()
id: key-vault-secrets
with:
keyvault: ${{ env.KEYVAULT_NAME }}
secrets: "SLACK-WEBHOOK"

- name: Notify Slack channel on job failure
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: CI Deployment
SLACK_TITLE: Database backup failure
SLACK_MESSAGE: Production database backup job failed
SLACK_WEBHOOK: ${{ steps.key-vault-secrets.outputs.SLACK-WEBHOOK }}
SLACK_COLOR: failure
SLACK_FOOTER: Sent from backup job in backup-db workflow
slack-webhook: ${{ steps.key-vault-secrets.outputs.SLACK_WEBHOOK }}
13 changes: 1 addition & 12 deletions .github/workflows/postgres-ptr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,11 @@ jobs:
echo "NEW_DB_SERVER=${NEW_DB_SERVER}" >> $GITHUB_ENV
- name: Restore ${{ inputs.environment }} postgres
uses: DFE-Digital/github-actions/ptr-postgres@master
uses: DFE-Digital/github-actions/ptr-postgres@2082-template-github-action-workflows
with:
resource-group: ${{ env.RESOURCE_GROUP_NAME }}
source-server: ${{ env.DB_SERVER }}
new-server: ${{ env.NEW_DB_SERVER }}
restore-time: ${{ inputs.restore-time }}
cluster: ${{ env.CLUSTER }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS}}

- name: Restore Summary
if: success()
run: |
NOW=$(TZ=Europe/London date +"%F %R")
echo 'RESTORE SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY
echo ' ENV: ${{ inputs.environment }}' >> $GITHUB_STEP_SUMMARY
echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY
echo ' SOURCE SERVER: ${{ env.DB_SERVER }}' >> $GITHUB_STEP_SUMMARY
echo ' RESTORED SERVER: ${{ env.NEW_DB_SERVER }}' >> $GITHUB_STEP_SUMMARY
echo ' RESTORE POINT: ${{ inputs.restore-time }} UTC' >> $GITHUB_STEP_SUMMARY
11 changes: 1 addition & 10 deletions .github/workflows/postgres-restore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,4 @@ jobs:
cluster: ${{ env.CLUSTER }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
backup-file: ${{ env.BACKUP_FILE }}

- name: Restore Summary
if: success()
run: |
NOW=$(TZ=Europe/London date +"%F %R")
echo 'RESTORE SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY
echo ' ENV: ${{ inputs.environment }}' >> $GITHUB_STEP_SUMMARY
echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY
echo ' DB SERVER: ${{ env.DB_SERVER }}' >> $GITHUB_STEP_SUMMARY
echo ' BACKUP FILE RESTORED: ${{ env.BACKUP_FILE }}' >> $GITHUB_STEP_SUMMARY
db-server-name: ${{ env.DB_SERVER }}

0 comments on commit a1d6882

Please sign in to comment.