Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ltello committed Jan 31, 2025
1 parent 289c137 commit 314ab0d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Backup production and restore snapshot DB
description: Dump production DB and straight restore to snapshot DB keeping no copy in Azure Storage
name: Directly backup main db of an environment and restore snapshot db
description: Dump main db of an environment and directly restore to snapshot db bypassing Azure Storage

inputs:
environment:
Expand Down Expand Up @@ -33,7 +33,7 @@ runs:

- name: Set AKS credentials
shell: bash
run: make ci production get-cluster-credentials
run: make ci ${{ inputs.environment }} get-cluster-credentials

- name: Install kubectl
uses: DFE-Digital/github-actions/set-kubectl@master
Expand All @@ -56,7 +56,7 @@ runs:
shell: bash
run: |
NOW=$(TZ=Europe/London date +"%F %R")
echo 'STRAIGHT COPY OF PRODUCTION-SNAPSHOT DB SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY
echo 'DIRECT COPY OF ${{ inputs.environment }}->SNAPSHOT DB SUCCESSFUL!' >> $GITHUB_STEP_SUMMARY
echo ' APP: ${{ inputs.app-name }}' >> $GITHUB_STEP_SUMMARY
echo " AT : ${NOW}" >> $GITHUB_STEP_SUMMARY
Expand All @@ -65,19 +65,19 @@ runs:
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: CI Deployment
SLACK_TITLE: Nightly copy production-snapshot database succeeded
SLACK_MESSAGE: ${{ inputs.app-name }} - the straight copy of production-snapshot db succeeded
SLACK_TITLE: Direct copy ${{ inputs.environment }}->snapshot database succeeded
SLACK_MESSAGE: ${{ inputs.app-name }} - the direct copy of ${{ inputs.environment }}->snapshot db succeeded
SLACK_WEBHOOK: ${{ inputs.slack-webhook }}
SLACK_COLOR: success
SLACK_FOOTER: Sent from backup-and-restore-snapshot-database action
SLACK_FOOTER: Sent from directly-backup-and-restore-snapshot-database action

- name: Notify Slack channel on job failure
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: CI Deployment
SLACK_TITLE: Nightly backup production and straight restore of Snapshot database failed
SLACK_MESSAGE: ${{ inputs.app-name }} - the straight copy of production-snapshot db failed
SLACK_TITLE: Direct copy ${{ inputs.environment }}->snapshot database failed
SLACK_MESSAGE: ${{ inputs.app-name }} - the direct copy of ${{ inputs.environment }}->snapshot db failed
SLACK_WEBHOOK: ${{ inputs.slack-webhook }}
SLACK_COLOR: failure
SLACK_FOOTER: Sent from backup-and-restore-snapshot-database action
SLACK_COLOR: failures
SLACK_FOOTER: Sent from directly-backup-and-restore-snapshot-database action
14 changes: 13 additions & 1 deletion .github/workflows/backup-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ jobs:
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
echo "APP_NAME=${SERVICE_NAME}-${DEPLOY_ENV}-web" >> $GITHUB_ENV
- name: Generate the backup file name
run: |
Expand Down Expand Up @@ -117,9 +118,20 @@ jobs:
with:
storage-account: ${{ env.STORAGE_ACCOUNT_NAME }}
resource-group: ${{ env.RESOURCE_GROUP_NAME }}
app-name: ${{ env.SERVICE_NAME }}-${{ env.DEPLOY_ENV }}-web
app-name: ${{ env.APP_NAME }}
cluster: ${{ env.CLUSTER }}
azure-credentials: ${{ secrets.azure-credentials || secrets.AZURE_CREDENTIALS }}
backup-file: ${{ env.BACKUP_FILE }}.sql
db-server-name: ${{ inputs.db-server }}
slack-webhook: ${{ steps.key-vault-secrets.outputs.SLACK_WEBHOOK }}

- name: Notify Slack channel on job success
if: success()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_USERNAME: CI Deployment
SLACK_TITLE: ${{ env.DEPLOY_ENV }} database dump stored in Azure Storage (${{ env.STORAGE_ACCOUNT_NAME }}) - Success
SLACK_MESSAGE: ${{ env.APP_NAME }} - ${{ env.DEPLOY_ENV }} database backup job succeeded
SLACK_WEBHOOK: ${{ steps.key-vault-secrets.outputs.SLACK_WEBHOOK }}
SLACK_COLOR: success
SLACK_FOOTER: Sent from backup-db workflow
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
name: Nightly copy production main db into snapshot db keeping no backup in Azure Storage
name: Directly copy an env main db into to the snapshot db, bypassing Azure Storage

on:
workflow_dispatch:
inputs:
environment:
description: GitHub environment to backup and restore
description: GitHub environment to backup
type: choice
default: production
options:
- staging
- production
required: true

schedule:
- cron: "45 3 * * *" # 03:45 UTC

env:
SERVICE_NAME: cpd-ec2
SERVICE_SHORT: cpdec2
TF_VARS_PATH: config/terraform/application/config

jobs:
backup-production-and-restore-snapshot:
backup-main-db-and-restore-snapshot:
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment || 'production' }}
Expand Down Expand Up @@ -55,7 +52,7 @@ jobs:
echo "SLACK_WEBHOOK=$SLACK_WEBHOOK" >> $GITHUB_OUTPUT
- name: Backup and restore snapshot
uses: ./.github/actions/backup-and-restore-snapshot-database
uses: ./.github/actions/directly-backup-and-restore-snapshot-database
with:
environment: ${{ inputs.environment || 'production' }}
azure-credentials: ${{ secrets.AZURE_CREDENTIALS }}
Expand Down
12 changes: 0 additions & 12 deletions .github/workflows/nightly-backup-of-production-db.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Nightly copy production main db into snapshot db keeping backup in Azure Storage
name: Nightly copy production main db into the snapshot db keeping backup in Azure Storage

on:
workflow_dispatch:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Restore default app database from Azure storage
name: Restore app main database from Azure storage

on:
workflow_dispatch:
Expand Down

0 comments on commit 314ab0d

Please sign in to comment.