Skip to content

Database Update - PROD #5

Database Update - PROD

Database Update - PROD #5

# Update the Mobility Database Schema
name: Database Update - PROD
on:
release: # Update on merge on master if the changelog file has been updated
paths:
- "liquibase/changelog.xml"
workflow_dispatch:
repository_dispatch: # Update on mobility-database-catalog repo dispatch
types: [ catalog-sources-updated ]
jobs:
get_database_ip:
name: 'Retrieve DB IP'
permissions: write-all
runs-on: ubuntu-latest
outputs:
db_ip: ${{ steps.get_ip.outputs.DB_IP }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.PROD_GCP_MOBILITY_FEEDS_SA_KEY }}
- name: Google Cloud Setup
uses: google-github-actions/setup-gcloud@v1
- name: Get Database Instance IP
id: get_ip
run: |
gcloud config set project ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }}
DB_IP=$(gcloud sql instances describe ${{ secrets.DB_INSTANCE_NAME }} --format=json | jq -r '.ipAddresses[] | select(.type=="PRIMARY") | .ipAddress')
echo "DB_IP=$DB_IP" >> "$GITHUB_OUTPUT"
update:
uses: ./.github/workflows/db-update.yml
needs: get_database_ip
with:
PROJECT_ID: ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }}
DB_NAME: ${{ vars.PROD_POSTGRE_SQL_DB_NAME }}
REGION: ${{ vars.PROD_MOBILITY_FEEDS_REGION }}
ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
DB_IP: ${{needs.get_database_ip.outputs.db_ip}}
secrets:
DB_USER_PASSWORD: ${{ secrets.PROD_POSTGRE_USER_PASSWORD }}
DB_USER_NAME: ${{ secrets.PROD_POSTGRE_USER_NAME }}
DB_INSTANCE_NAME: ${{ secrets.DB_INSTANCE_NAME }}
GCP_MOBILITY_FEEDS_SA_KEY: ${{ secrets.PROD_GCP_MOBILITY_FEEDS_SA_KEY }}
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}