Skip to content

Instantly share code, notes, and snippets.

@DennisAlund
Created April 25, 2020 13:11
Show Gist options
  • Save DennisAlund/8c3fed2f47467c5dd93ddc0732f3dbe6 to your computer and use it in GitHub Desktop.
Save DennisAlund/8c3fed2f47467c5dd93ddc0732f3dbe6 to your computer and use it in GitHub Desktop.
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/github-actions@0.1.2
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/github-actions@0.1.2
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/github-actions@0.1.2
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/github-actions@0.1.2
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/firebase-action@v1.3.0
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/firebase-action@v1.3.0
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