From c267af7c34a97dd4c75d151f81bcabd00601556a Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Tue, 8 Jan 2019 12:09:22 -0500 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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' From 81deb19830a607a7928399d758666dcdc15faf26 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 09:56:59 -0500 Subject: [PATCH 04/12] Update skaffold to v0.20.0 (to support newer skaffold config) --- cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index bf8aea7..2d031ce 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -11,7 +11,7 @@ steps: - id: 'Deploy application to cluster' - name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' + name: 'gcr.io/k8s-skaffold/skaffold:v0.20.0' entrypoint: 'bash' args: - '-c' From 9e257200a49c047d584519f5a00399759950e945 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Tue, 8 Jan 2019 12:09:22 -0500 Subject: [PATCH 05/12] 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 2d031ce..8b76515 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.20.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 9965b316518050ce5acb388fc91a0f228fa85a67 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Tue, 8 Jan 2019 12:15:25 -0500 Subject: [PATCH 06/12] Uncomment cluster push --- cloudbuild.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 8b76515..80c017d 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -23,7 +23,11 @@ steps: steps: - id: 'Deploy application to cluster' +<<<<<<< HEAD name: 'gcr.io/k8s-skaffold/skaffold:v0.20.0' +======= + name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' +>>>>>>> Uncomment cluster push entrypoint: 'bash' args: - '-c' From cce5d03dd0f4e8fa3596c9ba5e4d7732eeb704a5 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 11:36:12 -0500 Subject: [PATCH 07/12] rebase to get new skaffold version --- cloudbuild.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 80c017d..8b76515 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -23,11 +23,7 @@ steps: steps: - id: 'Deploy application to cluster' -<<<<<<< HEAD name: 'gcr.io/k8s-skaffold/skaffold:v0.20.0' -======= - name: 'gcr.io/k8s-skaffold/skaffold:v0.18.0' ->>>>>>> Uncomment cluster push entrypoint: 'bash' args: - '-c' From 6c0be012702214cd6a34b4ced9a2f9ba481781c6 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 11:44:45 -0500 Subject: [PATCH 08/12] Dummy commit to trigger Cloud Build --- cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 8b76515..3000d0e 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -3,7 +3,7 @@ # # PREREQUISITES: # - Cloud Build service account must have role: "Kubernetes Engine Developer" - +# # USAGE: # GCP zone and GKE target cluster must be specified as substitutions # Example invocation: From 1f390993804579e2d8986c6721ee9b000efd9559 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 11:57:44 -0500 Subject: [PATCH 09/12] Fix invalid YAML --- cloudbuild.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 3000d0e..f9a30ab 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -3,7 +3,7 @@ # # PREREQUISITES: # - Cloud Build service account must have role: "Kubernetes Engine Developer" -# + # USAGE: # GCP zone and GKE target cluster must be specified as substitutions # Example invocation: @@ -21,7 +21,6 @@ steps: - "COMMIT_SHA=$COMMIT_SHA" - "SHORT_SHA=$SHORT_SHA" -steps: - id: 'Deploy application to cluster' name: 'gcr.io/k8s-skaffold/skaffold:v0.20.0' entrypoint: 'bash' From e86aa072ed86e83bf1f69612869ebc853213e8b6 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 12:04:21 -0500 Subject: [PATCH 10/12] dummy commit to trigger GCB --- cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index f9a30ab..a6998b5 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -3,7 +3,7 @@ # # PREREQUISITES: # - Cloud Build service account must have role: "Kubernetes Engine Developer" - +# # USAGE: # GCP zone and GKE target cluster must be specified as substitutions # Example invocation: From f1736e4c73b803aab23ce3360828de5734692bb1 Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 12:06:55 -0500 Subject: [PATCH 11/12] Suppress logging of footer contents during build --- tools/insert_git_commit_link.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/insert_git_commit_link.sh b/tools/insert_git_commit_link.sh index 00f84ae..900d8bf 100755 --- a/tools/insert_git_commit_link.sh +++ b/tools/insert_git_commit_link.sh @@ -8,5 +8,6 @@ if [[ "$COMMIT_SHA" && "$SHORT_SHA" ]]; then sed -i'' -e "s^$target^$replace^g" src/frontend/templates/footer.html - cat src/frontend/templates/footer.html + # echo 'debug: contents of footer.html:' + # cat src/frontend/templates/footer.html fi \ No newline at end of file From a4cadd5be9a8721a0c7f30803a92ec68df046cbf Mon Sep 17 00:00:00 2001 From: Dave Stanke Date: Mon, 14 Jan 2019 12:38:57 -0500 Subject: [PATCH 12/12] Remove spurious character --- tools/insert_git_commit_link.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/insert_git_commit_link.sh b/tools/insert_git_commit_link.sh index 900d8bf..44d8a0d 100755 --- a/tools/insert_git_commit_link.sh +++ b/tools/insert_git_commit_link.sh @@ -4,7 +4,7 @@ if [[ "$COMMIT_SHA" && "$SHORT_SHA" ]]; then target="" replace=" [${SHORT_SHA}]#" + style='font-size:80%'>${SHORT_SHA}]" sed -i'' -e "s^$target^$replace^g" src/frontend/templates/footer.html