Created
October 30, 2019 05:36
-
-
Save jed204/e2ee82eab958d999b98c082bf4290624 to your computer and use it in GitHub Desktop.
Google Cloud Build Maven Build with Cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
steps: | |
# Grab cached M2 repo | |
- name: gcr.io/cloud-builders/gsutil | |
id: Get M2 Cache | |
args: ['cp', 'gs://BUCKET_NAME/m2.tar.gz', 'm2.tar.gz'] | |
# See https://github.com/GoogleCloudPlatform/cloud-builders-community to get the tar command | |
- name: gcr.io/PROJECT_ID/tar | |
id: Expand M2 Cache | |
args: ['xpzf', 'm2.tar.gz'] | |
# Optional, we had some extra settings to include | |
- name: 'gcr.io/cloud-builders/gsutil' | |
id: Get setting.xml | |
args: ['cp', 'gs://BUCKET_NAME/settings.xml', 'custom-settings.xml'] | |
# The maven.repo.local setting was key | |
- name: 'gcr.io/cloud-builders/mvn' | |
id: Test and Build | |
args: ['-Dmaven.repo.local=/workspace/.m2/repository', '--settings', 'custom-settings.xml', 'deploy'] | |
# Update M2 repo cache | |
- name: gcr.io/PROJECT_ID/tar | |
id: Compress M2 Cache | |
args: ['cpzf', 'm2.tar.gz', '.m2'] | |
- name: gcr.io/cloud-builders/gsutil | |
id: Save M2 Cache | |
args: ['cp', 'm2.tar.gz', 'gs://BUCKET_NAME/m2.tar.gz'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You have to seed your bucket with a m2.tar.gz file. Adding the .m2 cache via this method sped up our build about 50%. We have about 180MB of jar files that were being downloaded from central every build.
This concept is addressed in the Google Cloud Build docs but there isn't a great example of it: https://cloud.google.com/cloud-build/docs/speeding-up-builds