Nov 20, 20265 min read

Google Cloud Build vs GitHub Actions for Deploying to GCP

How Cloud Build and GitHub Actions differ on build definitions, triggers, GCP credentials, private network access and Cloud Run deploys, with a cloudbuild.yaml and a workflow for the same service, and how to skip the infrastructure step in both.

Illustration for Google Cloud Build vs GitHub Actions for Deploying to GCP

Deploying a backend from GitHub to Google Cloud usually means Cloud Build or GitHub Actions. Cloud Build runs container steps inside your project with a service account. GitHub Actions runs workflows next to your code and reaches GCP through Workload Identity Federation.

This comparison covers configs, triggers, credentials, network access and Cloud Run deploys for the same service. It also shows how Encore removes the infrastructure part of the pipeline.

Cloud Build vs GitHub Actions at a Glance

EncoreGoogle Cloud BuildGitHub Actions
Pipeline definitionNone to write, deploy on pushcloudbuild.yaml stepsYAML in .github/workflows
GCP credentialsEncore deploys into your connected projectBuild service accountWorkload Identity Federation
Private network accessServices deployed into a private VPCPrivate poolsSelf-hosted runners
Pull request checksBuilds and tests every pull requestPull request triggersNative
InfrastructureProvisioned from the codeA separate Terraform stepA separate Terraform step
Preview environmentsOne per pull requestBuilt by handBuilt by hand

Each option is covered below, starting with Encore.

Deploying to GCP Without a Pipeline with Encore

Encore brings infrastructure from code, with a platform that builds and deploys into your own GCP project. After you link the GitHub repository, every pull request is built and tested and gets a preview environment, and pushing to the configured branch deploys.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Encore provisions the infrastructure your application needs in your own AWS or GCP account.

The resources come from the code, so there is no provisioning step in a pipeline. A service with a database and a topic looks like this:

// orders/orders.ts import { api } from "encore.dev/api"; import { SQLDatabase } from "encore.dev/storage/sqldb"; import { Topic } from "encore.dev/pubsub"; const db = new SQLDatabase("orders", { migrations: "./migrations" }); export interface OrderPlaced { orderId: number; } export const orderPlaced = new Topic<OrderPlaced>("order-placed", { deliveryGuarantee: "at-least-once", }); export const place = api( { expose: true, method: "POST", path: "/orders" }, async ({ sku }: { sku: string }): Promise<{ id: number }> => { const row = await db.queryRow<{ id: number }>` INSERT INTO orders (sku) VALUES (${sku}) RETURNING id`; await orderPlaced.publish({ orderId: row!.id }); return { id: row!.id }; }, );

The service definition and migration sit next to it:

// orders/encore.service.ts import { Service } from "encore.dev/service"; export default new Service("orders");
-- orders/migrations/1_init.up.sql CREATE TABLE orders ( id BIGSERIAL PRIMARY KEY, sku TEXT NOT NULL );

In a GCP environment Encore provisions the matching resources: a dedicated project per environment with a private network, Cloud Run or GKE for compute with zero-downtime deploys, Cloud SQL for the database, Google Pub/Sub for the topic and Secret Manager for secrets. A pull request that adds a bucket gets the bucket in its preview environment, which is hosted by Encore, so the review covers the infrastructure too.

AI coding agents benefit from the same shape: the topic, the handler and the migration land in one diff that runs locally with encore run, with no cloudbuild.yaml, workflow or Terraform module to change in step.

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

Best fit: teams on GitHub shipping backends to GCP who want a preview environment per pull request and push-to-deploy into their own project.

Google Cloud Build: Container Steps in Your Project

Cloud Build runs a build config where each step is a container image with arguments, and steps share a workspace. Triggers come from a GitHub repository connection, with filters on branches, tags and pull requests. A Cloud Run deploy builds, pushes and rolls out:

