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 <[email protected]>
  • Loading branch information
Bin Lu committed May 23, 2019
1 parent c9d84ea commit 61a6c6f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ services:
- docker

script:
- docker build -t quay.io/kubernetes_incubator/node-feature-discovery .
- make image
21 changes: 17 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# Get qemu-user-static
FROM alpine:3.9.2 as qemu
RUN apk add --no-cache curl
ARG QEMUVERSION=2.9.1
ARG QEMUARCH

SHELL ["/bin/ash", "-o", "pipefail", "-c"]

RUN curl -fsSL https://github.com/multiarch/qemu-user-static/releases/download/v${QEMUVERSION}/qemu-${QEMUARCH}-static.tar.gz | tar zxvf - -C /usr/bin
RUN chmod +x /usr/bin/qemu-*

# Build node feature discovery
FROM golang:1.10 as builder
ARG IMAGEARCH
FROM ${IMAGEARCH}golang:1.11-stretch as builder

ARG QEMUARCH
COPY --from=qemu /usr/bin/qemu-${QEMUARCH}-static /usr/bin/

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

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

ARG NFD_VERSION

RUN go get github.com/golang/dep/cmd/dep
RUN dep ensure -v
RUN go install \
Expand All @@ -16,9 +30,8 @@ RUN install -D -m644 nfd-worker.conf.example /etc/kubernetes/node-feature-discov

RUN make test


# Create production image for running node feature discovery
FROM debian:stretch-slim
FROM ${IMAGEARCH}debian:stretch-slim

# Use more verbose logging of gRPC
ENV GRPC_GO_LOG_SEVERITY_LEVEL="INFO"
Expand Down
37 changes: 37 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x

.PHONY: all test

IMAGE_BUILD_CMD := docker build

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

IMAGEARCH ?=
QEMUARCH ?= x86_64

ifeq ($(ARCH),arm)
IMAGEARCH = arm32v7/
QEMUARCH = arm
endif
ifeq ($(ARCH),arm64)
IMAGEARCH = arm64v8/
QEMUARCH = aarch64
endif
ifeq ($(ARCH),ppc64le)
IMAGEARCH = ppc64le/
QEMUARCH = ppc64le
endif
ifeq ($(ARCH),s390x)
IMAGEARCH = s390x/
QEMUARCH = s390x
endif

IMAGE_REGISTRY := quay.io/kubernetes_incubator
IMAGE_NAME := node-feature-discovery
IMAGE_TAG_NAME := $(VERSION)
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)

ifneq ($(ARCH),amd64)
IMAGE_TAG = $(IMAGE_REPO)-$(ARCH):$(IMAGE_TAG_NAME)
endif

all: image

image:
$(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \
--build-arg IMAGEARCH=$(IMAGEARCH) \
--build-arg QEMUARCH=$(QEMUARCH) \
-t $(IMAGE_TAG) ./

pre-cross:
docker run --rm --privileged multiarch/qemu-user-static:register --reset

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

mock:
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"
Expand Down

0 comments on commit 61a6c6f

Please sign in to comment.