Sapper On Cloud Run

A boilerplate to deploy Sapper (Svelte) applications to Cloud Run (


A boilerplate to deploy Sapper (Svelte) applications to Cloud Run (

A demo is available at

Blog posts

Two corresponding blog posts are available with details:

Docker local testing

The following NPM scripts assist with testing the container image locally:

  • npm run dev:docker:build: Builds the docker image.
  • npm run dev:docker:run: Runs the docker image locally on port 3000.

Set up the Artifact Registry

# Enable the Artifact Registry API
gcloud services enable

# Create an Artifact Registry repository to host docker images
gcloud beta artifacts repositories create docker-repository --repository-format=docker \

Set up Cloud Build

# Enable the Cloud Build API
gcloud services enable

# Create a build trigger
gcloud beta builds triggers create github \
--repo-name=sapper-on-cloud-run \
--repo-owner=mikenikles \
--branch-pattern="^master$" \

Set up Cloud Run

# Obtain the numeric project ID
# Use: gcloud projects list --filter="$(gcloud config get-value project)" --format="value(PROJECT_NUMBER)"

# Grant the Cloud Run Admin role
gcloud projects add-iam-policy-binding $PROJECT_ID \
  --member "" \
  --role roles/run.admin

# Grant access to Cloud Build to deploy to Cloud Run
gcloud iam service-accounts add-iam-policy-binding \ \
  --member="" \

Note: If you have not enabled compute engine, you will see an error like:

Gaia id not found for email

where PROJECT_NUMBER is the actual number. To solve this, simply visit the compute engine service and allow the initial setup to complete. This will create the service account called and after that, the iam command will run successfully.

Deploy to Cloud Run

Cloud Run ( is a fully managed serverless compute platform that automatically scales your stateless containers.

The continuous deployment pipeline works as follows:

  1. Merge a pull request into the master branch.
  2. The Cloud Build GitHub app triggers Cloud Build to:
    1. Build the docker image
    2. Push the docker image to Artifact Registry
    3. Deploy the image to Cloud Run

Mapping a custom domain

Details on how to verify a domain can be found in the documentation.

Once a domain is verified, the following command maps it to a Cloud Run service:

gcloud beta run domain-mappings create \
  --service sapper-on-cloud-run \
  --domain \
  --region us-central1 \
  --platform managed

Add a CNAME record with name sapper-on-cloud-run and contents to your DNS.

Top categories

Loading Svelte Themes