Skip to content

Commit

Permalink
Add multiarch building support
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Lu <bin.lu@arm.com>
  • Loading branch information
Bin Lu committed Jan 25, 2019
1 parent 93f4221 commit 167ac83
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Build node feature discovery
FROM golang:1.8 as builder
FROM BASEIMAGE1 as builder

CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/

ADD . /go/src/sigs.k8s.io/node-feature-discovery

Expand Down Expand Up @@ -32,12 +34,16 @@ RUN go test .


# Create production image for running node feature discovery
FROM debian:stretch-slim
FROM BASEIMAGE2

CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/

COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /usr/local/lib /usr/local/lib
COPY --from=builder /etc/kubernetes/node-feature-discovery /etc/kubernetes/node-feature-discovery
RUN ldconfig
COPY --from=builder /go/bin/node-feature-discovery /usr/bin/node-feature-discovery

RUN rm /usr/bin/qemu-*-static -f

ENTRYPOINT ["/usr/bin/node-feature-discovery"]
72 changes: 70 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
ARCH?=amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x

QEMUVERSION=v2.9.1

.PHONY: all

IMAGE_BUILD_CMD := docker build
Expand All @@ -8,10 +13,73 @@ DOCKER_IMAGE_NAME := node-feature-discovery

VERSION := $(shell git describe --tags --dirty --always)

ifeq ($(ARCH),amd64)
BASEIMAGE1?=golang:1.11-stretch
BASEIMAGE2?=debian:stretch-slim
endif
ifeq ($(ARCH),arm)
BASEIMAGE1?=arm32v7/golang:1.11-stretch
BASEIMAGE2?=arm32v7/debian:stretch-slim
QEMUARCH=arm
endif
ifeq ($(ARCH),arm64)
BASEIMAGE1?=arm64v8/golang:1.11-stretch
BASEIMAGE2?=arm64v8/debian:stretch-slim
QEMUARCH=aarch64
endif
ifeq ($(ARCH),ppc64le)
BASEIMAGE1?=ppc64le/golang:1.11-stretch
BASEIMAGE2?=ppc64le/debian:stretch-slim
QEMUARCH=ppc64le
endif
ifeq ($(ARCH),s390x)
BASEIMAGE1?=s390x/golang:1.11-stretch
BASEIMAGE2?=s390x/debian:stretch-slim
QEMUARCH=s390x
endif

check-docker:
@if [ -z $$(which docker) ]; then \
echo "Missing \`docker\` client which is required for development"; \
exit 2; \
fi

all: image

# To override QUAY_REGISTRY_USER use the -e option as follows:
# QUAY_REGISTRY_USER=<my-username> make docker -e.
image:
image: check-docker
cat Dockerfile \
| sed "s|BASEIMAGE1|$(BASEIMAGE1)|g" \
| sed "s|BASEIMAGE2|$(BASEIMAGE2)|g" \
| sed "s|QEMUARCH|$(QEMUARCH)|g" \
> Dockerfile.build

ifeq ($(ARCH),amd64)
# When building "normally" for amd64, remove the whole line, it has no part in the amd64 image
sed "/CROSS_BUILD_/d" Dockerfile.build > Dockerfile.build.tmp
else
# When cross-building, only the placeholder "CROSS_BUILD_" should be removed
# Register /usr/bin/qemu-ARCH-static as the handler for non-x86 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 ./
# Ensure we don't get surprised by umask settings
chmod 0755 qemu-$(QEMUARCH)-static
sed "s/CROSS_BUILD_//g" Dockerfile.build > Dockerfile.build.tmp
endif

ifeq ($(ARCH),amd64)
$(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \
-t $(QUAY_DOMAIN_NAME)/$(QUAY_REGISTRY_USER)/$(DOCKER_IMAGE_NAME):$(VERSION) -f Dockerfile.build.tmp ./
endif
$(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \
-t $(QUAY_DOMAIN_NAME)/$(QUAY_REGISTRY_USER)/$(DOCKER_IMAGE_NAME):$(VERSION) ./
-t $(QUAY_DOMAIN_NAME)/$(QUAY_REGISTRY_USER)/$(DOCKER_IMAGE_NAME)-$(ARCH):$(VERSION) -f Dockerfile.build.tmp ./

rm Dockerfile.build* -f
rm qemu-*-static -f

# Building multi-arch docker images
images-all: check-docker
for arch in $(ALL_ARCH); do \
$(MAKE) image ARCH=$$arch; \
done

0 comments on commit 167ac83

Please sign in to comment.