Skip to content

Commit 363d013

Browse files
committed
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
1 parent e7fe0b2 commit 363d013

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

Dockerfile

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,22 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
ARG BASEIMAGE
15+
16+
FROM golang:1.17.7 as builder
17+
LABEL maintainer="Andy Xie <[email protected]>"
18+
19+
ENV GOPATH /gopath/
20+
ENV PATH $GOPATH/bin:$PATH
21+
22+
RUN apt-get update && apt-get --yes install libsystemd-dev
23+
RUN go version
24+
RUN go get github.com/tools/godep
25+
RUN godep version
26+
27+
COPY . /gopath/src/k8s.io/node-problem-detector/
28+
WORKDIR /gopath/src/k8s.io/node-problem-detector
29+
RUN make bin/node-problem-detector bin/health-checker bin/log-counter
1430

1531
ARG BASEIMAGE
1632
FROM ${BASEIMAGE}
@@ -22,10 +38,10 @@ RUN clean-install util-linux libsystemd0 bash
2238
# Avoid symlink of /etc/localtime.
2339
RUN test -h /etc/localtime && rm -f /etc/localtime && cp /usr/share/zoneinfo/UTC /etc/localtime || true
2440

25-
COPY ./bin/node-problem-detector /node-problem-detector
41+
COPY --from=builder /gopath/src/k8s.io/node-problem-detector/bin/node-problem-detector /node-problem-detector
2642

2743
ARG LOGCOUNTER
28-
COPY ./bin/health-checker ${LOGCOUNTER} /home/kubernetes/bin/
44+
COPY --from=builder /gopath/src/k8s.io/node-problem-detector/bin/health-checker /gopath/src/k8s.io/node-problem-detector/${LOGCOUNTER} /home/kubernetes/bin/
2945

30-
COPY config /config
46+
COPY --from=builder /gopath/src/k8s.io/node-problem-detector/config/ /config
3147
ENTRYPOINT ["/node-problem-detector", "--config.system-log-monitor=/config/kernel-monitor.json"]

Makefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ all: build
2323

2424
# PLATFORMS is the set of OS_ARCH that NPD can build against.
2525
LINUX_PLATFORMS=linux_amd64 linux_arm64
26+
DOCKER_PLATFORMS=linux/amd64,linux/arm64
2627
PLATFORMS=$(LINUX_PLATFORMS) windows_amd64
2728

2829
# VERSION is the version of the binary.
@@ -74,7 +75,7 @@ endif
7475
# The debian-base:v1.0.0 image built from kubernetes repository is based on
7576
# Debian Stretch. It includes systemd 232 with support for both +XZ and +LZ4
7677
# compression. +LZ4 is needed on some os distros such as COS.
77-
BASEIMAGE:=k8s.gcr.io/debian-base-amd64:v2.0.0
78+
BASEIMAGE:=k8s.gcr.io/debian-base:v2.0.0
7879

7980
# Disable cgo by default to make the binary statically linked.
8081
CGO_ENABLED:=0
@@ -239,8 +240,8 @@ $(NPD_NAME_VERSION)-%.tar.gz: $(ALL_BINARIES) test/e2e-install.sh
239240

240241
build-binaries: $(ALL_BINARIES)
241242

242-
build-container: build-binaries Dockerfile
243-
docker build -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
243+
build-container: clean Dockerfile
244+
docker buildx build --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
244245

245246
$(TARBALL): ./bin/node-problem-detector ./bin/log-counter ./bin/health-checker ./test/bin/problem-maker
246247
tar -zcvf $(TARBALL) bin/ config/ test/e2e-install.sh test/bin/problem-maker
@@ -252,16 +253,20 @@ build-tar: $(TARBALL) $(ALL_TARBALLS)
252253
build: build-container build-tar
253254

254255
docker-builder:
255-
docker build -t npd-builder ./builder
256+
docker build -t npd-builder . --target=builder
256257

257258
build-in-docker: clean docker-builder
258259
docker run \
259260
-v `pwd`:/gopath/src/k8s.io/node-problem-detector/ npd-builder:latest bash \
260261
-c 'cd /gopath/src/k8s.io/node-problem-detector/ && make build-binaries'
261262

262263
push-container: build-container
264+
# So we can push to docker hub by setting REGISTRY
265+
ifneq (,$(findstring gcr.io,$(REGISTRY)))
263266
gcloud auth configure-docker
264-
docker push $(IMAGE)
267+
endif
268+
# Build should be cached from build-container
269+
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
265270

266271
push-tar: build-tar
267272
gsutil cp $(TARBALL) $(UPLOAD_PATH)/node-problem-detector/

builder/Dockerfile

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)