diff --git a/Dockerfile b/Dockerfile index 4a0d0d13..a96990b6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,9 +13,11 @@ # limitations under the License. ARG BASEIMAGE -FROM golang:1.20.3@sha256:bcc311ec9655c350df3899611fdf134806f97a3e3b2c06c2b5c0696428503814 as builder +FROM golang:1.20.8-bookworm@sha256:81e1690c528627eeb6314f2fbd15964608e6769746459ce9727c77ec988cb28d as builder LABEL maintainer="Andy Xie " +ARG TARGETARCH + ENV GOPATH /gopath/ ENV PATH $GOPATH/bin:$PATH @@ -24,10 +26,10 @@ RUN go version COPY . /gopath/src/k8s.io/node-problem-detector/ WORKDIR /gopath/src/k8s.io/node-problem-detector -RUN make bin/node-problem-detector bin/health-checker bin/log-counter +RUN GOARCH=${TARGETARCH} make bin/node-problem-detector bin/health-checker bin/log-counter ARG BASEIMAGE -FROM ${BASEIMAGE} +FROM --platform=${TARGETPLATFORM} ${BASEIMAGE} LABEL maintainer="Random Liu " diff --git a/Makefile b/Makefile index 275e7738..49bafdd9 100644 --- a/Makefile +++ b/Makefile @@ -71,15 +71,15 @@ else ifeq ($(shell go env GOHOSTOS), windows) ENABLE_JOURNALD=0 endif -# TODO(random-liu): Support different architectures. -# The debian-base:v2.0.0 image built from kubernetes repository is based on -# Debian Stretch. It includes systemd 241 with support for both +XZ and +LZ4 -# compression. +LZ4 is needed on some os distros such as COS. +# Set default base image to Debian 12 (Bookworm) BASEIMAGE:=registry.k8s.io/build-image/debian-base:bookworm-v1.0.0 # Disable cgo by default to make the binary statically linked. CGO_ENABLED:=0 +# Set default Go architecture to AMD64. +GOARCH ?= amd64 + # Construct the "-tags" parameter used by "go build". BUILD_TAGS?= @@ -185,7 +185,7 @@ output/linux_arm64/test/bin/%: $(PKG_SOURCES) # In the future these targets should be deprecated. ./bin/log-counter: $(PKG_SOURCES) ifeq ($(ENABLE_JOURNALD), 1) - CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \ + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) GO111MODULE=on go build \ -mod vendor \ -o bin/log-counter \ -ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \ @@ -196,7 +196,7 @@ else endif ./bin/node-problem-detector: $(PKG_SOURCES) - CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \ + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) GO111MODULE=on go build \ -mod vendor \ -o bin/node-problem-detector \ -ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \ @@ -205,13 +205,13 @@ endif ./test/bin/problem-maker: $(PKG_SOURCES) cd test && \ - CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \ + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) GO111MODULE=on go build \ -o bin/problem-maker \ -tags "$(LINUX_BUILD_TAGS)" \ ./e2e/problemmaker/problem_maker.go ./bin/health-checker: $(PKG_SOURCES) - CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GO111MODULE=on go build \ + CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=$(GOARCH) GO111MODULE=on go build \ -mod vendor \ -o bin/health-checker \ -ldflags '-X $(PKG)/pkg/version.version=$(VERSION)' \ @@ -242,8 +242,7 @@ $(NPD_NAME_VERSION)-%.tar.gz: $(ALL_BINARIES) test/e2e-install.sh build-binaries: $(ALL_BINARIES) build-container: clean Dockerfile - docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - docker buildx create --use + docker buildx create --platform $(DOCKER_PLATFORMS) --use docker buildx build --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) . $(TARBALL): ./bin/node-problem-detector ./bin/log-counter ./bin/health-checker ./test/bin/problem-maker @@ -269,7 +268,6 @@ ifneq (,$(findstring gcr.io,$(REGISTRY))) gcloud auth configure-docker endif # Build should be cached from build-container - docker buildx create --use docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) . push-tar: build-tar