From 5f484579b5cc04900591c61cf87ece00fe8426d7 Mon Sep 17 00:00:00 2001 From: Manjunath A Kumatagi Date: Fri, 28 Jul 2017 21:25:53 +0530 Subject: [PATCH] Multi arch guestbook example --- guestbook/php-redis/Makefile | 81 ++++++++++++++++++++++++++++++++ guestbook/redis-slave/Dockerfile | 6 +-- guestbook/redis-slave/Makefile | 76 ++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 4 deletions(-) create mode 100644 guestbook/php-redis/Makefile create mode 100644 guestbook/redis-slave/Makefile diff --git a/guestbook/php-redis/Makefile b/guestbook/php-redis/Makefile new file mode 100644 index 00000000..20b00715 --- /dev/null +++ b/guestbook/php-redis/Makefile @@ -0,0 +1,81 @@ +# Copyright 2017 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. + +TAG = v5 +REGISTRY = gcr.io/google-samples +ARCH ?= $(shell go env GOARCH) +ALL_ARCH = amd64 arm arm64 ppc64le + +QEMUVERSION=v2.7.0 + +IMAGE = $(REGISTRY)/gb-frontend +MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) + +# Set default base image dynamically for each arch +ifeq ($(ARCH),arm) + QEMUARCH=arm + BASEIMAGE=armhf/php:5.6-apache +endif +ifeq ($(ARCH),arm64) + QEMUARCH=aarch64 + BASEIMAGE=arm64v8/php:5-apache +endif +ifeq ($(ARCH),ppc64le) + QEMUARCH=ppc64le + BASEIMAGE=ppc64le/php:5-apache +endif + +TEMP_DIR := $(shell mktemp -d) + +all: all-container + +sub-container-%: + $(MAKE) ARCH=$* container + +sub-push-%: + $(MAKE) ARCH=$* push + +all-container: $(addprefix sub-container-,$(ALL_ARCH)) + +all-push: $(addprefix sub-push-,$(ALL_ARCH)) + + +container: .container-$(ARCH) +.container-$(ARCH): + cp ./* $(TEMP_DIR) + +ifneq ($(ARCH),amd64) + cd $(TEMP_DIR) && sed -i "s|FROM php.*|FROM $(BASEIMAGE)\nCOPY qemu-$(QEMUARCH)-static /usr/bin\n|g" Dockerfile + # Register /usr/bin/qemu-ARCH-static as the handler for ARM binaries in the kernel + docker run --rm --privileged multiarch/qemu-user-static:register --reset + curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR) +endif + docker build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR) + +ifeq ($(ARCH), amd64) + # This is for to maintain the backward compatibility + docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG) +endif + +push: .push-$(ARCH) +.push-$(ARCH): .container-$(ARCH) + gcloud docker -- push $(MULTI_ARCH_IMG):$(TAG) +ifeq ($(ARCH), amd64) + gcloud docker -- push $(IMAGE):$(TAG) +endif + +clean: $(addprefix sub-clean-,$(ALL_ARCH)) + docker rmi -f $(IMAGE):$(TAG) || true +sub-clean-%: + docker rmi -f $(IMAGE)-$*:$(TAG) || true diff --git a/guestbook/redis-slave/Dockerfile b/guestbook/redis-slave/Dockerfile index e90b2258..4dfe3ef2 100644 --- a/guestbook/redis-slave/Dockerfile +++ b/guestbook/redis-slave/Dockerfile @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM redis +FROM redis:3.2.9 -ADD run.sh /run.sh - -RUN chmod a+x /run.sh +COPY run.sh / CMD /run.sh diff --git a/guestbook/redis-slave/Makefile b/guestbook/redis-slave/Makefile new file mode 100644 index 00000000..b3638e62 --- /dev/null +++ b/guestbook/redis-slave/Makefile @@ -0,0 +1,76 @@ +# Copyright 2017 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. + +TAG = v2 +REGISTRY = gcr.io/google-samples +ARCH ?= $(shell go env GOARCH) +ALL_ARCH = amd64 arm arm64 ppc64le + +IMAGE = $(REGISTRY)/gb-redisslave +MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) + +# Set default base image dynamically for each arch +ifeq ($(ARCH),arm) + QEMUARCH=arm + BASEIMAGE=arm32v6/redis:3.2.9-alpine +endif +ifeq ($(ARCH),arm64) + QEMUARCH=aarch64 + BASEIMAGE=arm64v8/redis:3.2.9 +endif +ifeq ($(ARCH),ppc64le) + QEMUARCH=ppc64le + BASEIMAGE=ppc64le/redis:3.2.9 +endif + +TEMP_DIR := $(shell mktemp -d) + +all: all-container + +sub-container-%: + $(MAKE) ARCH=$* container + +sub-push-%: + $(MAKE) ARCH=$* push + +all-container: $(addprefix sub-container-,$(ALL_ARCH)) + +all-push: $(addprefix sub-push-,$(ALL_ARCH)) + +container: .container-$(ARCH) +.container-$(ARCH): + cp ./* $(TEMP_DIR) + +ifneq ($(ARCH), amd64) + cd $(TEMP_DIR) && sed -i "s|FROM redis.*|FROM $(BASEIMAGE)|g" Dockerfile +endif + + docker build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR) + +ifeq ($(ARCH), amd64) + # This is for to maintain the backward compatibility + docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG) +endif + +push: .push-$(ARCH) +.push-$(ARCH): .container-$(ARCH) + gcloud docker -- push $(MULTI_ARCH_IMG):$(TAG) +ifeq ($(ARCH), amd64) + gcloud docker -- push $(IMAGE):$(TAG) +endif + +clean: $(addprefix sub-clean-,$(ALL_ARCH)) + docker rmi -f $(IMAGE):$(TAG) || true +sub-clean-%: + docker rmi -f $(IMAGE)-$*:$(TAG) || true