Fix docker build for multi-arch

This commit is contained in:
Ciprian Hacman
2023-09-01 11:37:16 +03:00
parent d8e9d550dc
commit e9922b0da7
2 changed files with 14 additions and 14 deletions

View File

@@ -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