# cloudbuild.yaml steps: - name: gcr.io/cloud-builders/docker args: ["build", "-t", "europe-west1-docker.pkg.dev/$PROJECT_ID/apps/orders:$COMMIT_SHA", "."] - name: gcr.io/cloud-builders/docker args: ["push", "europe-west1-docker.pkg.dev/$PROJECT_ID/apps/orders:$COMMIT_SHA"] - name: gcr.io/google.com/cloudsdktool/cloud-sdk entrypoint: gcloud args: - run - deploy - orders - --image=europe-west1-docker.pkg.dev/$PROJECT_ID/apps/orders:$COMMIT_SHA - --region=europe-west1 images: - europe-west1-docker.pkg.dev/$PROJECT_ID/apps/orders:$COMMIT_SHA options: logging: CLOUD_LOGGING_ONLY

Builds run as a service account in your project, so there is no credential to hand to an outside system. Private pools put workers on a network peered with your VPC, which is how a build step reaches a private Cloud SQL instance to run migrations. The weak spots are developer feedback and reuse: steps are plain container images with no curated marketplace like GitHub's, and status on pull requests depends on the GitHub connection rather than living next to other checks.

GitHub Actions: Workflows Next to the Code

GitHub Actions authenticates to Google Cloud with google-github-actions/auth and Workload Identity Federation, so jobs impersonate a service account without a JSON key. The same deploy:

# .github/workflows/deploy.yml name: deploy on: push: branches: [main] permissions: id-token: write contents: read jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: google-github-actions/auth@v2 with: workload_identity_provider: projects/123456789/locations/global/workloadIdentityPools/github/providers/my-repo service_account: deployer@my-project.iam.gserviceaccount.com - uses: google-github-actions/setup-gcloud@v2 - run: | gcloud auth configure-docker europe-west1-docker.pkg.dev --quiet docker build -t europe-west1-docker.pkg.dev/my-project/apps/orders:${{ github.sha }} . docker push europe-west1-docker.pkg.dev/my-project/apps/orders:${{ github.sha }} - uses: google-github-actions/deploy-cloudrun@v2 with: service: orders region: europe-west1 image: europe-west1-docker.pkg.dev/my-project/apps/orders:${{ github.sha }}

Pull request checks, required reviewers on environments and reusable workflows all live in one place, and the same tool deploys to other clouds. The cost is that hosted runners are outside your VPC, so migrations against a private database need a self-hosted runner or a Cloud Run job started from the workflow.

Good to Know

  • Neither tool creates Cloud SQL, Pub/Sub or buckets. Both run Terraform or gcloud commands in a step you maintain.
  • Grant the deploy identity roles/iam.serviceAccountUser on the runtime service account only, not project-wide.
  • Workload Identity Federation conditions should pin the repository and branch, or any branch can deploy.

How to Choose

Pick Encore when the goal is shipping a backend to GCP with per-pull-request previews and push-to-deploy, with the infrastructure coming from the same pull request as the code.

Pick Cloud Build when builds must run inside your project with a service account and private network access. Pick GitHub Actions when you want checks and deploys next to the code, keyless access through Workload Identity Federation, and the option of deploying elsewhere from the same workflows.

Frequently asked questions

Should I use Cloud Build or GitHub Actions for GCP?

Use GitHub Actions when the code is on GitHub and you want pull request checks and deploys in one tool, with Workload Identity Federation for keyless GCP access. Use Cloud Build when builds should run inside your GCP project with a service account, private pools for VPC access, and build logs and history in the Google Cloud console.

Can GitHub Actions deploy to Google Cloud without a service account key?

Yes. Create a Workload Identity Pool with GitHub as an OIDC provider, allow a service account to be impersonated by your repository, and use google-github-actions/auth with workload_identity_provider and service_account. Jobs then get short-lived credentials instead of a JSON key.

How does Cloud Build deploy to Cloud Run?

A cloudbuild.yaml builds and pushes the image with the docker builder, then runs gcloud run deploy with the new image in a later step. The Cloud Build service account needs permission to deploy to Cloud Run and to act as the runtime service account.

Do I need Cloud Build or GitHub Actions to deploy to GCP with Encore?

No. You link the GitHub repository and push, and Encore builds, provisions Cloud Run or GKE, Cloud SQL, Pub/Sub and the other resources your code declares in your own GCP project, then deploys.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders