Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create multi-arch image #684

Merged
merged 2 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"

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}
Expand All @@ -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"]
17 changes: 12 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -239,8 +240,9 @@ $(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 create --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
tar -zcvf $(TARBALL) bin/ config/ test/e2e-install.sh test/bin/problem-maker
Expand All @@ -252,16 +254,21 @@ 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 \
-v `pwd`:/gopath/src/k8s.io/node-problem-detector/ npd-builder:latest bash \
-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 create --use
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/
Expand Down
25 changes: 0 additions & 25 deletions builder/Dockerfile

This file was deleted.