CI/CD with Cloud Run and Artifact Registry

Using cloudbuild.yaml to configure a CI/CD pipeline


March 14, 2024

Below is an example cloudbuild.yaml file that will:

  1. Build a Docker image using Cloud Build

  2. Push the built image to Artifact Registry

  3. Deploy the image to Cloud Run

There may be some additional setup/service account permissions that need to be specified (I’ll update this later once I sort these out), but at the very least, we need to create a repository in Artifact Registry first. To do that, run the following in gcloud:

gcloud artifacts repositories create REPO_NAME --format docker --region us-east4

From there, the cloudbuild.yaml file should look like this:

  #docker build 
  - name: ''
    args: ['build', '-t',
  #docker push to artifact registry
  - name: ''

  #deploy the container to cloud run
  - name: ''
    args: ['run', 'deploy', 'SERVICE-NAME', '--image', '${PROJECT_ID}/REPO_NAME/IMAGE_NAME:$COMMIT_SHA', '--region', 'us-east4']

#optional but prob worth setting
timeout: 3600s

And then replace anything in ALL_CAPS above (without a $) with the relevant values