Search code examples
google-cloud-platformcontinuous-integrationgoogle-cloud-rungoogle-cloud-buildgoogle-cloud-deploy

Cloud Build -> Cloud Deploy -> Cloud Run?


I am trying to build a release-from-main pipeline using Google's "serverless" offerings, where when something gets merged into main on GitHub, it triggers a Cloud Build (which builds, containerizes, unit tests, and pushes the image), then deploys it to a "test" environment in Cloud Deploy, which sets up a Cloud Run instance with the new build and lets me try it before promoting it to staging and prod.

I've found documentation on the Cloud Deploy->Cloud Run part, and I've found Cloud Build->Cloud Run, and I've found examples of going to GKE or raw Kubernetes, but I haven't found any examples of putting the whole chain of "serverless" offerings together.

I asked ChatGPT, which suggested I use a "kind: Rollout" deploy_config.yaml, but Google Build says "kind Rollout not supported".

Here is my cloudbuild.yaml (with the project/app names generified, and just using "latest" for now to get things going):

steps:
  # Build and tag the Docker image
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'gcr.io/my-project/my-server:latest', '.']

  # Push the Docker image to Google Container Registry
  - name: 'gcr.io/cloud-builders/docker'
    args: ['push', 'gcr.io/my-project/my-server:latest']

  # Deploy using Cloud Deploy
  - name: 'gcr.io/cloud-builders/gcloud'
    args: ['deploy', 'apply', '--file=deploy_config.yaml', '--region=europe-west3']

Then my deploy_config.yaml:

apiVersion: deploy.cloud.google.com/v1
kind: Rollout
metadata:
  name: api-server-rollout
  namespace: default
spec:
  deliveryPipeline: my-delivery-pipeline
  stage: deploy-to-test
  target: my-delivery-target
  revision:
    from:
      type: PreviousRollout
  artifacts:
    - image: gcr.io/my-project/my-app:latest

But "Rollout" seems to be the wrong thing to do here. Can anyone point me in the right direction? Or am I misguided in this structure entirely?


Solution

  • Kind 'Rollout' (nor 'Release') is not supported and is not a declarative resource type of Cloud Deploy. You will instead want to create a Cloud Build trigger to create a Cloud Deploy release after creating your container(s), using gcloud deploy releases create.

    The steps would be to:

    1. Create a Cloud Build trigger to build your container(s), against a repro
    2. Create a Cloud Deploy delivery pipeline, representing where you would like to deploy your application
    3. Create your service.yaml definitions for each target
    4. Ensure your skaffold.yaml and Cloud Run service yaml(s) exist in the source directories, included with the trigger
    5. Create a cloud deploy release at the end of your Cloud Build trigger, into your delivery pipeline

    Here is some documentation, which I hope may be useful: https://cloud.google.com/deploy/docs/integrating-ci#examples_passing_a_build_artifacts_file

    The "Basic Walkthrough - Cloud Run" example here also should provide a general overview of the process of connecting CI to Cloud Deploy. https://cloud.google.com/deploy/docs/tutorials