"P2, Recapping the Speedrun of Serverless,
With Google Cloud Console (UI)"
For the slides in P1, go here
See more on choosing the appropriate
App Engine environment here
runtime: nodejs10
instance_class: B1
manual_scaling:
instances: 1
handlers:
- url: /static
static_dir: static
- url: /public
static_dir: public
- url: /client-assets
static_dir: client-assets
Add the above in the root dir of project as app.yaml
App Engine configuration differs between environment (Standard VS Flexible). Do check out the standard configuration here and flexible configuration here .
See code base that I used here .
timeout: '600s'
steps:
- id: init
waitFor: ['-']
name: 'gcr.io/cloud-builders/npm'
args: ['install']
- id: frontendTest
waitFor: ['init']
name: 'gcr.io/cloud-builders/npm'
args: ['run', 'f-test']
- id: backendTest
waitFor: ['init']
name: 'gcr.io/cloud-builders/npm'
args: ['run', 'b-test']
- id: buildAssets
waitFor: ['frontendTest', 'backendTest']
name: 'gcr.io/cloud-builders/npm'
args: ['run', 'build']
- id: appEngineDeploy
waitFor: ['buildAssets']
name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'deploy', '-q', '--project', '$PROJECT_ID']
- id: cloudRunDeploy
waitFor: ['frontendTest', 'backendTest']
name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'sh'
args:
- -c
- |
gcloud builds submit --tag gcr.io/$PROJECT_ID/webapp:1 -q
gcloud beta run deploy --image gcr.io/$PROJECT_ID/webapp:1 -q --allow-unauthenticated --platform="managed" --region="us-central1" webapp
Add the above in the root dir of project as cloudbuild.yaml
The above runs the application's unit tests, before building the assets and deploying the applications to Cloud Run and App Engine. See here for more details on Cloud Build's configuration.
Committing the code above will trigger Cloud Build to starting building based on the trigger from #6
Note that you might want to omit the usage of Cloud Run if you're using App Engine, or vice versa, as you only need to serve a web application from one of them. Amend from the Cloud Build steps to select the tool to use for your web application.
Deploying using both tools during the speedrun was part of the challenge to show how easy it was to get started with "serverless" XD
Linkedin / Github : bit.ly/weiyuan