Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature #2

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
96 changes: 91 additions & 5 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,104 @@
# Google Cloud Build script
#
# This build script is used to build the repository for every change pushed.
# The .m2 directory is cached across steps using a mounted volume and is saved to GCS for future runs.

# Manual Execution:
# Use the below command to invoke the build manually. Note the substitutions for BRANCH_NAME and
# REVISION_ID. These variables are normally populated when the build is executed via build triggers
# but will be empty during manual execution. Dummy branch and revisions can be passed during manual
# execution so the artifacts can be uploaded upon build completion.
#
# gcloud builds submit . \
# --config=cloudbuild.yaml \
# --substitutions=BRANCH_NAME="master",REVISION_ID="bd671f47ce9e95dce00d0c07aee08f46d65658e4"
#

steps:
###########################################################
# Step 1: Simple Bash command
# Step 1: Create the empty cached .m2 directory if not exists
###########################################################
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
gsutil mb gs://${_BUCKET} > /dev/null 2>&1
cachesize=$(gsutil du -s gs://${_BUCKET}/cache/.m2 | awk '{ print $1 }') #Check the size of the cache
if [[ $cachesize -eq 0 ]]; then
echo "Copying empty file to create maven cache path"
touch emptyfile.txt
gsutil cp emptyfile.txt gs://${_BUCKET}/cache/.m2/
fi

###########################################################
# Step 2: Retrieve the cached .m2 directory from GCS
###########################################################
- name: 'gcr.io/cloud-builders/gsutil'
args:
- '-m'
- 'rsync'
- '-r'
- 'gs://${_BUCKET}/cache/.m2'
- '/cache/.m2'
volumes:
- path: '/cache/.m2'
name: 'maven_cache'

###########################################################
# Step 3: Build, Test, and Verify
###########################################################
- name: 'gcr.io/cloud-builders/mvn'
args:
- '--batch-mode'
- 'verify'
volumes:
- path: '/cache/.m2'
name: 'maven_cache'
env:
- MAVEN_OPTS=-Dmaven.repo.local=/cache/.m2

###########################################################
# Step 4: Update cached .m2 directory on GCS with additional
# dependencies downloaded during the current build
###########################################################
- name: 'gcr.io/cloud-builders/gsutil'
args:
- '-m'
- 'rsync'
- '-r'
- '/cache/.m2'
- 'gs://${_BUCKET}/cache/.m2'
volumes:
- path: '/cache/.m2'
name: 'maven_cache'


###########################################################
# Step 5: Copy the Jar to public artifactory in case of
# push request to master branch of main repository
###########################################################
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
echo line1
if [[ $? -eq 0 ]]; then
echo "Command completed successfully"
fi
if [ "${_MAIN_REPO}" == "True" -a "$BRANCH_NAME" == "master" ]; then
echo "Copying jar files to artifactory"
gsutil -m cp target/*.jar gs://${_BUCKET}/artifacts/$BRANCH_NAME/$REVISION_ID/
fi


substitutions:
# Default values
_BUCKET: 'cloud-pso-artifactory'
_MAIN_REPO: 'False'

options:
# Use higher CPU machines so the caching and build steps are faster.
machineType: 'N1_HIGHCPU_32'