Google Professional Cloud Developer Question 386
Select 3Google Cloud PlatformYou are tasked with building a container image for your application using Cloud Build. The application requires a specific version of Python and some dependencies listed in a 'requirements.txt' file. You also need to ensure the resulting container image is pushed to a Google Container Registry (GCR) repository. Which steps should you include in your Cloud Build configuration file to achieve this?
- A
Define a 'steps' section in the Cloud Build configuration file that specifies the 'gcr.io/cloud-builders/docker' image with commands to build and push the container image.
- B
Add a 'steps' section to install Python dependencies by specifying a step that uses the 'gcr.io/cloud-builders/pip' image.
- C
Specify the 'images' field in the Cloud Build configuration file with the target GCR repository URL where the image should be pushed.
- D
Use the 'docker build' command in the 'steps' section to build the image and tag it with the GCR repository URL.
- E
Add a 'timeout' field to the Cloud Build configuration file to ensure the build process completes within a specified time frame.
Show answer and explanation
Correct answers: A, C, D
Explanation
To build and push a container image using Cloud Build, you need to define the 'steps' section to specify the actions required, such as building and pushing the image using the 'docker' builder. The 'images' field is required to specify the destination repository in GCR. A Dockerfile would typically handle tasks like installing dependencies. Adding a 'timeout' is optional and not directly relevant to this requirement.
- A. Correct.
Correct: The 'steps' section is essential in a Cloud Build configuration file, and using the 'gcr.io/cloud-builders/docker' image is a common approach for building and pushing container images.
- B. Incorrect.
Incorrect: While Python dependencies are necessary, Cloud Build does not have a predefined 'pip' builder image. Instead, dependencies are typically installed in the container's build process using a Dockerfile.
- C. Correct.
Correct: The 'images' field specifies where the resulting container image should be pushed, such as a GCR repository.
- D. Correct.
Correct: The 'docker build' command is the standard way to build and tag container images, and the tag should include the GCR repository URL for proper pushing.
- E. Incorrect.
Incorrect: While the 'timeout' field is optional and can be added to a Cloud Build configuration file, it is not required to successfully build and push a container image.