Continuous deployment of a web service on Cloud Run

GitHub

Create a new repository and initialise it with a .gitignore for Node.

Clone the repository with GitHub Desktop or open it in GitHub Codespaces, then run yarn add express

Add a "start" script and "engines" definition to package.json:

  "scripts": {
	"start": "node app.js"
  },
  "engines": {
	"node": "14"
  },

Commit the changes to package.json and package-lock.json and push to the repository.

Add file > Create new file: app.js

require('express')().get('/', (req, res) => {
  res.send('Hello World!')
}).listen(process.env.PORT)

Cloud Run

Create Service

Choose a region (e.g. europe-west1)

Choose a service name

Choose “Continuously deploy new revisions from a source repository”

Choose "Setup with Cloud Build" and select the new GitHub repository

Choose "Go, Node.js, Python, Java or .NET Core via Google Cloud Buildpacks” as the Build Type

Allow unauthenticated invocations

Back in Service Details, choose Manage Custom Domains

Add Mapping

Select the new service

Choose a verified domain

Enter a subdomain

Cloudflare (or other DNS provider)

Add a CNAME pointing the subdomain to ghs.googlehosted.com