diff --git a/.github/workflows/db-update-dev.yml b/.github/workflows/db-update-dev.yml index 3a78681d7..15e4c065b 100644 --- a/.github/workflows/db-update-dev.yml +++ b/.github/workflows/db-update-dev.yml @@ -48,7 +48,7 @@ jobs: - name: Google Cloud Setup uses: google-github-actions/setup-gcloud@v2 - + - name: Check GCP Machine Status id: check_gw_status run: | @@ -74,7 +74,7 @@ jobs: GCP_PROJECT_ID: ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }} update: - needs: get_database_ip + needs: [get_database_ip, gw_status] uses: ./.github/workflows/db-update.yml with: PROJECT_ID: ${{ vars.DEV_MOBILITY_FEEDS_PROJECT_ID }} diff --git a/.github/workflows/db-update-prod.yml b/.github/workflows/db-update-prod.yml index c2d92a234..8944879cd 100644 --- a/.github/workflows/db-update-prod.yml +++ b/.github/workflows/db-update-prod.yml @@ -33,9 +33,46 @@ jobs: 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 + needs: [get_database_ip, gw_status] with: PROJECT_ID: ${{ vars.PROD_MOBILITY_FEEDS_PROJECT_ID }} REGION: ${{ vars.MOBILITY_FEEDS_REGION }} diff --git a/.github/workflows/db-update-qa.yml b/.github/workflows/db-update-qa.yml index 250e3d36f..9270ec5ba 100644 --- a/.github/workflows/db-update-qa.yml +++ b/.github/workflows/db-update-qa.yml @@ -34,10 +34,46 @@ jobs: gcloud config set project ${{ vars.QA_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.QA_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-qa' + GCP_PROJECT_ID: ${{ vars.QA_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-qa' + GCP_PROJECT_ID: ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }} update: uses: ./.github/workflows/db-update.yml - needs: get_database_ip + needs: [get_database_ip, gw_status] with: PROJECT_ID: ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }} REGION: ${{ vars.MOBILITY_FEEDS_REGION }}