Documentation structure for LLMs (llms.txt)

Deploy to Google Cloud Platform

Cloud Server v4+

In this how-to guide, you will learn how to configure CircleCI to deploy to Google Cloud Platform.

Introduction

Before deploying to Google Cloud Platform, you will need to authorize the Google Cloud SDK and set default configuration settings. Refer to the Authorizing the Google Cloud SDK page for full details.

In addition to the orbs described below, CircleCI has created an GCP convenience image focusing on, deployment: cimg/gcp.

Using Google Cloud orbs

Several Google Cloud orbs are available in the CircleCI Orbs Registry. Use the orbs to simplify your deployments. For example, the Google Kubernetes Engine (GKE) orb has a pre-built job to build and publish a Docker image, and roll the image out to a GKE cluster:

Make sure to replace any placeholder versions in the example.
version: 2.1

orbs:
  gke: circleci/gcp-gke@x.y.z # Use the GCP GKE orb in your config

workflows:
  main:
    jobs:
      - gke/publish-and-rollout-image:
          cluster: <your-GKE-cluster> # name of GKE cluster to be created
          container: <your-K8-container-name> # name of your Kubernetes container
          deployment: <your-K8-deployment-name> # name of your Kubernetes deployment
          image: <your-image> # name of your Docker image
          tag: $CIRCLE_SHA1 # Docker image tag - optional

Deployment to GKE without orbs

In the following example, if the build-job passes and the current branch is main, CircleCI runs the deployment job.

version: 2.1

jobs:
  # build job omitted for brevity
  deploy-job:
    docker:
      - image: <docker-image-name-tag>
    working_directory: /tmp/my-project
    steps:
      - run:
          name: Deploy Main to GKE
          command: |
            # Push Docker image to registry, update K8s deployment to use new image - `gcloud` command handles authentication and push all at once
            sudo /opt/google-cloud-sdk/bin/gcloud docker push us.gcr.io/${PROJECT_NAME}/hello
            # The new image is now available in GCR for the GCP infrastructure to access, next, change permissions:
            sudo chown -R ubuntu:ubuntu /home/ubuntu/.kube
            # Use `kubectl` to find the line that specifies the image to use for our container, replace with image tag of the new image.
            # The K8s deployment intelligently upgrades the cluster by shutting down old containers and starting up-to-date ones.
            kubectl patch deployment docker-hello-google -p '{"spec":{"template":{"spec":{"containers":[{"name":"docker-hello-google","image":"us.gcr.io/circle-ctl-test/hello:'"$CIRCLE_SHA1"'"}]}}}}'

workflows:
  build-deploy:
    jobs:
      - build-job
      - deploy-job:
          requires:
            - build-job # Only deploy once the build job has completed
          filters:
            branches:
              only: main # Only deploy on the main branch

For another example, see our CircleCI Google Cloud deployment example project.

Track your deployments with deploy markers

Deploy markers provide a way to track and manage your Google Cloud Platform deployments in the CircleCI web app. Deploy markers work with all GCP deployment types including GKE, Cloud Run, and App Engine. When you add deploy markers to your deployment job, you can view a timeline of all deployments, track their status, and enable rollback and deploy pipelines.

You have two options for setting up deploy markers:

  • In-app setup: Use the guided setup in the CircleCI web app when configuring a Rollback Pipeline or Deploy Pipeline. The setup will walk you through adding deploy markers to your configuration. If you are using GitHub and have the CircleCI GitHub App installed, you can use AI to generate the deploy marker configuration automatically.

  • Manual setup: Add deploy marker commands directly to your .circleci/config.yml file by following the Configure Deploy Markers guide.

Both approaches will enable you to track deployment history and manage rollbacks directly from the CircleCI web app.