Skip to content

Commit 8647c54

Browse files
committed
Incrementally testing GH action.
1 parent e6ea1db commit 8647c54

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

.github/workflows/duplicate-prod-db.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ jobs:
1515
BUCKET_PROJECT_ID: ${{ vars.QA_MOBILITY_FEEDS_PROJECT_ID }}
1616
GCP_REGION: ${{ vars.MOBILITY_FEEDS_REGION }}
1717
DB_INSTANCE_NAME: ${{ secrets.DB_INSTANCE_NAME }}
18+
DEST_DATABASE_PASSWORD: ${{ secrets.QA_POSTGRE_USER_PASSWORD }}
1819
DUMP_FILE_NAME: "prod-db-dump.sql"
19-
DATABASE_NAME: "MobilityDatabase"
20+
SOURCE_DATABASE_NAME: ${{ secrets.PROD_POSTGRE_SQL_DB_NAME }}
21+
DEST_DATABASE_NAME: "testDB"
22+
DEST_DATABASE_USER: ${{ QA_POSTGRE_USER_NAME }}
23+
2024

2125
steps:
2226
- name: Checkout code
@@ -46,7 +50,7 @@ jobs:
4650
- name: GCloud Setup 2
4751
uses: google-github-actions/setup-gcloud@v2
4852

49-
- name: Create DB dump bucket and backup QA DB
53+
- name: Create DB dump bucket and give permissions
5054
run: |
5155
BUCKET_PROJECT_ID=$DEST_PROJECT_ID
5256
@@ -68,12 +72,6 @@ jobs:
6872
# Give read-write permission on the bucket to the destination sql instance
6973
gsutil iam ch serviceAccount:$DEST_SQL_SERVICE_ACCOUNT:objectAdmin gs://$DUMP_BUCKET_NAME
7074
71-
# Dump the QA database as a backup
72-
# According to chatgpt,
73-
# This is Google's recommended, safe method and doesn’t require direct access to the DB. It runs the export
74-
# in a way that avoids locking the database and works from GCP itself (so no traffic leaves GCP).
75-
gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/qa-db-dump-backup.sql --database=$DATABASE_NAME --quiet
76-
7775
- name: Authenticate to Google Cloud PROD project Again
7876
uses: google-github-actions/auth@v2
7977
with:
@@ -84,4 +82,22 @@ jobs:
8482

8583
- name: Dump the PROD DB
8684
run: |
87-
gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$DATABASE_NAME --quiet
85+
gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$SOURCE_DATABASE_NAME --quiet
86+
87+
- name: Authenticate to Google Cloud QA project Again Again
88+
uses: google-github-actions/auth@v2
89+
with:
90+
credentials_json: ${{ secrets.QA_GCP_MOBILITY_FEEDS_SA_KEY }}
91+
92+
- name: GCloud Setup 3
93+
uses: google-github-actions/setup-gcloud@v2
94+
run: |
95+
# Dump the QA database as a backup
96+
# According to chatgpt,
97+
# This is Google's recommended, safe method and doesn’t require direct access to the DB. It runs the export
98+
# in a way that avoids locking the database and works from GCP itself (so no traffic leaves GCP).
99+
gcloud sql export sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/qa-db-dump-backup.sql --database=$SOURCE_DATABASE_NAME --quiet
100+
101+
# Import the dump into the QA database
102+
export PGPASSWORD=$DEST_DATABASE_PASSWORD
103+
gcloud sql import sql $DB_INSTANCE_NAME gs://$DUMP_BUCKET_NAME/$DUMP_FILE_NAME --database=$DEST_DATABASE_NAME --user=$DEST_DATABASE_USER --quiet

0 commit comments

Comments
 (0)