Created
April 25, 2020 13:11
-
-
Save DennisAlund/8c3fed2f47467c5dd93ddc0732f3dbe6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Restore staging environment | |
env: | |
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }} | |
on: | |
pull_request: | |
branches: | |
- master | |
jobs: | |
remove-staging-backups: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup gcloud environment | |
uses: GoogleCloudPlatform/[email protected] | |
with: | |
project_id: example-staging | |
service_account_key: ${{ secrets.GCLOUD_AUTH_KEY_STAGING }} | |
- name: Select project | |
run: gcloud config set project example-staging | |
# The staging backups bucket will be soiled with production project backups | |
# since we're copying buckets in the subsequent job | |
- name: Remove redundant RTDB backups | |
run: | | |
gsutil rm gs://example-staging-backups/*prod_rules.json.gz | |
gsutil rm gs://example-staging-backups/*prod_data.json.gz | |
- name: Remove Firestore backups | |
run: gsutil rm -r gs://example-staging-backups/firestore | |
- name: Remove RTDB backups | |
run: gsutil rm -r gs://example-staging-backups/rtdb | |
copy-cloud-storage: | |
runs-on: ubuntu-latest | |
needs: remove-staging-backups | |
strategy: | |
fail-fast: true | |
matrix: | |
# Copy the backups bucket in order to restore Firestore from same bucket in same project | |
bucket: [".appspot.com", "-upload", "-backups"] | |
steps: | |
- name: Setup gcloud environment | |
uses: GoogleCloudPlatform/[email protected] | |
with: | |
project_id: example-staging | |
service_account_key: ${{ secrets.GCLOUD_AUTH_KEY_STAGING }} | |
- name: Select project | |
run: gcloud config set project example-staging | |
- name: Copy default storage bucket | |
run: gsutil cp -r gs://example-prod${{ matrix.bucket }}/* gs://example-staging${{ matrix.bucket }} | |
restore-firestore: | |
runs-on: ubuntu-latest | |
needs: copy-cloud-storage | |
steps: | |
- name: Setup gcloud environment | |
uses: GoogleCloudPlatform/[email protected] | |
with: | |
project_id: example-staging | |
service_account_key: ${{ secrets.GCLOUD_AUTH_KEY_STAGING }} | |
- name: Select project | |
run: gcloud config set project example-staging | |
- name: Import Firestore from Cloud Storage bucket | |
run: gcloud firestore import gs://example-staging-backups/firestore/snapshot --async | |
reset-rtdb: | |
runs-on: ubuntu-latest | |
needs: copy-cloud-storage | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup gcloud environment | |
uses: GoogleCloudPlatform/[email protected] | |
with: | |
project_id: example-staging | |
service_account_key: ${{ secrets.GCLOUD_AUTH_KEY_STAGING }} | |
- name: Select project | |
run: gcloud config set project example-staging | |
- name: Select Firebase project | |
uses: w9jds/[email protected] | |
with: | |
args: use staging | |
- name: Download RTDB data from Cloud Storage Bucket | |
run: gsutil cp gs://example-staging-backups/rtdb/snapshot.json . | |
- name: Set RTDB data | |
uses: w9jds/[email protected] | |
with: | |
args: database:set --confirm / snapshot.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment