Google Professional Cloud Developer Question 259
Select 3Google Cloud PlatformYour team is experiencing slow build times in a CI/CD pipeline for a Node.js application deployed on Google Cloud. You suspect unnecessary files and dependencies are being included in the build process. What steps can you take to optimize the build and reduce the time it takes?
- A
Use a .gcloudignore file to exclude unnecessary files during the deployment process.
- B
Enable Cloud Build caching to reuse layers from previous builds.
- C
Add all files in your project directory to the build context to ensure completeness.
- D
Use a package manager like npm or yarn to install only production dependencies during the build stage.
- E
Create a custom container image for your application with all dependencies pre-installed.
Show answer and explanation
Correct answers: A, B, D
Explanation
Optimizing builds in a CI/CD pipeline often involves reducing unnecessary files and dependencies, leveraging caching mechanisms, and minimizing the size of the build context. Using a .gcloudignore file, enabling Cloud Build caching, and focusing only on production dependencies are effective ways to achieve this. Avoiding redundant files and dependencies ensures faster and more efficient builds.
- A. Correct.
Using a .gcloudignore file helps exclude unnecessary files (e.g., test files, local configuration files) from being uploaded to Google Cloud Build, reducing the build time and improving efficiency.
- B. Correct.
Enabling Cloud Build caching allows the reuse of unchanged layers from previous builds, which significantly optimizes build times.
- C. Incorrect.
Including all files in the project directory is unnecessary and counterproductive. It increases the build context size, leading to slower build times.
- D. Correct.
Installing only production dependencies (using npm or yarn with the '--production' flag) during the build stage ensures that dev dependencies are excluded, reducing the size of the application and improving build speed.
- E. Incorrect.
Creating a custom container image can be useful in some cases but is not specific to optimizing the build process in this scenario. It also adds complexity unless absolutely required.