Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • Archiving and uploading source code to Google Cloud Storage
  • Building Docker images using Google Cloud Build
  • Pushing images to Google Artifact Registry
  • Deploying to Google Cloud Run with custom configurations
  • Sending deployment status notifications to Slack

Features

  • Flexible Image Tagging: Support for custom tag formats with branch names, commit SHAs, and timestamps
  • Scalable Builds: Configure Cloud Build machine types for optimal build performance
  • Resource Management: Customize Cloud Run CPU, memory, and scaling configurations
  • Secrets Integration: Mount secrets from Google Cloud Secrets Manager as environment variables
  • VPC Support: Connect Cloud Run services to your VPC via VPC connectors
  • Slack Notifications: Real-time deployment status updates
  • Automatic Cleanup: Removes temporary build artifacts after deployment

Prerequisites

  • Google Cloud Platform project with the following APIs enabled:
    • Cloud Build API
    • Cloud Run API
    • Cloud Storage API
    • Artifact Registry API
  • GCP service account with appropriate permissions
  • Slack workspace with bot token (for notifications)
  • Google Cloud Storage bucket for build artifacts
  • Google Artifact Registry repository

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

  • $BRANCH - Normalized branch name
  • $SHA - 7-digit commit SHA
  • $YYYY - Year (4 digits)
  • $MM - Month (2 digits)
  • $DD - Day (2 digits)
  • $HH - Hour (2 digits, 24h format)
  • $mm - Minute (2 digits)
  • $SS - Second (2 digits)

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:

  • APPLICATION: Name of the application being deployed
  • ENVIRONMENT: Deployment environment (e.g., staging, production)
  • SLACK_BOT_TOKEN: Slack bot OAuth token
  • SLACK_DEPLOYMENTS_CHANNEL: Slack channel ID for notifications

Development

Prerequisites

  • Node.js 20+
  • TypeScript
  • npm or yarn

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.

About

Build and deploy Docker containers to Google Cloud Run

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages