Google Professional Cloud Developer Question 388
Single answerGoogle Cloud PlatformYou are developing a web application and need to containerize it using Cloud Build. Your application requires a specific version of Node.js and must include a build artifact generated by a custom script. Which approach should you take to correctly build the container image?
- A
Create a Dockerfile that specifies the Node.js version and use a custom build step in the Cloud Build configuration file to run the script.
- B
Directly upload the source code to Cloud Build and specify the Node.js version in the cloudbuild.yaml file.
- C
Use a prebuilt Node.js image from Google Container Registry (GCR) and configure Cloud Build to only package the source code.
- D
Write a Cloud Run deployment configuration file that specifies the Node.js version and include the custom script in the deployment process.
Show answer and explanation
Correct answer: A
Explanation
To containerize an application with specific requirements, such as a Node.js version and a custom script, you should create a Dockerfile that defines these dependencies and processes. Cloud Build can then use the Dockerfile to build the container image. This approach ensures that the container image meets the application's requirements before deployment.
- A. Correct.
Correct. Creating a Dockerfile allows you to define the specific Node.js version and include the custom script as part of the build process. Cloud Build can then use this Dockerfile to generate the container image.
- B. Incorrect.
Incorrect. Cloud Build does not directly support specifying the Node.js version in the cloudbuild.yaml file. This must be handled in the Dockerfile or through a prebuilt image.
- C. Incorrect.
Incorrect. While prebuilt images can be used, they do not allow customization such as running custom scripts during the image build process.
- D. Incorrect.
Incorrect. Cloud Run is a deployment service and does not handle container image creation. The custom script and Node.js version would still need to be handled during the image build process.