Add multi-arch support for container images. (#885)

* Add multi-arch support for container images

Currently we have a arch-specific binary that gets installed on an amd64
container. This change ensures that the container image matches the
arch-specific binary.

Using alpine archictecture-specific images as  mentioned under
https://hub.docker.com/_/alpine

To support architectures different from host architecture, this uses
qemu-static.

* Lint Dockerfile

Use COPY instead of ADD
https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy
This commit is contained in:
Manuel Rüger 2020-04-26 12:10:20 +02:00 committed by GitHub
parent 2462137563
commit 21ea5a5abe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 11 deletions

View File

@ -14,11 +14,11 @@ RUN apk add --no-cache \
curl -L -o /usr/local/share/bash-completion/bash-completion \
https://raw.githubusercontent.com/scop/bash-completion/master/bash_completion
ADD build/image-assets/bashrc /root/.bashrc
ADD build/image-assets/profile /root/.profile
ADD build/image-assets/vimrc /root/.vimrc
ADD build/image-assets/motd-kube-router.sh /etc/motd-kube-router.sh
ADD kube-router gobgp /usr/local/bin/
COPY build/image-assets/bashrc /root/.bashrc
COPY build/image-assets/profile /root/.profile
COPY build/image-assets/vimrc /root/.vimrc
COPY build/image-assets/motd-kube-router.sh /etc/motd-kube-router.sh
COPY kube-router gobgp /usr/local/bin/
WORKDIR "/root"
WORKDIR /root
ENTRYPOINT ["/usr/local/bin/kube-router"]

View File

@ -18,22 +18,23 @@ MAKEFILE_DIR=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
UPSTREAM_IMPORT_PATH=$(GOPATH)/src/github.com/cloudnativelabs/kube-router/
BUILD_IN_DOCKER?=true
DOCKER_BUILD_IMAGE?=golang:1.10.8-alpine3.9
QEMU_IMAGE?=multiarch/qemu-user-static
ifeq ($(GOARCH), arm)
ARCH_TAG_PREFIX=$(GOARCH)
FILE_ARCH=ARM
DOCKERFILE_SED_EXPR?=
DOCKERFILE_SED_EXPR?=s,FROM alpine,FROM arm32v6/alpine,
else ifeq ($(GOARCH), arm64)
ARCH_TAG_PREFIX=$(GOARCH)
FILE_ARCH=ARM aarch64
DOCKERFILE_SED_EXPR?=
DOCKERFILE_SED_EXPR?=s,FROM alpine,FROM arm64v8/alpine,
else ifeq ($(GOARCH), s390x)
ARCH_TAG_PREFIX=$(GOARCH)
FILE_ARCH=IBM S/390
DOCKERFILE_SED_EXPR?=
DOCKERFILE_SED_EXPR?=s,FROM alpine,FROM s390x/alpine,
else ifeq ($(GOARCH), ppc64le)
ARCH_TAG_PREFIX=$(GOARCH)
FILE_ARCH=64-bit PowerPC
DOCKERFILE_SED_EXPR?=
DOCKERFILE_SED_EXPR?=s,FROM alpine,FROM ppc64le/alpine,
else
ARCH_TAG_PREFIX=amd64
DOCKERFILE_SED_EXPR?=
@ -91,7 +92,11 @@ run: kube-router ## Runs "kube-router --help".
./kube-router --help
container: Dockerfile.$(GOARCH).run kube-router gobgp multiarch-binverify ## Builds a Docker container image.
@echo Starting kube-router container image build.
@echo Starting kube-router container image build for $(GOARCH) on $(shell go env GOHOSTARCH)
@if [ "$(GOARCH)" != "$(shell go env GOHOSTARCH)" ]; then \
echo "Using qemu to build non-native container"; \
$(DOCKER) run --rm --privileged $(QEMU_IMAGE) --reset -p yes; \
fi
$(DOCKER) build -t "$(REGISTRY_DEV):$(IMG_TAG)" -f Dockerfile.$(GOARCH).run .
@if [ "$(GIT_BRANCH)" = "master" ]; then \
$(DOCKER) tag "$(REGISTRY_DEV):$(IMG_TAG)" "$(REGISTRY_DEV)"; \