Create multi-arch image

For linux arm64 and amd64, as per #586.

I moved the builder image into the same dockerfile, and bumped the Go
version on it. It didn't seem like the builder dockerfile worked with
the latest code anyway (the go modules require go 1.15 and higher).

This requires a recent enough docker install with buildx, as well as
an arm64 builder.

BASEIMAGE is changed to not specify an arch, so that the image will
build on its native arch in buildx.

Example image is on docker hub as:

    kelvie/node-problem-detector:v0.8.10-5-gb0fa610
This commit is contained in:
Kelvie Wong
2022-02-13 01:23:31 -08:00
parent e7fe0b20dc
commit 363d01392a
3 changed files with 29 additions and 33 deletions
+10 -5
View File
@@ -23,6 +23,7 @@ all: build
# PLATFORMS is the set of OS_ARCH that NPD can build against.
LINUX_PLATFORMS=linux_amd64 linux_arm64
DOCKER_PLATFORMS=linux/amd64,linux/arm64
PLATFORMS=$(LINUX_PLATFORMS) windows_amd64
# VERSION is the version of the binary.
@@ -74,7 +75,7 @@ endif
# The debian-base:v1.0.0 image built from kubernetes repository is based on
# Debian Stretch. It includes systemd 232 with support for both +XZ and +LZ4
# compression. +LZ4 is needed on some os distros such as COS.
BASEIMAGE:=k8s.gcr.io/debian-base-amd64:v2.0.0
BASEIMAGE:=k8s.gcr.io/debian-base:v2.0.0
# Disable cgo by default to make the binary statically linked.
CGO_ENABLED:=0
@@ -239,8 +240,8 @@ $(NPD_NAME_VERSION)-%.tar.gz: $(ALL_BINARIES) test/e2e-install.sh
build-binaries: $(ALL_BINARIES)
build-container: build-binaries Dockerfile
docker build -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
build-container: clean Dockerfile
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
tar -zcvf $(TARBALL) bin/ config/ test/e2e-install.sh test/bin/problem-maker
@@ -252,7 +253,7 @@ build-tar: $(TARBALL) $(ALL_TARBALLS)
build: build-container build-tar
docker-builder:
docker build -t npd-builder ./builder
docker build -t npd-builder . --target=builder
build-in-docker: clean docker-builder
docker run \
@@ -260,8 +261,12 @@ build-in-docker: clean docker-builder
-c 'cd /gopath/src/k8s.io/node-problem-detector/ && make build-binaries'
push-container: build-container
# So we can push to docker hub by setting REGISTRY
ifneq (,$(findstring gcr.io,$(REGISTRY)))
gcloud auth configure-docker
docker push $(IMAGE)
endif
# Build should be cached from build-container
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
push-tar: build-tar
gsutil cp $(TARBALL) $(UPLOAD_PATH)/node-problem-detector/