Skip to content

β˜οΈπŸƒπŸ½β€β™€οΈ deploy your node.js application on cloud run

Notifications You must be signed in to change notification settings

ruanmartinelli/cloud-run-nodejs-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

cloud-run-nodejs-template

A template for deploying Node.js applications on Google Cloud Run with Terraform and GitHub Actions.

Prerequisites

Getting started

Follow the steps below to set up your project for the first time.

  1. Create a new repository from the template. Clone it to your computer.

  2. Create a Google Cloud project:

# Create project
gcloud projects create "PROJECT_ID" --name="PROJECT NAME"

# Set proejct as default
gcloud config set project "PROJECT_ID"
  1. Set up billing
# List billing accounts available
gcloud beta billing accounts list

# Link billing account
gcloud beta billing projects link "PROJECT_ID" --billing-account="BILLING_ACCOUNT_ID"
  1. Create a bucket to store the remote Terraform state and update infra/backend.tf:
# Create bucket
gsutil mb gs://tfstate-PROJECT_ID
# infra/backend.tf

terraform {
  required_version = ">= 0.13"

+   backend "gcs" {
+     bucket = "tfstate-PROJECT_ID"
+   }

  required_providers {
    google = ">= 3.3"
  }
}
  1. Apply the Terraform configuration for the first time:
cd infra

terraform init

terraform plan -var project=PROJECT_ID

terraform apply -var project=PROJECT_ID
  1. Create GitHub secrets

Create two GitHub secrets for your repository:

PROJECT_ID

Your Google Cloud project ID.

SERVICE_ACCOUNT_KEY

Key for the deployment service account. It was created by Terraform on the previous step. Run terraform output deployment_sa_key to display the value.

  1. Commit modified files
git add .

git commit -m "update terraform config"

git push
  1. Done πŸŽ‰

Deploying the service

GitHub actions is configured to deploy a new image when a release is created.

Go here to create a new release and trigger a deployment.

License

MIT 2021

About

β˜οΈπŸƒπŸ½β€β™€οΈ deploy your node.js application on cloud run

Resources

Stars

Watchers

Forks

Packages

No packages published