Idea: GitLab CI/CD template for Google Firebase
Google Firebase is a BaaS (backend as a service) provider used by a lot of teams to deploy mobile apps. We should have a CI/CD template that helps folks deploy to Firebase.
Details
Learn more about using firebase with CI systems here: https://firebase.google.com/docs/cli#cli-ci-systems
Example
default:
image: node:12-alpine3.11
cache:
paths:
- node_modules/
- functions/node_modules/
stages:
- prepare
- build
- test
- stage
- deploy
- test
workflow:
rules:
- if: "$CI_MERGE_REQUEST_IID"
- if: "$CI_COMMIT_TAG"
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
build-web:
stage: build
script:
- yarn
- yarn build
artifacts:
paths:
- dist/
expire_in: 1 year
build-fns:
stage: build
script:
- cd functions
- npm i
- npm run build
artifacts:
paths:
- functions/lib
expire_in: 1 year
deploy-prod:
stage: deploy
script:
- cd functions
- npm i
- cd ..
- npm install -g firebase-tools
- echo $FIREBASE_TOKEN
- firebase use default
- firebase deploy --token "$FIREBASE_TOKEN"
rules:
- if: "$CI_COMMIT_TAG"
backup-firestore:
image: google/cloud-sdk:latest
stage: build
script:
- echo $GCP_SA_KEY | base64 -d > google-creds.json
- gcloud auth activate-service-account --key-file=google-creds.json
- gcloud info
- gcloud config set project $GCP_PROJECT_ID
- gcloud firestore export $GCP_BUCKET
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
sast:
stage: test
include:
- template: Security/SAST.gitlab-ci.yml
Edited by Brendan O'Leary