Serverless Boilerplate Typescript
Setup
Create a service account under IAM & admin
- Choose the project from dropdown
- Navigate to Service accounts https://console.cloud.google.com/iam-admin/serviceaccounts
- Create a service account by click on
Create service account
eg
Service account name: serverless-cicd
Service account ID: autogenerated id
- Download the private in JSON format by clicking on
Create key
underActions
of the account. - Make sure change the role of the service account to
Editor
Encrypt the generated key
$ base64 /Users/xxx/xxx-xxx.json
copy the encrypted key
Add generated key into Environment Variables of CircleCI Project
- Navigate to CircleCI project https://circleci.com/gh/xxx/xxx/edit#env-vars
- Create a key by clicking
Add Variable
Name: GCLOUD_SERVICE_KEY
Value: paste encrypted key
- Create the following variables
GOOGLE_CLOUD_PROJECT_ID: xxxx
GOOGLE_COMPUTE_REGION: xxxx
Update config related to function (optional)
- navigate to
.circleci/config.yml
name: serverless-function-name
entry-point: helloWorld
runtime: nodejs10
memory: 128
timeout: 540
Dev Setup
Setup the app
$ nvm use
$ npm install
Use
$ npm run build
Others
$ npm run clean
$ npm run lint
$ npm run tslint-check
$ npm run tsc
$ npm run test
Deployment
CircleCI Lint -> Build -> Test -> Deploy
Access function
https://[region]-[project_id].cloudfunctions.net/serverless-function-name