Table of Contents
Node and npm
Install node and npm
Gatsby
npm install -g gatsby-cli
Gatsby
- Run
npm install
in the root dir - Run
npm run start
- Any environemnt variables go into
.env.development
for local development and intocloudbuild-prod|staging.yaml
for prod / staging.
Cloud Functions
- Navigate to
functions/
and runnpm run install
. - Login in gcloud cli
- Setup your local runtime. Under
functions/
run:
firebase functions:config:get --project dps-website-staging-0 > .runtimeconfig.json
This would provide all the configs from google cloud runtime on your local PC so you can run functions locally. Please never commit .runtimeconfig.json
to git, because this is sensitive information.
-
Authentication: run both
gcloud auth login
followed bygcloud auth application-default login
so that the local environment has access of default credentials. See ADC credentials discovery. -
Running
npm run serve
will start the functions locally. However, those functions connect tofirestore
on the cloud. The other option would be to startfirestore
emulator as well, but for now we like the cloud one, because it provides nice UI and is less hassle to setup. Those functions would connect against our stagingcloud storage
as well. -
In order to authenticate against
firestore
andcloud storage
, you need to go to the dps-website-staging project and download the key for[email protected]
and put it underfunctions/
with namedps-website-staging.firebase.key.json
. -
Now you can experiment against the functions that run locally and are accessible via localhost, but they access our staging database & storage.
-
For faster iterations, we recommend developing via tests if possible
Functions such as sending confirmation mails and storing data into Google sheets require OAuth credentials. The following steps guide you to get the required tokens.
-
Login into
https://console.developers.google.com/
and choose the working project. -
Then go to the credentials tab, click on
create credentials
and chooseOAuth client id
. You would be redirected toCreate OAuth client ID
screen. -
Choose
Application type
asWeb application
and then specify the name of your application and forAuthorised redirect URIs
specifyhttps://developers.google.com/oauthplayground
and press enter (very important). We use oauthplayground to access refresh token. Click onSave
thenOAuth client
screen would pop up containingclient ID
andclient secret
. Save them as you would require these later to create refresh token. -
Now visit
https://developers.google.com/oauthplayground/
. Click on the settings tab located in far right and thenOAuth 2.0 configuration
screen would pop up. ChooseUse your own OAuth credentials
option and then specifyOAuth Client ID
andOAuth Client secret
that you had saved before. -
Now in the far left, select the scope for the APIs you would like to access and click on authorise APIs. You would be then asked to choose your gmail account and then allow the application to access that account.
-
You would be redirected to the Oauth playground screen and under step 2 click on
Exchange authorization code for tokens
to get your refresh token. Save this refresh token as you would need it in firebase functions to access the APIs. This refresh token helps you to get the access token.
While in development we use ADC credentials discovery via credential: admin.credential.applicationDefault(), I haven't figured out how to use default credentials in tests as well, so we use a file instead.
In order to authenticate against firestore
and cloud storage
, you need to go to the dps-website-staging project and download the key for [email protected]
and put it under functions/
with name dps-website-staging.firebase.key.json
.
We have unit tests under __test__/
, you could run them via npm run test
or npm run test:watch
. Those should test against functionality that's not related to database or storage - mostly pure functions.
You could find integration tests under __test__/
and run them via npm run integrationtest
or npm run integrationtest:watch
. Those tests would be executed against the database
and storage
staging environment.
Unfortunately, some things such as file uploads are very difficult to test, so we recommend weighting out the benefits of writing tests there and thinking about what to mock.
- Write a cloud function
- Write unit tests
- Write integration tests
- Go manually over the flow to see if it works
- Deploy the function to staging & make sure it works
- Deploy the function to production
We don't have CI yet. You'll need to be logged into gcloud cli and have the appropriate premissions.
npm run deploy:staging
Any push to staging branch is being deployed via cloudbuild-staging.yaml
npm run deploy:production
Any push to master branch is being deplopyed via cloudbuild-prod.yaml
Following are the people who contributed in the development of this website:
Bela Sinoimeri |
Bhawna Saini |
Lyubomir Stoykov |
Daniel Bedo |
Michael Stockerl |
Bastian Rieder |
Benji Rothman |