From 304a68334e7f74dcf963fbc2a9c8d213daa32809 Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Fri, 3 Dec 2021 17:42:03 +0000 Subject: [PATCH] ci/cd: build for arm64 arch Signed-off-by: Ramkumar Chinchani --- .github/workflows/ci-cd.yml | 17 +++++++++++++++++ Dockerfile | 2 +- Dockerfile-arch | 33 +++++++++++++++++++++++++++++++++ Dockerfile-arch-minimal | 33 +++++++++++++++++++++++++++++++++ Dockerfile-conformance | 2 +- Dockerfile-minimal | 2 +- Makefile | 10 ++++++---- 7 files changed, 92 insertions(+), 7 deletions(-) create mode 100644 Dockerfile-arch create mode 100644 Dockerfile-arch-minimal diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 6e58981b..5e879b31 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -91,3 +91,20 @@ jobs: tags: | ghcr.io/${{ github.repository }}-minimal:${{ github.event.release.tag_name }} ghcr.io/${{ github.repository }}-minimal:latest + - name: Build container image (arm64) + uses: docker/build-push-action@v2 + with: + build-args: ARCH=arm64 + push: true + tags: | + ghcr.io/${{ github.repository }}-arm64:${{ github.event.release.tag_name }} + ghcr.io/${{ github.repository }}-arm64:latest + - name: Build minimal container image (arm64) + uses: docker/build-push-action@v2 + with: + build-args: ARCH=arm64 + push: true + file: Dockerfile-minimal + tags: | + ghcr.io/${{ github.repository }}-arm64-minimal:${{ github.event.release.tag_name }} + ghcr.io/${{ github.repository }}-arm64-minimal:latest diff --git a/Dockerfile b/Dockerfile index 1e9a368d..a5130e68 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ FROM docker.io/golang:1.16 AS builder RUN mkdir -p /go/src/github.com/anuvu/zot WORKDIR /go/src/github.com/anuvu/zot COPY . . -RUN CGO_ENABLED=0 make clean binary +RUN make clean binary RUN echo '{\n\ "storage": {\n\ "rootDirectory": "/var/lib/registry"\n\ diff --git a/Dockerfile-arch b/Dockerfile-arch new file mode 100644 index 00000000..b03f9258 --- /dev/null +++ b/Dockerfile-arch @@ -0,0 +1,33 @@ +# --- +# Stage 1: Install certs, build binary, create default config file +# --- +FROM docker.io/golang:1.16 AS builder +ARG ARCH +RUN mkdir -p /go/src/github.com/anuvu/zot +WORKDIR /go/src/github.com/anuvu/zot +COPY . . +RUN make ARCH=$ARCH clean binary +RUN echo '{\n\ + "storage": {\n\ + "rootDirectory": "/var/lib/registry"\n\ + },\n\ + "http": {\n\ + "address": "0.0.0.0",\n\ + "port": "5000"\n\ + },\n\ + "log": {\n\ + "level": "debug"\n\ + }\n\ +}\n' > config.json && cat config.json + +# --- +# Stage 2: Final image with nothing but certs, binary, and default config file +# --- +FROM scratch AS final +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /go/src/github.com/anuvu/zot/bin/zot /usr/bin/zot +COPY --from=builder /go/src/github.com/anuvu/zot/config.json /etc/zot/config.json +ENTRYPOINT ["/usr/bin/zot"] +EXPOSE 5000 +VOLUME ["/var/lib/registry"] +CMD ["serve", "/etc/zot/config.json"] diff --git a/Dockerfile-arch-minimal b/Dockerfile-arch-minimal new file mode 100644 index 00000000..a6d17f68 --- /dev/null +++ b/Dockerfile-arch-minimal @@ -0,0 +1,33 @@ +# --- +# Stage 1: Install certs, build binary, create default config file +# --- +FROM docker.io/golang:1.16 AS builder +ARG ARCH +RUN mkdir -p /go/src/github.com/anuvu/zot +WORKDIR /go/src/github.com/anuvu/zot +COPY . . +RUN make ARCH=$ARCH clean binary-minimal +RUN echo '{\n\ + "storage": {\n\ + "rootDirectory": "/var/lib/registry"\n\ + },\n\ + "http": {\n\ + "address": "0.0.0.0",\n\ + "port": "5000"\n\ + },\n\ + "log": {\n\ + "level": "debug"\n\ + }\n\ +}\n' > config.json && cat config.json + +# --- +# Stage 2: Final image with nothing but certs, binary, and default config file +# --- +FROM scratch AS final +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /go/src/github.com/anuvu/zot/bin/zot-minimal /usr/bin/zot +COPY --from=builder /go/src/github.com/anuvu/zot/config.json /etc/zot/config.json +ENTRYPOINT ["/usr/bin/zot"] +EXPOSE 5000 +VOLUME ["/var/lib/registry"] +CMD ["serve", "/etc/zot/config.json"] diff --git a/Dockerfile-conformance b/Dockerfile-conformance index 77db89c7..37df0009 100644 --- a/Dockerfile-conformance +++ b/Dockerfile-conformance @@ -6,7 +6,7 @@ RUN apk --update add git make ca-certificates RUN mkdir -p /go/src/github.com/anuvu/zot WORKDIR /go/src/github.com/anuvu/zot COPY . . -RUN CGO_ENABLED=0 make clean binary +RUN make clean binary RUN echo -e '# Default config file for zot server\n\ http:\n\ address: 0.0.0.0\n\ diff --git a/Dockerfile-minimal b/Dockerfile-minimal index c29929b8..eb191517 100644 --- a/Dockerfile-minimal +++ b/Dockerfile-minimal @@ -5,7 +5,7 @@ FROM docker.io/golang:1.16 AS builder RUN mkdir -p /go/src/github.com/anuvu/zot WORKDIR /go/src/github.com/anuvu/zot COPY . . -RUN CGO_ENABLED=0 make clean binary-minimal +RUN make clean binary-minimal RUN echo '{\n\ "storage": {\n\ "rootDirectory": "/var/lib/registry"\n\ diff --git a/Makefile b/Makefile index 3813afc6..95e996e2 100644 --- a/Makefile +++ b/Makefile @@ -7,25 +7,27 @@ CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker) PATH := bin:$(PATH) TMPDIR := $(shell mktemp -d) STACKER := $(shell which stacker) +OS ?= linux +ARCH ?= amd64 .PHONY: all all: swagger binary binary-minimal exporter-minimal debug test test-clean check .PHONY: binary-minimal binary-minimal: swagger - go build -o bin/zot-minimal -tags minimal,containers_image_openpgp -v -trimpath -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=minimal -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-minimal -tags minimal,containers_image_openpgp -v -trimpath -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=minimal -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot .PHONY: binary binary: swagger - go build -o bin/zot -tags extended,containers_image_openpgp -v -trimpath -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=extended -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot -tags extended,containers_image_openpgp -v -trimpath -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=extended -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION} -s -w" ./cmd/zot .PHONY: debug debug: swagger - go build -o bin/zot-debug -tags extended,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=extended -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-debug -tags extended,containers_image_openpgp -v -gcflags all='-N -l' -ldflags "-X github.com/anuvu/zot/pkg/api/config.Commit=${COMMIT} -X github.com/anuvu/zot/pkg/api/config.BinaryType=extended -X github.com/anuvu/zot/pkg/api/config.GoVersion=${GO_VERSION}" ./cmd/zot .PHONY: exporter-minimal exporter-minimal: swagger - go build -o bin/zot-exporter -tags minimal,containers_image_openpgp -v -trimpath ./cmd/exporter + env CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) go build -o bin/zot-exporter -tags minimal,containers_image_openpgp -v -trimpath ./cmd/exporter .PHONY: test test: