Skip to content

Commit

Permalink
build: fix container image targets
Browse files Browse the repository at this point in the history
Use stacker to build OCI image.
Use podman/docker to build docker image.

Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Oct 2, 2023
1 parent 75085dc commit 0ea5a34
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 28 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ make exporter-minimal
## Using container builds (stacker)

```
make binary-stacker
make oci-image
```

## Using container builds (docker)

```
make binary-container
make docker-image
```

# Project Structure
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,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) \
Expand All @@ -364,9 +364,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; \
Expand Down Expand Up @@ -437,7 +437,7 @@ fuzz-all:
bash test/scripts/fuzzAll.sh ${fuzztime}; \
rm -rf pkg/storage/testdata; \

$(STACKER):
$(STACKER): check-linux
mkdir -p $(TOOLSDIR)/bin; \
curl -fsSL https://github.com/project-stacker/stacker/releases/latest/download/stacker -o $@; \
chmod +x $@
Expand Down
10 changes: 8 additions & 2 deletions build/Dockerfile-conformance
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# ---
# Stage 1: Install certs, build binary, create default config file
# ---
FROM ghcr.io/project-zot/golang:1.20 AS builder
FROM --platform=$BUILDPLATFORM 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
COPY . .
RUN make COMMIT=$COMMIT clean binary
RUN make COMMIT=$COMMIT OS=$TARGETOS ARCH=$TARGETARCH clean binary
RUN echo '# Default config file for zot server\n\
http:\n\
address: 0.0.0.0\n\
Expand All @@ -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.yaml /etc/zot/config.yaml
Expand Down
14 changes: 8 additions & 6 deletions build/Dockerfile-minimal
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# ---
# Stage 1: Install certs, build binary, create default config file
# ---
FROM ghcr.io/project-zot/golang:1.20 AS builder
FROM --platform=$BUILDPLATFORM 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 . .
RUN make COMMIT=$COMMIT OS=$OS ARCH=$ARCH clean binary-minimal
RUN make COMMIT=$COMMIT OS=$TARGETOS ARCH=$TARGETARCH clean binary-minimal
RUN echo '{\n\
"storage": {\n\
"rootDirectory": "/var/lib/registry"\n\
Expand All @@ -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
Expand Down
14 changes: 8 additions & 6 deletions build/Dockerfile-zb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# ---
# Stage 1: Install certs, build binary, create default config file
# ---
FROM ghcr.io/project-zot/golang:1.20 AS builder
FROM --platform=$BUILDPLATFORM 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 . .
RUN make COMMIT=$COMMIT OS=$OS ARCH=$ARCH clean bench
RUN make COMMIT=$COMMIT OS=$TARGETOS ARCH=$TARGETARCH 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"]
14 changes: 8 additions & 6 deletions build/Dockerfile-zxp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# ---
# Stage 1: Build binary, create default config file
# ---
FROM ghcr.io/project-zot/golang:1.20 AS builder
FROM --platform=$BUILDPLATFORM 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 . .
RUN make COMMIT=$COMMIT OS=$OS ARCH=$ARCH clean exporter-minimal
RUN make COMMIT=$COMMIT OS=$TARGETOS ARCH=$TARGETARCH clean exporter-minimal
RUN echo '{\n\
"Server": {\n\
"protocol": "http",\n\
Expand All @@ -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"]
Expand Down

0 comments on commit 0ea5a34

Please sign in to comment.