Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rollback for Github Action #863

Merged
merged 10 commits into from
Feb 12, 2024
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: ./.github/workflows/terraform-deploy_reusable.yml
with:
ENVIRONMENT: stg
TERRAFORM_DIRECTORY: operations/environments/staging
TERRAFORM_DIRECTORY: operations/environments/stg
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CDC_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_CDC_TENANT_ID }}
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/db_rollback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Rollback DB

on:
workflow_dispatch:
inputs:
halprin marked this conversation as resolved.
Show resolved Hide resolved
rollbackCount:
description: 'Number of migrations to rollback'
required: true
default: # of rollback you require in the file input
rollbackFile:
description: "File with migrations you want to rollback"
required: true
default: Filepath to yml
environment:
type: choice
description: "Azure environment to rollback on"
options:
- dev
- internal
- stg
- prd
required: true


jobs:
database-rollback:
name: Database Rollback
environment:
name: ${{ github.event.inputs.environment }}
runs-on: ubuntu-latest
env:
ARM_CLIENT_ID: ${{ github.event.inputs.environment == 'internal' && secrets.AZURE_CLIENT_ID || secrets.AZURE_CDC_CLIENT_ID }}
ARM_TENANT_ID: ${{ github.event.inputs.environment == 'internal' && secrets.AZURE_TENANT_ID || secrets.AZURE_CDC_TENANT_ID}}
ARM_SUBSCRIPTION_ID: ${{ github.event.inputs.environment == 'internal' && secrets.AZURE_SUBSCRIPTION_ID || secrets.AZURE_CDC_DMZ_C1_SUBSCRIPTION_ID}}
ARM_USE_OIDC: true
permissions:
id-token: write
contents: read

steps:

- uses: actions/checkout@v4

- name: Terraform Init
id: init
run: |
cd ./operations/environments/${{ github.event.inputs.environment }}
terraform init

- name: Login via Azure CLI
uses: azure/login@v1
with:
client-id: ${{ github.event.inputs.environment == 'internal' && secrets.AZURE_CLIENT_ID || secrets.AZURE_CDC_CLIENT_ID }}
tenant-id: ${{ github.event.inputs.environment == 'internal' && secrets.AZURE_TENANT_ID || secrets.AZURE_CDC_TENANT_ID}}
subscription-id: ${{ github.event.inputs.environment == 'internal' && secrets.AZURE_SUBSCRIPTION_ID || secrets.AZURE_CDC_DMZ_C1_SUBSCRIPTION_ID}}

- name: Extract database hostname and password into GitHub Env
run: |
cd ./operations/environments/${{ github.event.inputs.environment }}
DATABASE_HOSTNAME=$(terraform output -raw database_hostname)
DATABASE_PASSWORD=$(az account get-access-token --resource-type oss-rdbms --query "[accessToken]" -o tsv)
echo "::add-mask::$DATABASE_HOSTNAME"
echo "::add-mask::$DATABASE_PASSWORD"
echo "DATABASE_HOSTNAME=$DATABASE_HOSTNAME" >> "$GITHUB_ENV"
echo "DATABASE_PASSWORD=$DATABASE_PASSWORD" >> "$GITHUB_ENV"

- name: Run Db Rollback
halprin marked this conversation as resolved.
Show resolved Hide resolved
uses: liquibase-github-actions/[email protected]
with:
changelogFile: ${{ github.event.inputs.rollbackFile }}
count: ${{ github.event.inputs.rollbackCount }}
url: "jdbc:postgresql://${{ env.DATABASE_HOSTNAME }}:5432/postgres"
username: cdcti-github
password: ${{ env.DATABASE_PASSWORD }}
2 changes: 1 addition & 1 deletion .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: ./.github/workflows/terraform-deploy_reusable.yml
with:
ENVIRONMENT: prd
TERRAFORM_DIRECTORY: operations/environments/prod
TERRAFORM_DIRECTORY: operations/environments/prd
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CDC_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_CDC_TENANT_ID }}
Expand Down
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
"filename": "docker-compose.postgres.yml",
"hashed_secret": "0f7866a6cab6f2793ea9f68e92935e4d726d58b5",
"is_verified": false,
"line_number": 12,
"line_number": 15,
"is_secret": false
}
],
Expand Down Expand Up @@ -269,5 +269,5 @@
}
]
},
"generated_at": "2024-02-09T15:36:39Z"
"generated_at": "2024-02-09T17:58:04Z"
}
3 changes: 3 additions & 0 deletions docker-compose.postgres.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Run the following to migrate...
# liquibase update --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --label-filter '!azure'

# Run the following to rollback...
# liquibase rollback-count --changelog-file ./etor/databaseMigrations/root.yml --url jdbc:postgresql://localhost:5433/intermediary --username intermediary --password 'changeIT!' --count 2

version: "3.7"

services:
Expand Down
1 change: 1 addition & 0 deletions etor/databaseMigrations/azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ databaseChangeLog:
changes:
- sql:
sql: REASSIGN OWNED BY CURRENT_USER TO azure_pg_admin
rollback: empty
3 changes: 3 additions & 0 deletions etor/databaseMigrations/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ databaseChangeLog:
changes:
- sql:
sql: CREATE TYPE message_status AS ENUM ('PENDING', 'DELIVERED', 'FAILED')
rollback:
- sql:
sql: DROP TYPE message_status

- changeSet:
id: 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ output "publish_app" {

output "database_hostname" {
value = module.template.database_hostname
}
}
Loading