From eff27cd50345966ac4f7b9ab7a7273d96dbc9b36 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Tue, 16 Feb 2016 16:42:45 +0100 Subject: [PATCH 1/7] Fix: add src and workdir to correct root path. --- examples/guestbook-go/_src/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/guestbook-go/_src/Dockerfile b/examples/guestbook-go/_src/Dockerfile index adbe6c2237e..e3132af1a50 100644 --- a/examples/guestbook-go/_src/Dockerfile +++ b/examples/guestbook-go/_src/Dockerfile @@ -14,9 +14,9 @@ FROM google/golang:latest -ADD . /gopath/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src +ADD . /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src -WORKDIR /gopath/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/ +WORKDIR /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/ RUN cd _src/ && go get && go build -o ../bin/guestbook RUN cp _src/guestbook/Dockerfile . From 6fe13ab72684964c5dd8215db30ae3c78a1dabe8 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Sat, 20 Feb 2016 23:16:51 +0100 Subject: [PATCH 2/7] using official golang image --- examples/guestbook-go/_src/Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/guestbook-go/_src/Dockerfile b/examples/guestbook-go/_src/Dockerfile index e3132af1a50..f342d028622 100644 --- a/examples/guestbook-go/_src/Dockerfile +++ b/examples/guestbook-go/_src/Dockerfile @@ -12,9 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM google/golang:latest +FROM golang:latest -ADD . /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src +ADD . /gopath/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src WORKDIR /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/ RUN cd _src/ && go get && go build -o ../bin/guestbook From 90c89e15b676563b931e6df12a98ef898c54a661 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Sat, 20 Feb 2016 23:25:03 +0100 Subject: [PATCH 3/7] Fix: add src to correct root path. --- examples/guestbook-go/_src/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/guestbook-go/_src/Dockerfile b/examples/guestbook-go/_src/Dockerfile index f342d028622..36689b99520 100644 --- a/examples/guestbook-go/_src/Dockerfile +++ b/examples/guestbook-go/_src/Dockerfile @@ -14,7 +14,7 @@ FROM golang:latest -ADD . /gopath/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src +ADD . /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src WORKDIR /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/ RUN cd _src/ && go get && go build -o ../bin/guestbook From 771354f14a1398bb8e47de50245c85532c5c3b6d Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Tue, 15 Mar 2016 09:49:50 +0100 Subject: [PATCH 4/7] replacing the shell scripts with a Makefile --- examples/guestbook-go/_src/Makefile | 39 +++++++++++++++++++ examples/guestbook-go/_src/README.md | 30 ++++----------- examples/guestbook-go/_src/script/build.sh | 25 ------------ examples/guestbook-go/_src/script/clean.sh | 26 ------------- examples/guestbook-go/_src/script/push.sh | 24 ------------ examples/guestbook-go/_src/script/release.sh | 40 -------------------- 6 files changed, 47 insertions(+), 137 deletions(-) create mode 100644 examples/guestbook-go/_src/Makefile delete mode 100755 examples/guestbook-go/_src/script/build.sh delete mode 100755 examples/guestbook-go/_src/script/clean.sh delete mode 100755 examples/guestbook-go/_src/script/push.sh delete mode 100755 examples/guestbook-go/_src/script/release.sh diff --git a/examples/guestbook-go/_src/Makefile b/examples/guestbook-go/_src/Makefile new file mode 100644 index 00000000000..9c89fbcd95f --- /dev/null +++ b/examples/guestbook-go/_src/Makefile @@ -0,0 +1,39 @@ +# Copyright 2016 The Kubernetes Authors All rights reserved. +# +# 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 +# +# http://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. + +# Build the guestbook-go example + +# Usage: +# [VERSION=v3] [REGISTRY="gcr.io/google_containers"] make build +VERSION?=v3 +REGISTRY?=gcr.io/google_containers + +release: clean build push clean + +# builds a docker image that builds the app and packages it into a minimal docker image +build: + docker build --rm --force-rm -t ${REGISTRY}/guestbook-builder . + docker run --rm ${REGISTRY}/guestbook-builder | docker build -t "${REGISTRY}/guestbook:${VERSION}" - + +# push the image to an registry +push: + gcloud docker push ${REGISTRY}/guestbook:${VERSION} + +# remove previous images and containers +clean: + docker rm -f ${REGISTRY}/guestbook-builder 2> /dev/null || true + docker rmi -f ${REGISTRY}/guestbook-builder || true + docker rmi -f "${REGISTRY}/guestbook:${VERSION}" || true + +.PHONY: release clean build push diff --git a/examples/guestbook-go/_src/README.md b/examples/guestbook-go/_src/README.md index bba1f0dcfa4..fd3d68ad35c 100644 --- a/examples/guestbook-go/_src/README.md +++ b/examples/guestbook-go/_src/README.md @@ -36,36 +36,22 @@ Documentation for other releases can be found at This process employs building two docker images, one compiles the source and the other hosts the compiled binaries. -Releasing the image requires that you have access to the docker registry user account which will host the image. +Releasing the image requires that you have access to the docker registry user account which will host the image. You can specify the registry including the user account by setting the environment variable `REGISTRY`. To build and release the guestbook image: cd examples/guestbook-go/_src - ./script/release.sh + make release -#### Step by step +To build and release the guestbook image with a different registry and version: -If you may want to, you can build and push the image step by step. + VERSION=v4 REGISTRY="docker.io/luebken" make build -###### Start fresh before building +If you want to, you can build and push the image step by step: - ./script/clean.sh 2> /dev/null - -###### Build - -Builds a docker image that builds the app and packages it into a minimal docker image - - ./script/build.sh - -###### Push - -Accepts an optional tag (defaults to "latest") - - ./script/push.sh [TAG] - -###### Clean up - - ./script/clean.sh + make clean + make build + make push diff --git a/examples/guestbook-go/_src/script/build.sh b/examples/guestbook-go/_src/script/build.sh deleted file mode 100755 index 9aee8a1a8ea..00000000000 --- a/examples/guestbook-go/_src/script/build.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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 -# -# http://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. - -# Usage: ./script/build.sh - -set -o errexit -set -o nounset -set -o pipefail - -guestbook_version=${1:-latest} -docker build --rm --force-rm -t kubernetes/guestbook-builder . -docker run --rm kubernetes/guestbook-builder | docker build -t "kubernetes/guestbook:${guestbook_version}" - diff --git a/examples/guestbook-go/_src/script/clean.sh b/examples/guestbook-go/_src/script/clean.sh deleted file mode 100755 index 026b8ad9ec9..00000000000 --- a/examples/guestbook-go/_src/script/clean.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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 -# -# http://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. - -# Usage: ./script/clean.sh - -set -o errexit -set -o nounset -set -o pipefail - -guestbook_version=${1:-latest} -docker rm -f guestbook-builder 2> /dev/null || true -docker rmi -f kubernetes/guestbook-builder || true -docker rmi -f "kubernetes/guestbook:${guestbook_version}" || true diff --git a/examples/guestbook-go/_src/script/push.sh b/examples/guestbook-go/_src/script/push.sh deleted file mode 100755 index 2d359ccc0bf..00000000000 --- a/examples/guestbook-go/_src/script/push.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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 -# -# http://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. - -# Usage: ./script/push.sh [TAG] - -set -o errexit -set -o nounset -set -o pipefail - -guestbook_version=${1:-latest} -docker push "kubernetes/guestbook:${guestbook_version}" diff --git a/examples/guestbook-go/_src/script/release.sh b/examples/guestbook-go/_src/script/release.sh deleted file mode 100755 index 34af8fb414f..00000000000 --- a/examples/guestbook-go/_src/script/release.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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 -# -# http://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. - -# Usage: ./script/release.sh [TAG] - -set -o errexit -set -o nounset -set -o pipefail - -base_dir=$(dirname "$0") -base_dir=$(cd "${base_dir}" && pwd) - -guestbook_version=${1:-latest} - -echo " ---> Cleaning up before building..." -"${base_dir}/clean.sh" "${guestbook_version}" 2> /dev/null - -echo " ---> Building..." -"${base_dir}/build.sh" "${guestbook_version}" - -echo " ---> Pushing kubernetes/guestbook:${guestbook_version}..." -"${base_dir}/push.sh" "${guestbook_version}" - -echo " ---> Cleaning up..." -"${base_dir}/clean.sh" "${guestbook_version}" - -echo " ---> Done." From 1531700f4230011a844b052840e3c75ed2bfa697 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Tue, 15 Mar 2016 10:18:28 +0100 Subject: [PATCH 5/7] using registry and image name as specified in _src/Makefile --- examples/guestbook-go/guestbook-controller.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/guestbook-go/guestbook-controller.json b/examples/guestbook-go/guestbook-controller.json index 2fe5d99c71d..82c0e9134fd 100644 --- a/examples/guestbook-go/guestbook-controller.json +++ b/examples/guestbook-go/guestbook-controller.json @@ -22,7 +22,7 @@ "containers":[ { "name":"guestbook", - "image":"kubernetes/guestbook:v2", + "image":"gcr.io/google_containers/guestbook:v3", "ports":[ { "name":"http-server", From cc91f129a003dcfd15380483765f8f2ac241ff8a Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Mon, 21 Mar 2016 22:22:41 +0100 Subject: [PATCH 6/7] pinned version --- examples/guestbook-go/_src/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/guestbook-go/_src/Dockerfile b/examples/guestbook-go/_src/Dockerfile index 36689b99520..b1bb5ea0ef4 100644 --- a/examples/guestbook-go/_src/Dockerfile +++ b/examples/guestbook-go/_src/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM golang:latest +FROM golang:1.6.0 ADD . /go/src/github.com/GoogleCloudPlatform/kubernetes/examples/guestbook-go/_src From 95cee0db17dc5a586a1bbba30baf20fcf8c47945 Mon Sep 17 00:00:00 2001 From: Matthias Luebken Date: Mon, 21 Mar 2016 22:23:53 +0100 Subject: [PATCH 7/7] * updated console output to reflect actual output * added a tip how to build your own image --- examples/guestbook-go/README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/guestbook-go/README.md b/examples/guestbook-go/README.md index 4f52621f36b..a2cf0c89ad6 100644 --- a/examples/guestbook-go/README.md +++ b/examples/guestbook-go/README.md @@ -95,8 +95,8 @@ Use the `examples/guestbook-go/redis-master-controller.json` file to create a [r me@workstation$ gcloud compute ssh --zone us-central1-b kubernetes-minion-bz1p me@kubernetes-minion-3:~$ sudo docker ps - CONTAINER ID IMAGE COMMAND CREATED STATUS - d5c458dabe50 gurpartap/redis:latest "/usr/local/bin/redi 5 minutes ago Up 5 minutes + CONTAINER ID IMAGE COMMAND CREATED STATUS + d5c458dabe50 redis "/entrypoint.sh redis" 5 minutes ago Up 5 minutes ``` Note: The initial `docker pull` can take a few minutes, depending on network conditions. @@ -141,9 +141,9 @@ The Redis master we created earlier is a single pod (REPLICAS = 1), while the Re ```console $ kubectl get rc - CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS - redis-master redis-master gurpartap/redis app=redis,role=master 1 - redis-slave redis-slave gurpartap/redis app=redis,role=slave 2 + CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS + redis-master redis-master redis app=redis,role=master 1 + redis-slave redis-slave kubernetes/redis-slave:v2 app=redis,role=slave 2 ... ``` @@ -205,14 +205,16 @@ This is a simple Go `net/http` ([negroni](https://github.com/codegangsta/negroni replicationcontrollers/guestbook ``` + Tip: If you want to modify the guestbook code open the `_src` of this example and read the README.md and the Makefile. If you have pushed your custom image be sure to update the `image` accordingly in the guestbook-controller.json. + 2. To verify that the guestbook replication controller is running, run the `kubectl get rc` command: ```console $ kubectl get rc - CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS - guestbook guestbook kubernetes/guestbook:v2 app=guestbook 3 - redis-master redis-master gurpartap/redis app=redis,role=master 1 - redis-slave redis-slave gurpartap/redis app=redis,role=slave 2 + CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS + guestbook guestbook gcr.io/google_containers/guestbook:v3 app=guestbook 3 + redis-master redis-master redis app=redis,role=master 1 + redis-slave redis-slave kubernetes/redis-slave:v2 app=redis,role=slave 2 ... ```