From 29a23c826396fdf6ff40c556756b741311358dbc Mon Sep 17 00:00:00 2001 From: Nischal Shrestha Date: Thu, 4 Jul 2024 16:32:00 +0545 Subject: [PATCH] feat: add ci for database migrations --- .../build_and_deploy_DTM_frontend.yml | 2 +- .github/workflows/migrations.yml | 38 +++++++++++++++++++ .github/workflows/test_frontend.yml | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/migrations.yml diff --git a/.github/workflows/build_and_deploy_DTM_frontend.yml b/.github/workflows/build_and_deploy_DTM_frontend.yml index 4f1c7685..b08fbc5d 100644 --- a/.github/workflows/build_and_deploy_DTM_frontend.yml +++ b/.github/workflows/build_and_deploy_DTM_frontend.yml @@ -24,7 +24,7 @@ jobs: name: ${{ github.ref_name }} steps: - name: Clone repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.ref_name }} diff --git a/.github/workflows/migrations.yml b/.github/workflows/migrations.yml new file mode 100644 index 00000000..55365854 --- /dev/null +++ b/.github/workflows/migrations.yml @@ -0,0 +1,38 @@ +name: Database Migrations + +on: + workflow_dispatch: + +permissions: + id-token: write + contents: read + +env: + AWS_REGION: ap-south-1 + ECR_REGISTRY: 685797548389.dkr.ecr.ap-south-1.amazonaws.com + ECR_REPOSITORY: dtmweb + +jobs: + migration: + name: Do migration on RDS + runs-on: ubuntu-latest + environment: + name: ${{ github.ref_name }} + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + audience: sts.amazonaws.com + aws-region: ${{ env.AWS_REGION }} + role-session-name: GH-Actions-${{ github.run_id }}-${{ github.run_attempt }} + role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }} + + - name: Run migration command + id: run-migration + shell: bash + run: | + TASK_ID=`aws ecs list-tasks --cluster ${{ secrets.ECS_CLUSTER_NAME }} --service ${{ secrets.ECS_SERVICE_NAME }} | jq -r .taskArns[0]` + aws ecs execute-command --cluster dtm-ecs-cluster --task $TASK_ID --region ${{env.AWS_REGION}} --interactive --command "/bin/bash -c 'pdm run alembic upgrade head'" diff --git a/.github/workflows/test_frontend.yml b/.github/workflows/test_frontend.yml index a0f30e71..25e315dd 100644 --- a/.github/workflows/test_frontend.yml +++ b/.github/workflows/test_frontend.yml @@ -22,7 +22,7 @@ jobs: name: ${{ github.ref_name }} steps: - name: Clone repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.ref_name }}