
Answer-first summary for fast verification
Answer: Add the --cache-from argument to the Docker build step in your build config file.
The correct answer is D. Adding the `--cache-from` argument to the Docker build step allows Docker to reuse cached layers from previous builds, significantly reducing build time by avoiding redundant layer creation. This optimization directly addresses the goal of improving deployment times. Options A, B, and C are incorrect: removing the push step (A) would break deployment, deploying a new Docker registry in a VPC (B) adds unnecessary complexity, and Cloud Storage (C) is not used for container image storage in Cloud Run deployments.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
No comments yet.
You are deploying a Python application to Cloud Run using Cloud Source Repositories and Cloud Build. The Cloud Build pipeline is shown below:
steps:
- name: python
entrypoint: pip
args: ["install", "-r", "requirements.txt", "--user"]
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'us-central1-docker.pkg.dev/$(PROJECT_ID)/$(_REPO_NAME)/myimage:$(SHORT_SHA)', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'us-central1-docker.pkg.dev/$(PROJECT_ID)/$(_REPO_NAME)/myimage:$(SHORT_SHA)']
- name: google/cloud-sdk
args: ['cloud', 'run', 'deploy', 'helloworld-$(SHORT_SHA)',
'--image=us-central1-docker.pkg.dev/$(PROJECT_ID)/$(_REPO_NAME)/myimage:$(SHORT_SHA)',
'--region', 'us-central1', '--platform', 'managed',
'--allow-unauthenticated']
steps:
- name: python
entrypoint: pip
args: ["install", "-r", "requirements.txt", "--user"]
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'us-central1-docker.pkg.dev/$(PROJECT_ID)/$(_REPO_NAME)/myimage:$(SHORT_SHA)', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'us-central1-docker.pkg.dev/$(PROJECT_ID)/$(_REPO_NAME)/myimage:$(SHORT_SHA)']
- name: google/cloud-sdk
args: ['cloud', 'run', 'deploy', 'helloworld-$(SHORT_SHA)',
'--image=us-central1-docker.pkg.dev/$(PROJECT_ID)/$(_REPO_NAME)/myimage:$(SHORT_SHA)',
'--region', 'us-central1', '--platform', 'managed',
'--allow-unauthenticated']
You want to optimize deployment times and avoid unnecessary steps. What should you do?
A
Remove the step that pushes the container to Artifact Registry.
B
Deploy a new Docker registry in a VPC, and use Cloud Build worker pools inside the VPC to run the build pipeline.
C
Store image artifacts in a Cloud Storage bucket in the same region as the Cloud Run instance.
D
Add the --cache-from argument to the Docker build step in your build config file.