github.com/qsunny/k8s@v0.0.0-20220101153623-e6dca256d5bf/examples-master/guestbook/php-redis/Makefile (about)

     1  # Copyright 2017 The Kubernetes Authors. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  TAG = v6
    16  REGISTRY = gcr.io/google-samples
    17  ARCH ?= $(shell go env GOARCH)
    18  ALL_ARCH = amd64 arm arm64 ppc64le s390x
    19  
    20  QEMUVERSION=v2.9.1
    21  
    22  IMAGE = $(REGISTRY)/gb-frontend
    23  MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
    24  
    25  # Set default base image dynamically for each arch
    26  ifeq ($(ARCH),arm)
    27  	QEMUARCH=arm
    28  	BASEIMAGE=armhf/php:5.6-apache
    29  endif
    30  ifeq ($(ARCH),arm64)
    31  	QEMUARCH=aarch64
    32  	BASEIMAGE=arm64v8/php:5-apache
    33  endif
    34  ifeq ($(ARCH),ppc64le)
    35  	QEMUARCH=ppc64le
    36  	BASEIMAGE=ppc64le/php:5-apache
    37  endif
    38  ifeq ($(ARCH),s390x)
    39          QEMUARCH=s390x
    40          BASEIMAGE=s390x/php:5-apache
    41  endif
    42  TEMP_DIR := $(shell mktemp -d)
    43  
    44  all: all-container
    45  
    46  sub-container-%:
    47  	$(MAKE) ARCH=$* container
    48  
    49  sub-push-%:
    50  	$(MAKE) ARCH=$* push
    51  
    52  all-container: $(addprefix sub-container-,$(ALL_ARCH))
    53  
    54  all-push: $(addprefix sub-push-,$(ALL_ARCH))
    55  	docker manifest create --amend $(IMAGE):$(TAG) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(TAG)~g")
    56  	@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${TAG} ${IMAGE}-$${arch}:${TAG}; done
    57  	docker manifest push --purge ${IMAGE}:${TAG}
    58  
    59  container: .container-$(ARCH)
    60  .container-$(ARCH):
    61  	cp ./* $(TEMP_DIR)
    62  
    63  ifneq ($(ARCH),amd64)
    64  	cd $(TEMP_DIR) && sed -i "s|FROM php.*|FROM $(BASEIMAGE)\nCOPY qemu-$(QEMUARCH)-static /usr/bin\n|g" Dockerfile
    65  	# Register /usr/bin/qemu-ARCH-static as the handler for ARM binaries in the kernel
    66  	docker run --rm --privileged multiarch/qemu-user-static:register --reset
    67  	curl -sSL https://github.com/multiarch/qemu-user-static/releases/download/$(QEMUVERSION)/x86_64_qemu-$(QEMUARCH)-static.tar.gz | tar -xz -C $(TEMP_DIR)
    68  endif
    69  	docker build -t $(MULTI_ARCH_IMG):$(TAG) $(TEMP_DIR)
    70  
    71  ifeq ($(ARCH), amd64)
    72  	# This is for to maintain the backward compatibility
    73  	docker tag $(MULTI_ARCH_IMG):$(TAG) $(IMAGE):$(TAG)
    74  endif
    75  
    76  push: .push-$(ARCH)
    77  .push-$(ARCH): .container-$(ARCH)
    78  	docker push $(MULTI_ARCH_IMG):$(TAG)
    79  
    80  clean: $(addprefix sub-clean-,$(ALL_ARCH))
    81  	docker rmi -f $(IMAGE):$(TAG) || true
    82  sub-clean-%:
    83  	docker rmi -f $(IMAGE)-$*:$(TAG) || true