Skip to content

Database Update - PROD #8

Database Update - PROD

Database Update - PROD #8

Workflow file for this run

# 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@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.PROD_GCP_MOBILITY_FEEDS_SA_KEY }}
- name: Google Cloud Setup
uses: google-github-actions/setup-gcloud@v2
- 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=="PRIVATE") | .ipAddress')
echo "DB_IP=$DB_IP" >> "$GITHUB_OUTPUT"
gw_status:
name: 'Check GCP GW Machine Status'
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.PROD_GCP_MOBILITY_FEEDS_SA_KEY }}
- name: Google Cloud Setup
uses: google-github-actions/setup-gcloud@v2
- name: Check GCP Machine Status
id: check_gw_status
run: |
gcloud config set component_manager/disable_update_check true
STATUS=$(gcloud compute instances describe $INSTANCE_NAME --zone=$ZONE --format='get(status)')
echo "Instance status: $STATUS"
echo "status=$STATUS" >> $GITHUB_OUTPUT
env:
ZONE: ${{ vars.MOBILITY_FEEDS_REGION }}-a
INSTANCE_NAME: 'zerotier-instance-prod'
GCP_PROJECT_ID: ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }}
- name: Start GCP Machine if Not Running
if: steps.check_gw_status.outputs.status != 'RUNNING'
run: |
echo "Instance is not running. Starting instance..."
gcloud compute instances start $INSTANCE_NAME --zone=$ZONE
echo "Instance is starting. Please wait..."
sleep 60
env:
ZONE: ${{ vars.MOBILITY_FEEDS_REGION }}-a
INSTANCE_NAME: 'zerotier-instance-prod'
GCP_PROJECT_ID: ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }}
update:
uses: ./.github/workflows/db-update.yml
needs: [get_database_ip, gw_status]
with:
PROJECT_ID: ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }}
REGION: ${{ vars.MOBILITY_FEEDS_REGION }}
DB_NAME: ${{ vars.PROD_POSTGRE_SQL_DB_NAME }}
ENVIRONMENT: ${{ vars.PROD_MOBILITY_FEEDS_ENVIRONMENT }}
DB_IP: ${{needs.get_database_ip.outputs.db_ip}}
ZEROTIER_NETWORK_GW_KEY: "op://rbiv7rvkkrsdlpcrz3bmv7nmcu/GCP_FEED_PROD_ZEROTIER_NETWORK_GW/credential"
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 }}