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 00:12:04 -08:00
parent e7fe0b20dc
commit 363d01392a
3 changed files with 29 additions and 33 deletions

View File

@@ -11,6 +11,22 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ARG BASEIMAGE
FROM golang:1.17.7 as builder
LABEL maintainer="Andy Xie <andy.xning@gmail.com>"
ENV GOPATH /gopath/
ENV PATH $GOPATH/bin:$PATH
RUN apt-get update && apt-get --yes install libsystemd-dev
RUN go version
RUN go get github.com/tools/godep
RUN godep 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
ARG BASEIMAGE
FROM ${BASEIMAGE}
@@ -22,10 +38,10 @@ RUN clean-install util-linux libsystemd0 bash
# Avoid symlink of /etc/localtime.
RUN test -h /etc/localtime && rm -f /etc/localtime && cp /usr/share/zoneinfo/UTC /etc/localtime || true
COPY ./bin/node-problem-detector /node-problem-detector
COPY --from=builder /gopath/src/k8s.io/node-problem-detector/bin/node-problem-detector /node-problem-detector
ARG LOGCOUNTER
COPY ./bin/health-checker ${LOGCOUNTER} /home/kubernetes/bin/
COPY --from=builder /gopath/src/k8s.io/node-problem-detector/bin/health-checker /gopath/src/k8s.io/node-problem-detector/${LOGCOUNTER} /home/kubernetes/bin/
COPY config /config
COPY --from=builder /gopath/src/k8s.io/node-problem-detector/config/ /config
ENTRYPOINT ["/node-problem-detector", "--config.system-log-monitor=/config/kernel-monitor.json"]

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/

View File

@@ -1,25 +0,0 @@
# Copyright 2018 The Kubernetes Authors. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM golang:1.11.0
LABEL maintainer="Andy Xie <andy.xning@gmail.com>"
ENV GOPATH /gopath/
ENV PATH $GOPATH/bin:$PATH
RUN apt-get update && apt-get --yes install libsystemd-dev
RUN go version
RUN go get github.com/tools/godep
RUN godep version
CMD ["/bin/bash"]