Google Professional Cloud Developer Question 390
Select 3Google Cloud PlatformYou are a developer tasked with building a container image for your application using Cloud Build. The application source code is stored in a GitHub repository. You want to ensure the build process automatically triggers whenever new code is pushed to the main branch. Which steps should you take to achieve this?
- A
Connect the GitHub repository to your Google Cloud project using the Cloud Build GitHub App.
- B
Create a
cloudbuild.yamlfile in the root directory of your repository to define the build steps. - C
Manually build the container image using the
gcloud builds submitcommand each time code is pushed. - D
Create a trigger in Cloud Build that listens to changes in the
mainbranch of your GitHub repository. - E
Configure a Dockerfile to be used by Cloud Build and include it in the repository.
Show answer and explanation
Correct answers: A, B, D
Explanation
To automate the container image build process using Cloud Build, you need to connect your GitHub repository to Cloud Build using the GitHub App and define the build process in a cloudbuild.yaml file. Additionally, you must create a trigger that listens for changes to the main branch to ensure the build runs automatically. Manual builds or simply including a Dockerfile in the repository do not meet the automation requirements.
- A. Correct.
Correct: Connecting the GitHub repository to Cloud Build using the GitHub App is necessary to enable automatic triggers for builds.
- B. Correct.
Correct: A
cloudbuild.yamlfile is required to define the build steps that Cloud Build should execute when triggered. - C. Incorrect.
Incorrect: Manually building the container image each time code is pushed does not align with the requirement for automation.
- D. Correct.
Correct: Creating a trigger in Cloud Build ensures that the build process is automatically initiated whenever new code is pushed to the
mainbranch. - E. Incorrect.
Incorrect: While a Dockerfile is commonly used to build container images, simply including it in the repository is not enough to automate the build process.