From 962b7cb12bb53926d27787c21d7bcc1c7afc81c9 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Mon, 25 Sep 2023 19:01:49 +0000 Subject: [PATCH] build: fix container image targets Use stacker to build OCI image. Use podman/docker to build docker image. Signed-off-by: Ramkumar Chinchani --- Makefile | 10 +++++----- build/Dockerfile-conformance | 6 ++++++ build/Dockerfile-minimal | 10 ++++++---- build/Dockerfile-zb | 10 ++++++---- build/Dockerfile-zxp | 10 ++++++---- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 8bcc63ee59..f2ef779f95 100644 --- a/Makefile +++ b/Makefile @@ -338,8 +338,8 @@ run-container: ${CONTAINER_RUNTIME} run --rm --security-opt label=disable -v $$(pwd):/go/src/github.com/project-zot/zot \ zot-build:latest -.PHONY: binary-stacker -binary-stacker: $(STACKER) +.PHONY: oci-image +oci-image: $(STACKER) ${STACKER} --debug build \ -f build/stacker.yaml \ --substitute COMMIT=$(COMMIT) \ @@ -348,9 +348,9 @@ binary-stacker: $(STACKER) --substitute RELEASE_TAG=$(RELEASE_TAG) \ --substitute REPO_NAME=zot-$(OS)-$(ARCH) -.PHONY: image -image: - ${CONTAINER_RUNTIME} build ${BUILD_ARGS} -f build/Dockerfile -t zot:latest . +.PHONY: docker-image +docker-image: + ${CONTAINER_RUNTIME} buildx build --platform $(OS)/$(ARCH) -f build/Dockerfile . $(BATS): rm -rf bats-core; \ diff --git a/build/Dockerfile-conformance b/build/Dockerfile-conformance index e0e7f10bed..d5bde3ce62 100644 --- a/build/Dockerfile-conformance +++ b/build/Dockerfile-conformance @@ -2,7 +2,11 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM ghcr.io/project-zot/golang:1.20 AS builder + +ARG TARGETOS +ARG TARGETARCH ARG COMMIT + RUN apt-get update && apt-get install -y git make ca-certificates RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot @@ -21,6 +25,8 @@ storage:\n\ # Stage 2: Final image with nothing but certs, binary, and default config file # --- FROM gcr.io/distroless/base AS final +ARG TARGETOS +ARG TARGETARCH COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /go/src/github.com/project-zot/zot/bin/zot-linux-amd64 /usr/bin/zot COPY --from=builder /go/src/github.com/project-zot/zot/config.yml /etc/zot/config.yml diff --git a/build/Dockerfile-minimal b/build/Dockerfile-minimal index e963068341..0ad4e2e099 100644 --- a/build/Dockerfile-minimal +++ b/build/Dockerfile-minimal @@ -2,9 +2,11 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM ghcr.io/project-zot/golang:1.20 AS builder + +ARG TARGETOS +ARG TARGETARCH ARG COMMIT -ARG OS -ARG ARCH + RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . @@ -26,8 +28,8 @@ RUN echo '{\n\ # Stage 2: Final image with nothing but certs, binary, and default config file # --- FROM gcr.io/distroless/base AS final -ARG OS -ARG ARCH +ARG TARGETOS +ARG TARGETARCH COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt COPY --from=builder /go/src/github.com/project-zot/zot/bin/zot-$OS-$ARCH-minimal /usr/bin/zot COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zot/config.json diff --git a/build/Dockerfile-zb b/build/Dockerfile-zb index 33b6454f8f..21cce595b0 100644 --- a/build/Dockerfile-zb +++ b/build/Dockerfile-zb @@ -2,9 +2,11 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM ghcr.io/project-zot/golang:1.20 AS builder + +ARG TARGETOS +ARG TARGETARCH ARG COMMIT -ARG OS -ARG ARCH + RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . @@ -14,7 +16,7 @@ RUN make COMMIT=$COMMIT OS=$OS ARCH=$ARCH clean bench # Stage 2: Final image with nothing but certs, binary, and default config file # --- FROM gcr.io/distroless/base AS final -ARG OS -ARG ARCH +ARG TARGETOS +ARG TARGETARCH COPY --from=builder /go/src/github.com/project-zot/zot/bin/zb-$OS-$ARCH /usr/bin/zb ENTRYPOINT ["/usr/bin/zb"] diff --git a/build/Dockerfile-zxp b/build/Dockerfile-zxp index d9b2f91f37..7105fb2d81 100644 --- a/build/Dockerfile-zxp +++ b/build/Dockerfile-zxp @@ -2,9 +2,11 @@ # Stage 1: Build binary, create default config file # --- FROM ghcr.io/project-zot/golang:1.20 AS builder + +ARG TARGETOS +ARG TARGETARCH ARG COMMIT -ARG OS -ARG ARCH + RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . @@ -27,8 +29,8 @@ RUN echo '{\n\ # Stage 2: Final image with nothing but binary and default config file # --- FROM gcr.io/distroless/base AS final -ARG OS -ARG ARCH +ARG TARGETOS +ARG TARGETARCH COPY --from=builder /go/src/github.com/project-zot/zot/bin/zxp-$OS-$ARCH /zxp COPY --from=builder /go/src/github.com/project-zot/zot/config.json /etc/zxp/config.json ENTRYPOINT ["/zxp"]