From c267af7c34a97dd4c75d151f81bcabd00601556a Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Tue, 8 Jan 2019 12:09:22 -0500 Subject: [PATCH 1/3] On triggered build, write git commit to front end --- cloudbuild.yaml | 18 +++++++++++++++--- src/frontend/templates/footer.html | 2 +- tools/insert_git_commit_link.sh | 12 ++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100755 tools/insert_git_commit_link.sh diff --git a/cloudbuild.yaml b/cloudbuild.yaml index bf8aea7..0417f27 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -9,15 +9,27 @@ # Example invocation: # `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: - id: 'Deploy application to cluster' name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' entrypoint: 'bash' args: - '-c' - - > - gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER; - skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID; + - | + gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER + skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID # Add more power, and more time, for heavy Skaffold build timeout: '3600s' diff --git a/src/frontend/templates/footer.html b/src/frontend/templates/footer.html index 0ca31e1..5519847 100644 --- a/src/frontend/templates/footer.html +++ b/src/frontend/templates/footer.html @@ -4,7 +4,7 @@

© 2018 Google Inc - (Source Code) + (Source Code)

diff --git a/tools/insert_git_commit_link.sh b/tools/insert_git_commit_link.sh new file mode 100755 index 0000000..00f84ae --- /dev/null +++ b/tools/insert_git_commit_link.sh @@ -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="" + replace=" [${SHORT_SHA}]#" + + sed -i'' -e "s^$target^$replace^g" src/frontend/templates/footer.html + + cat src/frontend/templates/footer.html +fi \ No newline at end of file From e5f1f9c53557b80ed329535e92a62aa28dfc7efd Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Tue, 8 Jan 2019 12:12:25 -0500 Subject: [PATCH 2/3] testing GCB env vars --- cloudbuild.yaml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 0417f27..10531ab 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -16,20 +16,22 @@ steps: args: - '-c' - | + env + echo "-----------------" tools/insert_git_commit_link.sh env: - "COMMIT_SHA=$COMMIT_SHA" - "SHORT_SHA=$SHORT_SHA" -steps: -- id: 'Deploy application to cluster' - name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' - entrypoint: 'bash' - args: - - '-c' - - | - gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER - skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID +# steps: +# - id: 'Deploy application to cluster' +# name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' +# entrypoint: 'bash' +# args: +# - '-c' +# - | +# gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER +# skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID # Add more power, and more time, for heavy Skaffold build timeout: '3600s' From a9d8b08e3de5eec6c8f147c1d2ff7e368bce62f1 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Tue, 8 Jan 2019 12:15:25 -0500 Subject: [PATCH 3/3] Uncomment cluster push --- cloudbuild.yaml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 10531ab..0417f27 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -16,22 +16,20 @@ steps: args: - '-c' - | - env - echo "-----------------" tools/insert_git_commit_link.sh env: - "COMMIT_SHA=$COMMIT_SHA" - "SHORT_SHA=$SHORT_SHA" -# steps: -# - id: 'Deploy application to cluster' -# name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' -# entrypoint: 'bash' -# args: -# - '-c' -# - | -# gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER -# skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID +steps: +- id: 'Deploy application to cluster' + name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' + entrypoint: 'bash' + args: + - '-c' + - | + gcloud container clusters get-credentials --zone=$_ZONE $_CLUSTER + skaffold run -f=skaffold.yaml --default-repo=gcr.io/$PROJECT_ID # Add more power, and more time, for heavy Skaffold build timeout: '3600s'