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...
Adapted from https://firebase.google.com/docs/functions/get-started
$ cd backend/functions
to switch to this folder$ yarn global add firebase-tools
to install the Firebase CLI globally$ yarn
to install JS dependencies$ firebase login
to authenticate the CLI tools to Firebase$ firebase use dev
to choose the dev project
-
Install gcloud CLI
-
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.
):$ brew install java
$ sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
-
$ gcloud auth login
to authenticate the CLI tools to Google Cloud -
$ gcloud config set project <project-id>
to choose the project ($ gcloud projects list
to see options)
Generate new private keys from the Google service account management page:
-
Dev: https://console.firebase.google.com/u/0/project/dev-mantic-markets/settings/serviceaccounts/adminsdk
-
Prod: https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk
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
-
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
- Or
-
If you want to test a scheduled function replace your function in test-backend-function.ts and run the file
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)
- Find local logs directly in the shell
- Find deployed logs in the Firebase console
- After merging, you need to manually deploy to backend:
git checkout main
git pull origin main
firebase use prod
to switch to prodfirebase deploy --only functions
to push your changes live!
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.