DevOps Peach

GCP Basics · Containers & Serverless – Cloud Run, Cloud Run Functions, GKE and Cloud Build · Lesson 4 of 5

Artifact Registry and Cloud Build

Cloud Build runs build steps in containers from a cloudbuild.yaml or a trigger; Artifact Registry stores Docker images and language packages with IAM, vulnerability scanning and cleanup policies.

Practice interactively →

A typical pipeline on Google Cloud: Cloud Build builds and tests, Artifact Registry stores the image, and Cloud Deploy or a deploy step releases it to Cloud Run or GKE.

flowchart LR
  GH["GitHub push to main"] --> TR["Cloud Build trigger"]
  TR --> CB["Build steps<br/>test, docker build, push"]
  CB --> AR["Artifact Registry<br/>asia-southeast1-docker.pkg.dev"]
  AR --> SCAN["Vulnerability scanning"]
  CB --> DEP["Deploy to Cloud Run / GKE"]
  %% step GH: A push to main (or a pull request) starts the pipeline.
  %% step TR: A Cloud Build trigger connected to the repository runs cloudbuild.yaml as a dedicated service account.
  %% step CB: Each step runs in its own container: run tests, build the image, push it.
  %% step AR: The image is stored in a regional Docker repository with IAM-controlled access.
  %% step SCAN: Artifact Analysis scans images for known vulnerabilities in OS packages and language dependencies.
  %% step DEP: A final step (or Cloud Deploy) rolls the new image out to Cloud Run or GKE.

Artifact Registry

Cloud Build

# cloudbuild.yaml
steps:
- name: python:3.12
  entrypoint: bash
  args: ["-c", "pip install -r requirements.txt && pytest"]
- name: gcr.io/cloud-builders/docker
  args: ["build", "-t", "asia-southeast1-docker.pkg.dev/dl-lab-dev/shop/web:$SHORT_SHA", "."]
images: ["asia-southeast1-docker.pkg.dev/dl-lab-dev/shop/web:$SHORT_SHA"]
options:
  logging: CLOUD_LOGGING_ONLY

Cloud Deploy

A managed delivery pipeline: dev → staging → prod targets, promotions, approvals, canary releases and rollbacks for GKE and Cloud Run.

gcloud artifacts repositories create shop --repository-format=docker --location=asia-southeast1
gcloud auth configure-docker asia-southeast1-docker.pkg.dev
gcloud builds submit --tag=asia-southeast1-docker.pkg.dev/dl-lab-dev/shop/web:1.4.0
Command Meaning
gcloud artifacts docker images list asia-southeast1-docker.pkg.dev/dl-lab-dev/shop Images in a repo
gcloud builds list --limit=5 Recent builds
gcloud builds triggers list Triggers

Traps: the old default Cloud Build service account had broad Editor-like rights, so set your own; pushing needs writer on the repository, not project Viewer; latest tags make rollbacks and audits hard, use commit SHAs.

Practice interactively →