Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: add multiarch building support #203

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
# Get qemu-user-static
ARG IMAGEARCH
FROM alpine:3.9.2 as qemu
RUN apk add --no-cache curl
ARG QEMUVERSION=2.9.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QEMU version needs to be update

Suggested change
ARG QEMUVERSION=2.9.1
ARG QEMUVERSION=4.1.1-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
FROM ${IMAGEARCH}golang:1.12.7-stretch as builder
ENV GO_FLAGS=${GO_FLAGS:-"-tags netgo"}

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 curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
RUN dep ensure -v
RUN go install \
-ldflags "-s -w -X sigs.k8s.io/node-feature-discovery/pkg/version.version=$NFD_VERSION" \
Expand All @@ -16,9 +32,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
40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,53 @@ KUBECONFIG :=
yaml_templates := $(wildcard *.yaml.template)
yaml_instances := $(patsubst %.yaml.template,%.yaml,$(yaml_templates))

ARCH ?= amd64
ALL_ARCH = amd64 arm64

IMAGEARCH ?=
QEMUARCH ?=

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

ifeq ($(ARCH),amd64)
IMAGEARCH =
QEMUARCH = x86_64
else ifeq ($(ARCH),arm)
IMAGEARCH = arm32v7/
QEMUARCH = arm
else ifeq ($(ARCH),arm64)
IMAGEARCH = arm64v8/
QEMUARCH = aarch64
else ifeq ($(ARCH),ppc64le)
IMAGEARCH = ppc64le/
QEMUARCH = ppc64le
else ifeq ($(ARCH),s390x)
IMAGEARCH = s390x/
QEMUARCH = s390x
else
$(error unknown arch "$(ARCH)")
endif

all: image

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

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

# Building multi-arch docker images
images-all: pre-cross
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think pre-cross should be listed as a phony target, or, removed from here. With the former, we always would run pre-cross when building images-all which prolly is ok

for arch in $(ALL_ARCH); do \
$(MAKE) image ARCH=$$arch; \
done

yamls: $(yaml_instances)

%.yaml: %.yaml.template .FORCE
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,19 @@ cd <project-root>
make
```

**Build non-amd64 image on amd64:**<br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: this just looks a bit clumsy heading 😄

How about Multiarch builds or Build for target architectures or smth? If AMD64 is mentioned I think it should be capital case.

Optional, for example.
```
cd <project-root>
docker run --rm --privileged multiarch/qemu-user-static:register --reset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would make pre-cross be better?

make image ARCH=arm64
```
Or, you can build all supported amd64/non-amd64 images together.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest Or, you can build all supported architectures with one command: or similar, drop the amd64 here...

```
cd <project-root>
make images-all
```

**Push the container image:**<br>
Optional, this example with Docker.

Expand Down
3 changes: 1 addition & 2 deletions source/cpu/pstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
func turboEnabled() (bool, error) {
// On Arm platform, the frequency boost mechanism is software-based.
// So skip pstate detection on Arm.
switch runtime.GOARCH {
case "arm64":
if runtime.GOARCH != "amd64" {
return false, nil
}

Expand Down