On triggered build, write git commit to front end

This commit is contained in:
Dave Stanke 2019-01-08 12:09:22 -05:00
parent d944092100
commit c267af7c34
3 changed files with 28 additions and 4 deletions

View file

@ -9,15 +9,27 @@
# Example invocation: # Example invocation:
# `gcloud builds submit --config=cloudbuild.yaml --substitutions=_ZONE=us-central1-b,_CLUSTER=demo-app-staging .` # `gcloud builds submit --config=cloudbuild.yaml --substitutions=_ZONE=us-central1-b,_CLUSTER=demo-app-staging .`
steps:
- id: 'Write git commit to frontend'
name: 'ubuntu'
entrypoint: 'bash'
args:
- '-c'
- |
tools/insert_git_commit_link.sh
env:
- "COMMIT_SHA=$COMMIT_SHA"
- "SHORT_SHA=$SHORT_SHA"
steps: steps:
- id: 'Deploy application to cluster' - id: 'Deploy application to cluster'
name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0'
entrypoint: 'bash' entrypoint: 'bash'
args: args:
- '-c' - '-c'
- > - |
gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER; gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER
skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID; skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID
# Add more power, and more time, for heavy Skaffold build # Add more power, and more time, for heavy Skaffold build
timeout: '3600s' timeout: '3600s'

View file

@ -4,7 +4,7 @@
<p> <p>
&copy; 2018 Google Inc &copy; 2018 Google Inc
<span class="text-muted"> <span class="text-muted">
<a href="https://github.com/GoogleCloudPlatform/microservices-demo/">(Source Code)</a> (<a href="https://github.com/GoogleCloudPlatform/microservices-demo/">Source Code</a><!--GIT_COMMIT_LINK-->)
</span> </span>
</p> </p>
<p> <p>

12
tools/insert_git_commit_link.sh Executable file
View file

@ -0,0 +1,12 @@
# when project is built by Cloud Build from a source trigger, the
# commit SHA will be available as an env var
if [[ "$COMMIT_SHA" && "$SHORT_SHA" ]]; then
target="<!--GIT_COMMIT_LINK-->"
replace=" [<a href='https://github.com/GoogleCloudPlatform/microservices-demo/commit/${COMMIT_SHA}'\
style='font-size:80%'>${SHORT_SHA}</a>]#"
sed -i'' -e "s^$target^$replace^g" src/frontend/templates/footer.html
cat src/frontend/templates/footer.html
fi