diff --git a/.travis.yml b/.travis.yml index c4195736b1..da9f5eda0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ services: - docker script: - - docker build -t quay.io/kubernetes_incubator/node-feature-discovery . + - make image diff --git a/Dockerfile b/Dockerfile index 22951132e5..34a5433bd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -10,15 +12,15 @@ ENV CMT_CAT_VERSION="v1.2.0" ARG NFD_VERSION RUN case $(dpkg --print-architecture) in \ - arm64) \ - echo "skip rdt on Arm64 platform" \ - ;; \ - *) \ + amd64) \ git clone --depth 1 -b $CMT_CAT_VERSION https://github.com/intel/intel-cmt-cat.git && \ make -C intel-cmt-cat/lib install && \ make -C rdt-discovery && \ make -C rdt-discovery install \ ;; \ + *) \ + echo "skip rdt on non-amd64 platform" \ + ;; \ esac RUN go get github.com/Masterminds/glide @@ -32,7 +34,9 @@ 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 @@ -40,4 +44,6 @@ COPY --from=builder /etc/kubernetes/node-feature-discovery /etc/kubernetes/node- 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"] diff --git a/Makefile b/Makefile index 2e92839600..e75fc41523 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,8 @@ +ARCH?=amd64 +ALL_ARCH = amd64 arm arm64 ppc64le s390x + +QEMUVERSION=v2.9.1 + .PHONY: all IMAGE_BUILD_CMD := docker build @@ -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= 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