Skip to content

AndreasHeintze/cloud-app

Repository files navigation

Gitpod Ready-to-Code

sapper-on-cloud-run

A boilerplate to deploy Sapper (Svelte) applications to Cloud Run (https://cloud.run)

A demo is available at https://sapper-on-cloud-run.mikenikles.com/.

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 artifactregistry.googleapis.com

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

Set up Cloud Build

# Enable the Cloud Build API
gcloud services enable cloudbuild.googleapis.com

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

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 "serviceAccount:PROJECT_NUMBER@cloudbuild.gserviceaccount.com" \
  --role roles/run.admin

# Grant access to Cloud Build to deploy to Cloud Run
gcloud iam service-accounts add-iam-policy-binding \
  PROJECT_NUMBER-compute@developer.gserviceaccount.com \
  --member="serviceAccount:PROJECT_NUMBER@cloudbuild.gserviceaccount.com" \
  --role="roles/iam.serviceAccountUser"

Deploy to Cloud Run

Cloud Run (https://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 sapper-on-cloud-run.mikenikles.com \
  --region us-central1 \
  --platform managed

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published