Skip to content

Run Liquibase Migrations #2

Run Liquibase Migrations

Run Liquibase Migrations #2

Workflow file for this run

name: Run Liquibase Migrations
on:
workflow_dispatch:
inputs:
version:
description: "Version tag for the container"
required: true
type: string
account:
description: "Target AWS account"
required: true
type: choice
options:
- nonprod
- prod
dry_run:
description: "Run in dry-run mode (show pending changes only)"
required: true
type: boolean
default: true
ref:
description: "Git ref to checkout (branch, tag, or commit SHA)"
required: false
type: string
default: "main"
submit_job:
description: "Submit AWS Batch job after building"
required: true
type: boolean
default: false
workflow_call:
inputs:
version:
type: string
required: true
push:
type: boolean
required: true
default: false
account:
type: string
required: true
ref:
type: string
required: false
default: "main"
env:
REGISTRY: 054614622558.dkr.ecr.eu-west-1.amazonaws.com
AWS_REGION: ${{ vars.DVSA_AWS_REGION }}
AWS_OIDC_ROLE: ${{ (inputs.account || github.event.inputs.account) == 'prod' && vars.ACCOUNT_PROD_TF_OIDC_ROLE || vars.ACCOUNT_NONPROD_TF_OIDC_ROLE }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.event.inputs.ref }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Configure AWS credentials
if: ${{ inputs.push || github.event_name == 'workflow_dispatch' }}
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_OIDC_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to ECR
if: ${{ inputs.push || github.event_name == 'workflow_dispatch' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./infra/docker/liquibase
push: ${{ inputs.push || github.event_name == 'workflow_dispatch' }}
tags: |
${{ env.REGISTRY }}/vol-app/liquibase:${{ inputs.version || github.event.inputs.version }}
${{ env.REGISTRY }}/vol-app/liquibase:latest
cache-from: type=gha,scope=liquibase
cache-to: type=gha,mode=max,scope=liquibase
build-args: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
submit-batch-job:
needs: build
if: |
(inputs.push || (github.event_name == 'workflow_dispatch' && github.event.inputs.submit_job == 'true'))
runs-on: ubuntu-latest
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ env.AWS_OIDC_ROLE }}
aws-region: ${{ env.AWS_REGION }}
- name: Submit AWS Batch job
run: |
aws batch submit-job \
--job-name "liquibase-migration-${{ inputs.version || github.event.inputs.version }}" \
--job-queue "${{ (inputs.account || github.event.inputs.account) == 'prod' && vars.ACCOUNT_PROD_BATCH_JOB_QUEUE || vars.ACCOUNT_NONPROD_BATCH_JOB_QUEUE }}" \
--job-definition "${{ (inputs.account || github.event.inputs.account) == 'prod' && vars.ACCOUNT_PROD_BATCH_LIQUIBASE_JOB_DEFINITION || vars.ACCOUNT_NONPROD_BATCH_LIQUIBASE_JOB_DEFINITION }}" \
--container-overrides "{
\"image\": \"${{ env.REGISTRY }}/vol-app/liquibase:${{ inputs.version || github.event.inputs.version }}\",
\"environment\": [
{\"name\": \"DRY_RUN\", \"value\": \"${{ github.event.inputs.dry_run || 'false' }}\"}
]
}"