From 61659634dfe21a2875d7b933823127c2474311b1 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 17:03:42 +0300 Subject: [PATCH 01/20] Update helloworld.sh --- helloworld.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helloworld.sh b/helloworld.sh index 79a32fd6..bfd578dc 100644 --- a/helloworld.sh +++ b/helloworld.sh @@ -1,2 +1,2 @@ #!/bin/sh -echo "Hello, world!" +echo "The time is $(date)" From a4ed66ec8971c3875e02fa7614697abc84530e4c Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:35:52 +0300 Subject: [PATCH 02/20] Create cloudbuild.yaml --- cloudbuild.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 cloudbuild.yaml diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 00000000..b85870c1 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,18 @@ + +# This step builds the container image. +- name: 'gcr.io/cloud-builders/docker' + id: Build + args: + - 'build' + - '-t' + - 'gcr.io/$PROJECT_ID/helloworld:$SHORT_SHA' + - '.' + +# This step pushes the image to Container Registry +# The PROJECT_ID and SHORT_SHA variables are automatically +# replaced by Cloud Build. +- name: 'gcr.io/cloud-builders/docker' + id: Push + args: + - 'push' + - 'gcr.io/$PROJECT_ID/helloworld:$SHORT_SHA' From c2e62971e48b10fdce95787253a70a9e55cffff9 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:46:21 +0300 Subject: [PATCH 03/20] Delete Dockerfile --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b5b30924..00000000 --- a/Dockerfile +++ /dev/null @@ -1,3 +0,0 @@ -FROM alpine -COPY helloworld.sh / -CMD ["/helloworld.sh"] From 9d1e63ea5f73a0860fa4481dbed007a24d5c0905 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:47:06 +0300 Subject: [PATCH 04/20] Update helloworld.sh --- helloworld.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helloworld.sh b/helloworld.sh index bfd578dc..e5d39867 100644 --- a/helloworld.sh +++ b/helloworld.sh @@ -1,2 +1,2 @@ #!/bin/sh -echo "The time is $(date)" +echo "Hello" From ac138737ee9c4b343076dd377db067d59bb32cbd Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:52:12 +0300 Subject: [PATCH 05/20] Update and rename helloworld.sh to app.py --- app.py | 10 ++++++++++ helloworld.sh | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 app.py delete mode 100644 helloworld.sh diff --git a/app.py b/app.py new file mode 100644 index 00000000..8b66ae20 --- /dev/null +++ b/app.py @@ -0,0 +1,10 @@ +from flask import Flask +app = Flask('hello-cloudbuild') + +@app.route('/') +def hello(): + return "Hello World!\n" + +if __name__ == '__main__': + app.run(host = '0.0.0.0', port = 8080) +Create a container image with Cloud B diff --git a/helloworld.sh b/helloworld.sh deleted file mode 100644 index e5d39867..00000000 --- a/helloworld.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -echo "Hello" From a37961263ba5034d897a2d0fc79c8c9e147d31c3 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:53:23 +0300 Subject: [PATCH 06/20] Create Dockerfile --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..f5c5c8ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM python:3.7-slim +RUN pip install flask +WORKDIR /app +COPY app.py /app/app.py +ENTRYPOINT ["python"] +CMD ["/app/app.py"] From 3f431f2ac9c9feee80db42007e751bfd6483793a Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:55:50 +0300 Subject: [PATCH 07/20] Update cloudbuild.yaml --- cloudbuild.yaml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index b85870c1..5338936b 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,3 +1,11 @@ +steps: +# This step runs the unit tests on the app +- name: 'python:3.7-slim' + id: Test + entrypoint: /bin/sh + args: + - -c + - 'pip install flask && python test_app.py -v' # This step builds the container image. - name: 'gcr.io/cloud-builders/docker' @@ -5,7 +13,7 @@ args: - 'build' - '-t' - - 'gcr.io/$PROJECT_ID/helloworld:$SHORT_SHA' + - 'gcr.io/$PROJECT_ID/hello-cloudbuild:$SHORT_SHA' - '.' # This step pushes the image to Container Registry @@ -15,4 +23,4 @@ id: Push args: - 'push' - - 'gcr.io/$PROJECT_ID/helloworld:$SHORT_SHA' + - 'gcr.io/$PROJECT_ID/hello-cloudbuild:$SHORT_SHA' From f7a8baea18629a8b4ad5982644bdcabd32047c21 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 19:59:05 +0300 Subject: [PATCH 08/20] Create test_app.py --- test_app.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 test_app.py diff --git a/test_app.py b/test_app.py new file mode 100644 index 00000000..93b0c68b --- /dev/null +++ b/test_app.py @@ -0,0 +1,24 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from app import hello + +class TestHelloApp(unittest.TestCase): + + def test_hello(self): + self.assertEqual(hello(), "Hello World!\n") + +if __name__ == '__main__': + unittest.main() From a9e53ca3e3d2236b8b482941e93bb7addf1a997e Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:05:01 +0300 Subject: [PATCH 09/20] Update test_app.py --- test_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_app.py b/test_app.py index 93b0c68b..fea2ee57 100644 --- a/test_app.py +++ b/test_app.py @@ -18,7 +18,7 @@ class TestHelloApp(unittest.TestCase): def test_hello(self): - self.assertEqual(hello(), "Hello World!\n") + self.assertEqual(hello(), "Hello World!!\n") if __name__ == '__main__': unittest.main() From 1b8e85817c819e6ed63e680bd50bb09eb801071b Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:07:17 +0300 Subject: [PATCH 10/20] Update cloudbuild.yaml --- cloudbuild.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 5338936b..12de84bc 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,11 +1,3 @@ -steps: -# This step runs the unit tests on the app -- name: 'python:3.7-slim' - id: Test - entrypoint: /bin/sh - args: - - -c - - 'pip install flask && python test_app.py -v' # This step builds the container image. - name: 'gcr.io/cloud-builders/docker' From 5d5bf8cddc0ccb3e97d5d3cd01f1f6afaa2a9bae Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:08:57 +0300 Subject: [PATCH 11/20] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 8b66ae20..7993334e 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ @app.route('/') def hello(): - return "Hello World!\n" + return "Hello World!!\n" if __name__ == '__main__': app.run(host = '0.0.0.0', port = 8080) From d79ba339c2bf125bed60fbebe07b1e34a25bc3d4 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:14:40 +0300 Subject: [PATCH 12/20] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 7993334e..5ae884c6 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ @app.route('/') def hello(): - return "Hello World!!\n" + return "Hello World!!!\n" if __name__ == '__main__': app.run(host = '0.0.0.0', port = 8080) From 804282602664caec6dcd1c3481abde4194d4c850 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:22:31 +0300 Subject: [PATCH 13/20] Update cloudbuild.yaml --- cloudbuild.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 12de84bc..aeef17af 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -1,4 +1,4 @@ - +steps: # This step builds the container image. - name: 'gcr.io/cloud-builders/docker' id: Build From 825e34155f41aa4f1066b2b6ee21da0552e133c3 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:26:12 +0300 Subject: [PATCH 14/20] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 5ae884c6..7993334e 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ @app.route('/') def hello(): - return "Hello World!!!\n" + return "Hello World!!\n" if __name__ == '__main__': app.run(host = '0.0.0.0', port = 8080) From 8fc57e45210df4beefc05adb5035185b1a2bf2e8 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:38:24 +0300 Subject: [PATCH 15/20] Create cloudbuild-delivery.yaml --- cloudbuild-delivery.yaml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 cloudbuild-delivery.yaml diff --git a/cloudbuild-delivery.yaml b/cloudbuild-delivery.yaml new file mode 100644 index 00000000..ea936916 --- /dev/null +++ b/cloudbuild-delivery.yaml @@ -0,0 +1,33 @@ +steps: +# This step deploys the new version of our container image +# in the hello-cloudbuild Kubernetes Engine cluster. +- name: 'gcr.io/cloud-builders/kubectl' + id: Deploy + args: + - 'apply' + - '-f' + - 'kubernetes.yaml' + env: + - 'CLOUDSDK_COMPUTE_ZONE=us-central1-b' + - 'CLOUDSDK_CONTAINER_CLUSTER=hello-cloudbuild' + +# This step copies the applied manifest to the production branch +# The COMMIT_SHA variable is automatically +# replaced by Cloud Build. +- name: 'gcr.io/cloud-builders/git' + id: Copy to production branch + entrypoint: /bin/sh + args: + - '-c' + - | + set -x && \ + # Configure Git to create commits with Cloud Build's service account + git config user.email $(gcloud auth list --filter=status:ACTIVE --format='value(account)') && \ + # Switch to the production branch and copy the kubernetes.yaml file from the candidate branch + git fetch origin production && git checkout production && \ + git checkout $COMMIT_SHA kubernetes.yaml && \ + # Commit the kubernetes.yaml file with a descriptive commit message + git commit -m "Manifest from commit $COMMIT_SHA + $(git log --format=%B -n 1 $COMMIT_SHA)" && \ + # Push the changes back to Cloud Source Repository + git push origin production From 2b198276361d3781f5dd4a01bc7c33cf2bdfe392 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:38:50 +0300 Subject: [PATCH 16/20] Create kubernetes.yaml.tpl --- kubernetes.yaml.tpl | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 kubernetes.yaml.tpl diff --git a/kubernetes.yaml.tpl b/kubernetes.yaml.tpl new file mode 100644 index 00000000..a463e274 --- /dev/null +++ b/kubernetes.yaml.tpl @@ -0,0 +1,48 @@ +# Copyright 2018 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-cloudbuild + labels: + app: hello-cloudbuild +spec: + replicas: 1 + selector: + matchLabels: + app: hello-cloudbuild + template: + metadata: + labels: + app: hello-cloudbuild + spec: + containers: + - name: hello-cloudbuild + image: gcr.io/GOOGLE_CLOUD_PROJECT/hello-cloudbuild:COMMIT_SHA + ports: + - containerPort: 8080 +--- +kind: Service +apiVersion: v1 +metadata: + name: hello-cloudbuild +spec: + selector: + app: hello-cloudbuild + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + type: LoadBalancer From 7e597bf68dd5efbdb646a71b017195629f6a7837 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 20:54:17 +0300 Subject: [PATCH 17/20] Update cloudbuild-delivery.yaml --- cloudbuild-delivery.yaml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/cloudbuild-delivery.yaml b/cloudbuild-delivery.yaml index ea936916..b7eb4918 100644 --- a/cloudbuild-delivery.yaml +++ b/cloudbuild-delivery.yaml @@ -10,24 +10,3 @@ steps: env: - 'CLOUDSDK_COMPUTE_ZONE=us-central1-b' - 'CLOUDSDK_CONTAINER_CLUSTER=hello-cloudbuild' - -# This step copies the applied manifest to the production branch -# The COMMIT_SHA variable is automatically -# replaced by Cloud Build. -- name: 'gcr.io/cloud-builders/git' - id: Copy to production branch - entrypoint: /bin/sh - args: - - '-c' - - | - set -x && \ - # Configure Git to create commits with Cloud Build's service account - git config user.email $(gcloud auth list --filter=status:ACTIVE --format='value(account)') && \ - # Switch to the production branch and copy the kubernetes.yaml file from the candidate branch - git fetch origin production && git checkout production && \ - git checkout $COMMIT_SHA kubernetes.yaml && \ - # Commit the kubernetes.yaml file with a descriptive commit message - git commit -m "Manifest from commit $COMMIT_SHA - $(git log --format=%B -n 1 $COMMIT_SHA)" && \ - # Push the changes back to Cloud Source Repository - git push origin production From efd0e3f7648dc9ce802d07b7ccbddffe6b1eaa3d Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 21:00:22 +0300 Subject: [PATCH 18/20] Update cloudbuild-delivery.yaml --- cloudbuild-delivery.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/cloudbuild-delivery.yaml b/cloudbuild-delivery.yaml index b7eb4918..4b761299 100644 --- a/cloudbuild-delivery.yaml +++ b/cloudbuild-delivery.yaml @@ -10,3 +10,4 @@ steps: env: - 'CLOUDSDK_COMPUTE_ZONE=us-central1-b' - 'CLOUDSDK_CONTAINER_CLUSTER=hello-cloudbuild' + - 'CLOUDSDK_CORE_PROJEC=o-epm-gcp-by-meetup1-ml-t1iylu' From b7dfc5e789dc777a366d5ee8976cb2e5baff2803 Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 21:05:16 +0300 Subject: [PATCH 19/20] Update cloudbuild-delivery.yaml --- cloudbuild-delivery.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudbuild-delivery.yaml b/cloudbuild-delivery.yaml index 4b761299..08418ebb 100644 --- a/cloudbuild-delivery.yaml +++ b/cloudbuild-delivery.yaml @@ -10,4 +10,4 @@ steps: env: - 'CLOUDSDK_COMPUTE_ZONE=us-central1-b' - 'CLOUDSDK_CONTAINER_CLUSTER=hello-cloudbuild' - - 'CLOUDSDK_CORE_PROJEC=o-epm-gcp-by-meetup1-ml-t1iylu' + - 'CLOUDSDK_CORE_PROJECT=o-epm-gcp-by-meetup1-ml-t1iylu' From c9487ce2bf04cee31631828a35346eecaedccc2b Mon Sep 17 00:00:00 2001 From: Svetlana-Panamarenka Date: Mon, 28 Oct 2019 22:29:22 +0300 Subject: [PATCH 20/20] Rename kubernetes.yaml.tpl to kubernetes.yaml --- kubernetes.yaml.tpl => kubernetes.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename kubernetes.yaml.tpl => kubernetes.yaml (100%) diff --git a/kubernetes.yaml.tpl b/kubernetes.yaml similarity index 100% rename from kubernetes.yaml.tpl rename to kubernetes.yaml