Multi arch nginx-slim docker image

Signed-off-by: Manjunath A Kumatagi <mkumatag@in.ibm.com>
This commit is contained in:
Manjunath A Kumatagi 2017-04-11 19:19:15 +05:30
parent 6ed6475e87
commit 172f7548d4
6 changed files with 152 additions and 15 deletions

View file

@ -1,22 +1,79 @@
# 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.
all: push
TAG ?= 0.8
PREFIX ?= gcr.io/google-containers/ubuntu-slim
TAG ?= 0.9
REGISTRY = gcr.io/google_containers
ARCH ?= $(shell go env GOARCH)
QEMUVERSION=v2.7.0
IMGNAME = ubuntu-slim
IMAGE = $(REGISTRY)/$(IMGNAME)
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
BUILD_IMAGE ?= ubuntu-build
TAR_FILE ?= rootfs.tar
PUSH_TOOL ?= gcloud
# Set default base image dynamically for each arch
ifeq ($(ARCH),amd64)
BASEIMAGE?=ubuntu:16.04
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE?=ppc64le/ubuntu:16.04
QEMUARCH=ppc64le
endif
TEMP_DIR := $(shell mktemp -d)
container: clean
docker build --pull -t $(BUILD_IMAGE) -f Dockerfile.build .
cp ./* $(TEMP_DIR)
cd $(TEMP_DIR) && sed -i 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile.build
cd $(TEMP_DIR) && sed -i "s|ARCH|$(QEMUARCH)|g" Dockerfile.build
ifeq ($(ARCH),amd64)
# When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
cd $(TEMP_DIR) && sed -i "/CROSS_BUILD_/d" Dockerfile.build
else
# When cross-building, only the placeholder "CROSS_BUILD_" should be removed
# 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)
cd $(TEMP_DIR) && sed -i "s/CROSS_BUILD_//g" Dockerfile.build
endif
docker build --pull -t $(BUILD_IMAGE) -f $(TEMP_DIR)/Dockerfile.build $(TEMP_DIR)
docker create --name $(BUILD_IMAGE) $(BUILD_IMAGE)
docker export $(BUILD_IMAGE) > $(TAR_FILE)
docker build --pull -t $(PREFIX):$(TAG) .
cp rootfs.tar $(TEMP_DIR)
docker build --pull -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: container
$(PUSH_TOOL) docker -- push $(PREFIX):$(TAG)
$(PUSH_TOOL) docker -- push $(MULTI_ARCH_IMG):$(TAG)
ifeq ($(ARCH),amd64)
$(PUSH_TOOL) docker -- push $(IMAGE):$(TAG)
endif
clean:
docker rmi -f $(PREFIX):$(TAG) || true
docker rmi -f $(IMAGE):$(TAG) || true
docker rmi -f $(BUILD_IMAGE) || true
docker rm -f $(BUILD_IMAGE) || true
rm -f $(TAR_FILE)