/serverless-boilerplate-typescript

Serverless boilerplate using typescript on GCP cloud functions

Primary LanguageTypeScript

Serverless Boilerplate Typescript

Setup

Create a service account under IAM & admin

Service account name: serverless-cicd
Service account ID: autogenerated id
  • Download the private in JSON format by clicking on Create key under Actions 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

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