Skip to content

Commit

Permalink
Add multi-arch support for container images. (#885)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mrueg authored Apr 26, 2020
1 parent 2462137 commit 21ea5a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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?=
Expand Down Expand Up @@ -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)"; \
Expand Down

0 comments on commit 21ea5a5

Please sign in to comment.