Skip to content

Latest commit

 

History

History
82 lines (50 loc) · 3.52 KB

README.md

File metadata and controls

82 lines (50 loc) · 3.52 KB

Firestore Cloud Functions

This is code that doesn't make sense on the frontend client, e.g.

  • Long-running or slow operation (database)
  • Tasks that need to be run every so often (syncing email list to Mailjet)
  • Anything we should't trust to clients (secrets, auth)

If you want to make and test changes, you'll have to do a bit of setup...

Installing

Adapted from https://firebase.google.com/docs/functions/get-started

  1. $ cd backend/functions to switch to this folder
  2. $ yarn global add firebase-tools to install the Firebase CLI globally
  3. $ yarn to install JS dependencies
  4. $ firebase login to authenticate the CLI tools to Firebase
  5. $ firebase use dev to choose the dev project

Installing for local development

  1. Install gcloud CLI

  2. If you don't have java (or see the error Error: Process java -version has exited with code 1. Please make sure Java is installed and on your system PATH.):

    1. $ brew install java
    2. $ sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
  3. $ gcloud auth login to authenticate the CLI tools to Google Cloud

  4. $ gcloud config set project <project-id> to choose the project ($ gcloud projects list to see options)

Setting up Authentication

Generate new private keys from the Google service account management page:

Set environment variable GOOGLE_APPLICATION_CREDENTIALS_PROD or GOOGLE_APPLICATION_CREDENTIALS_DEV in your shell to the path of the key file.

e.g. in ~/.zshrc or ~/.bashrc

export GOOGLE_APPLICATION_CREDENTIALS_DEV=~/dev-mantic-market.json

Developing locally

  • In root directory run $ ./dev.sh dev to start the dev functions, the /api docker image, and /web frontend. Note the database is the dev db.

    • Or $ yarn serve in this directory to start the functions only
  • If you want to test a scheduled function replace your function in test-backend-function.ts and run the file

Developing with localdb

Developing with a local copy of the database is deprecated. The old instructions are on Notion (or in the git history of this README file)

Debugging

  • Find local logs directly in the shell
  • Find deployed logs in the Firebase console

Deploying

  1. After merging, you need to manually deploy to backend:
  2. git checkout main
  3. git pull origin main
  4. firebase use prod to switch to prod
  5. firebase deploy --only functions to push your changes live!

Secrets management

Secrets are strings that shouldn't be checked into Git (eg API keys, passwords).

Add or remove keys using Google Secret Manager, which provides them as environment variables to functions that require them.

Dev secrets manager Prod secrets manager

Secondly, please update the list of secret keys at common/src/secrets.ts. Only these keys are provided to functions, scripts, and the api.