Skip to content

Commit 2d5de8d

Browse files
authored
Merge pull request #684 from acumino/multi-arch-image
Create multi-arch image
2 parents c9ffa67 + 04e8d00 commit 2d5de8d

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-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 systemd
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: 12 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,9 @@ $(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 create --use
245+
docker buildx build --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
244246

245247
$(TARBALL): ./bin/node-problem-detector ./bin/log-counter ./bin/health-checker ./test/bin/problem-maker
246248
tar -zcvf $(TARBALL) bin/ config/ test/e2e-install.sh test/bin/problem-maker
@@ -252,16 +254,21 @@ build-tar: $(TARBALL) $(ALL_TARBALLS)
252254
build: build-container build-tar
253255

254256
docker-builder:
255-
docker build -t npd-builder ./builder
257+
docker build -t npd-builder . --target=builder
256258

257259
build-in-docker: clean docker-builder
258260
docker run \
259261
-v `pwd`:/gopath/src/k8s.io/node-problem-detector/ npd-builder:latest bash \
260262
-c 'cd /gopath/src/k8s.io/node-problem-detector/ && make build-binaries'
261263

262264
push-container: build-container
265+
# So we can push to docker hub by setting REGISTRY
266+
ifneq (,$(findstring gcr.io,$(REGISTRY)))
263267
gcloud auth configure-docker
264-
docker push $(IMAGE)
268+
endif
269+
# Build should be cached from build-container
270+
docker buildx create --use
271+
docker buildx build --push --platform $(DOCKER_PLATFORMS) -t $(IMAGE) --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg LOGCOUNTER=$(LOGCOUNTER) .
265272

266273
push-tar: build-tar
267274
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)