~ git clone https://git.cass.si/deploy-cloud-run.git

Deploy to Google Cloud Run

A GitHub Action that automates building Docker images using Google Cloud Build and deploying them to Google Cloud Run with Slack notifications.

Overview

This action provides a complete CI/CD pipeline for deploying containerized applications to Google Cloud Run. It handles:

Features

Prerequisites

Usage

- name: Build & Deploy to Cloud Run
  uses: ./.github/actions/deploy-cloud-run
  env:
    APPLICATION: "my-app"
    ENVIRONMENT: "production"
    SLACK_BOT_TOKEN: ${{ secrets.SLACK_TOKEN }}
    SLACK_DEPLOYMENTS_CHANNEL: ${{ secrets.SLACK_DEPLOYMENTS_CHANNEL }}
  with:
    # Required inputs
    gcp-project-id: my-project-id
    gcp-service-account-key: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
    gcp-cloud-storage-bucket: my-build-bucket
    gcp-artifact-registry-repository: my-registry
    gcp-cloud-run-service-name: my-service
    gcp-cloud-run-port: 8080
    image-name: my-app
    image-sources: "src,package.json,Dockerfile"

    # Optional inputs
    gcp-cloud-build-machine-type: E2_HIGHCPU_32
    gcp-cloud-run-scaling-min-max: "0,10"
    gcp-cloud-run-resources-cpu-mem: "2,1Gi"
    gcp-cloud-run-max-concurrency: 80
    gcp-cloud-run-cpu-idle: true
    gcp-secrets-manager-secret-id: my-secret
    gcp-secrets-manager-secret-env-key: API_KEY
    image-path: ./Dockerfile
    image-tag-format: $BRANCH-$SHA
    image-tag-latest: true
    image-tag-additional-tags: "stable,v1.0.0"

Inputs

Required

Input Description
gcp-project-id The GCP Project ID
gcp-service-account-key Base64-encoded service account key file
gcp-cloud-storage-bucket Cloud Storage bucket for temporary build files
gcp-artifact-registry-repository Artifact Registry repository name
gcp-cloud-run-service-name Cloud Run service name
gcp-cloud-run-port Container port to expose
image-name Name of the Docker image
image-sources Comma-separated list of files/folders to include in build

Optional

Input Default Description
gcp-cloud-build-machine-type - Cloud Build machine type (e.g., E2_HIGHCPU_32)
gcp-cloud-run-resources-cpu-mem 1,512Mi CPU and memory allocation (e.g., "4,2Gi")
gcp-cloud-run-scaling-min-max - Min and max instances (e.g., "0,10")
gcp-cloud-run-max-concurrency - Max concurrent requests per instance
gcp-cloud-run-cpu-idle - Scale to zero when idle
gcp-cloud-run-region europe-west2 Cloud Run deployment region
gcp-artifact-registry-region europe-west2 Artifact Registry region
gcp-secrets-manager-secret-id - Secrets Manager secret to reference
gcp-secrets-manager-secret-env-key - Environment variable name for the secret
gcp-vpc-connector-name - VPC connector name for network access
image-path ./Dockerfile Path to Dockerfile
image-tag-format $BRANCH-$SHA-$YYYY.$MM.$DD-$HH.$mm.$SS Custom tag format
image-tag-latest false Tag image as "latest"
image-tag-additional-tags - Comma-separated list of additional tags

Image Tag Format Variables

Outputs

Output Description
full-image-name Full image name with host, project ID, and image name (without tags)
image-tags Comma-separated list of tags applied to the built image
cloud-run-uri URI of the deployed Cloud Run service

How It Works

  1. Archive: Creates a tarball of specified source files and uploads to Cloud Storage
  2. Build: Triggers Cloud Build to create Docker image and push to Artifact Registry
  3. Deploy: Creates or updates Cloud Run service with the new image
  4. Notify: Sends deployment status to Slack channel
  5. Cleanup: Removes temporary build artifacts from Cloud Storage

Environment Variables

The action requires the following environment variables:

Development

Prerequisites

Setup

npm install

Build

npm run build

This compiles TypeScript to JavaScript and bundles the action using esbuild.

Lint

npm run lint        # Check for issues
npm run lintFix     # Auto-fix issues

Support

For issues or questions, please open an issue in the repository.