Prepare and test your skills
Prepare and test your skills
Pipeline integration and optimization is the practice of moving container images securely from Cloud Build (opens in a new tab) to Artifact Registry (opens in a new tab) while keeping builds fast and trustworthy. Cloud Build builds the image from source, checks the image for vulnerabilities, and then stores the image in Artifact Registry for deployment. Efficient layer design reduces rebuild time and storage use, while scanning and deployment policy protect the software supply chain.
Secure transfer from Cloud Build to Artifact Registry means the built image is pushed to a versioned Docker repository address in the form LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME. The simplest transfer runs gcloud builds submit --tag LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME from the directory with source code and a Dockerfile, which builds the image and pushes it to Artifact Registry. A build config file gives more control by defining steps that run builders such as gcr.io/cloud-builders/docker, and each build step container attaches to a local Docker network named cloudbuild that hosts Application Default Credentials for Google Cloud services.
Cloud Build can store a built image in three different ways:
images field to store a Docker image in Artifact Registry after the build completes, which makes the stored image appear in the build results.artifacts.oci field with file and registryPath to upload an Open Container Initiative (OCI) image, including multi-architecture images, to a supported Artifact Registry repository.docker push command inside a build step to store a container image as part of the build flow, which does not display the image in the build results.Choose the images field when visibility in build results matters, because results include the Build description page in the console, Build.get(), and gcloud builds list. Choose docker push inside the step sequence when the push must happen at a specific point in the pipeline, such as only after a vulnerability check passes.
Exam tip: An image stored with the images field appears in Cloud Build results, while an image stored with docker push does not.
Automated vulnerability scanning in the pipeline uses Artifact Analysis (opens in a new tab) to find package vulnerabilities before an image reaches Artifact Registry or production. Automatic vulnerability scanning scans container images when they are uploaded to Artifact Registry and continuously monitors the data for new vulnerabilities for up to 30 days after the push. The On-Demand Scanning API scans local images or images stored in Artifact Registry on request, so Cloud Build can scan an image after it is built and block the upload to Artifact Registry if vulnerabilities at a specified severity are found.
| Scanning option | When scan runs | Pipeline use |
|---|---|---|
| Automatic vulnerability scanning | On image upload to Artifact Registry, plus 30 days of monitoring | Detect new vulnerabilities in stored images after the push |
| On-Demand Scanning API | When gcloud artifacts docker images scan is called in a build step | Shift security left by blocking a risky image before the push |
A secure Cloud Build pipeline orders build, scan, check, and push so only clean images are stored:
/workspace/image-digest.txt./workspace/scan_id.txt.vulnerability.effectiveSeverity, and fail the build with exit 1 if a blocked severity is found.docker push only if the severity check succeeded, and list the image in the images field for visibility.The severity gate blocks only the levels explicitly defined in the _SEVERITY substitution. Supported levels are:
CRITICALHIGHMEDIUMLOWBecause the check uses exact matching, specifying only HIGH will not block CRITICAL, so teams that want to block High and above use a regular expression such as CRITICAL|HIGH.
Enforcing integrity at deploy time means only images that meet security proof are allowed into supported Google Cloud environments. Binary Authorization (opens in a new tab) enforces a deployment policy when a deploy is attempted, for example by allowing deployment only if an image is signed for compliance with a vulnerability scan policy. This enforcement depends on earlier pipeline evidence, including On-Demand Scanning results, automatic scan data, and build provenance from Cloud Build.
Cloud Build can generate build provenance that provides Supply Chain Levels for Software Artifacts (SLSA) Level 3 assurance, which verifies the build source, entry point, parameters, and builder identity. Cloud Build also runs each build in a fresh virtual machine environment that is destroyed after the build, so no residual files or settings carry over to interfere with the next build or hide tampering. Together, ephemeral builds, signed provenance, and Binary Authorization let operators allow only code built from verified sources by a trusted build system.
Efficient layer caching in Artifact Registry relies on how container image layers are constructed and reused. A container image is built incrementally from layers, where each instruction in a Dockerfile corresponds to a layer in the Docker image. Images in the same registry that share common layers reuse those layers for storage efficiency, while layers are not shared across different registries. When an image is deleted, its unreferenced layers are cleaned up daily rather than immediately.
Dockerfiles stay fast when stable dependency steps are ordered before frequently changing code. Node.js Dockerfiles copy package*.json first and run npm install --omit=dev before copying application code, so code changes do not force dependency reinstalls. Python Dockerfiles copy requirements.txt and run pip install -r requirements.txt before copying code for the same reason, and Java and .NET examples use multi-stage builds where a builder stage compiles the artifact and only the final jar or published output is copied into a smaller runtime image. Removing unused container images further reduces storage costs and lowers the risk of running old, vulnerable software.
Build configuration and automation in Cloud Build (opens in a new tab) is the practice of defining container construction as code in a cloudbuild.yaml or cloudbuild.json file so source code flows automatically to a versioned image in Artifact Registry. The config file declares an ordered list of build steps, substitution variables for different environments, and output fields that control where the finished image is stored. When combined with manual submission or build triggers, the same file produces repeatable builds across development, staging, and production.
A cloudbuild.yaml file defines automation through its steps field, where each build step runs a container as an instance of docker run. Each step names a builder image in name, such as gcr.io/cloud-builders/docker, and passes tool commands in args, such as build or push. By default Cloud Build runs all steps serially on the same machine, and a config can include up to 300 steps with up to 100 arguments per step.
A typical containerization pipeline moves source code through an ordered sequence:
docker builder step runs docker build -t LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME . to build the image from the Dockerfile and source in the workspace.docker builder step runs docker push with the same Artifact Registry path to send the image from the build worker to the repository.gcr.io/google.com/cloudsdktool/cloud-sdk with a gcloud entrypoint, to scan the image, check vulnerabilities, or create a Compute Engine instance from the pushed image.Steps can share data through the /workspace directory, so one step can write an image digest or scan ID to a file that a later step reads. Use id to name steps for tracking, waitFor to allow steps to run concurrently, and -f DOCKERFILE_PATH in args when the Dockerfile lives in a different directory than the source.
Substitution variables in Cloud Build are named placeholders that let one cloudbuild.yaml file build different projects, repositories, and environments without editing the file. Custom substitutions start with an underscore, such as $_IMAGE, $_PROJECT_ID, $_SERVICE_ACCOUNT, and $_SEVERITY, and are declared in a top-level substitutions map with default values. Built-in values such as ${PROJECT_ID} and ${BUILD_ID} resolve automatically at build time, so the image path LOCATION-docker.pkg.dev/${PROJECT_ID}/REPOSITORY/IMAGE_NAME adapts to the project that runs the build.
The build depends on options flags to control how substitutions flow into containers. Setting dynamicSubstitutions: true allows values like ${BUILD_ID} to resolve correctly, while automapSubstitutions: true maps substitution variables into the container environment. Setting substitutionOption: ALLOW_LOOSE tells Cloud Build to ignore unused substitutions or dynamic script arguments instead of failing. A trigger or gcloud builds submit command can then override any custom value at run time to target a new region, repository, or severity threshold.
Automation in Cloud Build starts a container build from source without manually running Docker locally, either on demand or automatically when source changes. The command gcloud builds submit --config CONFIG_FILE_PATH SOURCE_DIRECTORY sends the source directory and config file to Cloud Build, which runs each step and stores the result. If no paths are given, Cloud Build assumes the config file and source are in the current working directory.
The same delivery goal can be started in three ways:
gcloud builds submit --config to run explicit multi-step logic such as build, scan, severity check, and push.Dockerfile with gcloud builds submit --tag LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME to build an image without writing a config file.gcloud builds submit --pack image=LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME to build an image with no Dockerfile and no config file, optionally adding builder= and env= values.Build triggers extend this automation by watching a repository and starting the same config, Dockerfile, or buildpacks build automatically on pushes or pull requests. A trigger that uses buildpacks can therefore rebuild and republish an image on every source change, streamlining delivery across diverse environments from one definition.
Storing images in Artifact Registry connects the end of the build to a secure Docker repository addressed as LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME. Cloud Build supports three output mechanisms that differ in what they store and whether the result appears in build metadata.
| Storage option | What it stores | Visibility in build results |
|---|---|---|
images field | Docker image pushed to Artifact Registry after the build completes | Shown on the Build description page, in Build.get(), and in gcloud builds list |
docker push step | Container image pushed to Artifact Registry as part of the build flow | Not shown in build results |
artifacts.oci field | Open Container Initiative (OCI) image folder uploaded to Artifact Registry using file and registryPath | Stored as OCI artifact with optional tags |
The images field lists one or more image paths to push after all steps succeed, and the build fails if a listed image was not produced. The docker push step runs inside the step sequence, so it can occur before later validation or deployment steps. To store the image during the flow and still display it in build results, include both the docker push step and the images field with the same image path.
Exam tip: Use the images field when the image must appear in build results, and add a docker push step when the image must be available to later steps in the same build.
Artifact Management and Repository Security is the practice of storing Docker container images in centrally managed, versioned repositories with controlled access and secure publishing. In Google Cloud, Artifact Registry (opens in a new tab) provides that central location for packages and Docker images, while Cloud Build (opens in a new tab) builds images from source and pushes them to Artifact Registry. Identity and Access Management (IAM) controls who can administer repositories and who can push or pull images.
A Docker repository in Artifact Registry is a regional or multi-regional container for storing multiple related container images in one Google Cloud project. Each repository has its own location, such as us-west1, and images are addressed as LOCATION-docker.pkg.dev/PROJECT/REPOSITORY/IMAGE:TAG, where docker.pkg.dev is the hostname for Docker-format repositories. You can create multiple separately controlled repositories in the same project to group images by team or stage, such as testing, staging, or production, and control access at the repository level.
Images inside a Docker repository are versioned by tag and manifest digest, and tags can be mutable or immutable. Container images are built from layers, where each Dockerfile instruction creates a layer, and images in the same registry that share layers reuse that storage for efficiency. Layers are never shared across different registries for security, and layers that are no longer referenced by any image are deleted daily. For all push and pull requests to the pkg.dev domain, the target repository must already exist before the push.
Granular access control in Artifact Registry means granting IAM roles on individual repositories instead of on a whole registry host. IAM provides consistent credentials for Cloud Build, Google Kubernetes Engine (GKE), Cloud Run, Compute Engine, and developer tools, and permissions are managed directly on the repository with no Cloud Storage buckets to manage. For example, access to images in us-docker.pkg.dev/my-project/team1 can be controlled separately from us-docker.pkg.dev/my-project/team2, and conditional access can be granted with IAM and repository tags.
The build and runtime service accounts receive scoped repository permissions:
gcr.io repositories in the same Google Cloud project.Repositories can be further protected by encrypting each repository with customer-managed encryption keys (CMEK) and by placing repositories inside a VPC Service Controls security perimeter. Artifact Registry also supports vulnerability scanning and metadata management through Artifact Analysis, Pub/Sub notifications for repository changes, and image prewarming with Image streaming to reduce GKE cold-start latency.
Exam tip: The default Cloud Build service account already pushes and pulls in the same project, but pushes across projects or with a user-specified service account require granting the Artifact Registry Writer role on the repository project.
Secure publishing from Cloud Build to Artifact Registry is an automated flow where source code moves through ordered build steps and the resulting image is pushed to a specific repository. Cloud Build executes each build step in a Docker container attached to a local cloudbuild network, using supported builders, community builders, or custom builders such as gcr.io/cloud-builders/docker. A Docker build tags the image with the full Artifact Registry path and lists that path in the images field so Cloud Build pushes it after the build succeeds.
The general lifecycle of a Cloud Build build is:
gcloud builds submit or automatically with a build trigger connected to Cloud Source Repositories, GitHub, or Bitbucket.A Docker build config reuses the same file across environments by using substitutions for location, repository, image, and project. User-defined substitutions such as ${_LOCATION}, ${_REPOSITORY}, and ${_IMAGE} are supplied at build time, while the default substitution $PROJECT_ID resolves to the project where Cloud Build runs. The same config can therefore push us-east1-docker.pkg.dev/PROJECT_ID/my-repo/my-image for one run and a different location, repository, or image for the next without editing the file.
Artifact Registry expands on Container Registry and is the recommended container registry for Google Cloud. The security and management differences center on how repositories are created, isolated, and authorized.
| Capability | Container Registry | Artifact Registry |
|---|---|---|
| Repository creation | Images push directly to registry hosts, with storage in Cloud Storage buckets in the project | Creating a repository is a separate administration step from pushing and pulling, with no buckets to manage |
| Registry location | Four multi-regional gcr.io hosts per project | Multiple regional or multi-regional repositories per project |
| Access control | Grant access with Cloud Storage roles on the whole multi-region host, not individual image paths | Grant access with Artifact Registry roles on individual repositories, with support for conditional access with tags |
| Encryption | Encrypt storage buckets that contain images with CMEK | Encrypt individual repositories with CMEK |
Because administration is separated from usage, repository owners create and secure the repository first, then developers and build service accounts only receive the push or pull access they need for that repository.
LOCATION-docker.pkg.dev/PROJECT_ID/REPOSITORY/IMAGE_NAME.images field appears in Cloud Build results, while an image stored with docker push inside a build step does not.Use the images field in Cloud Build when the image must appear in build results, and use docker push inside a build step when the push must happen at a specific point in the pipeline. An image stored with the images field is pushed after the build completes and appears on the Build description page, in Build.get(), and in gcloud builds list, while an image stored with docker push does not appear in build results.
Use the On-Demand Scanning API in Cloud Build when you want to block a risky image before it is pushed to Artifact Registry, and rely on automatic vulnerability scanning to monitor images already stored in Artifact Registry. On-Demand scanning runs when called in a build step and can fail the build if a blocked severity is found, while automatic scanning runs on image upload and continuously monitors for new vulnerabilities for up to 30 days after the push.
Binary Authorization enforces a deployment policy when a deploy is attempted by allowing deployment only for images with required proof such as compliance with a vulnerability scan policy. This enforcement depends on earlier pipeline evidence including On-Demand Scanning results, automatic scan data, and build provenance from Cloud Build that provides Supply Chain Levels for Software Artifacts Level 3 assurance.
Last updated