From fc4a34d43a2c24508a87a16b2bdf6e6e630b4eae Mon Sep 17 00:00:00 2001 From: Ramkumar Chinchani Date: Wed, 15 Dec 2021 22:47:53 +0000 Subject: [PATCH] ci/cd: include tag name in release docker builds Signed-off-by: Ramkumar Chinchani --- .github/workflows/ci-cd.yml | 12 ++++++++++-- Dockerfile | 3 ++- Dockerfile-arch | 3 ++- Dockerfile-arch-minimal | 3 ++- Dockerfile-conformance | 3 ++- Dockerfile-minimal | 3 ++- Makefile | 2 +- 7 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 3a15885e..792402fc 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -81,6 +81,8 @@ jobs: - name: Build container image uses: docker/build-push-action@v2 with: + build-args: | + COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} push: true tags: | ghcr.io/${{ github.repository }}:${{ github.event.release.tag_name }} @@ -88,6 +90,8 @@ jobs: - name: Build minimal container image uses: docker/build-push-action@v2 with: + build-args: | + COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} push: true file: Dockerfile-minimal tags: | @@ -96,7 +100,9 @@ jobs: - name: Build container image (arm64) uses: docker/build-push-action@v2 with: - build-args: ARCH=arm64 + build-args: | + COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} + ARCH=arm64 push: true file: Dockerfile-arch tags: | @@ -105,7 +111,9 @@ jobs: - name: Build minimal container image (arm64) uses: docker/build-push-action@v2 with: - build-args: ARCH=arm64 + build-args: | + COMMIT=${{ github.event.release.tag_name }}-${{ github.sha }} + ARCH=arm64 push: true file: Dockerfile-arch-minimal tags: | diff --git a/Dockerfile b/Dockerfile index 007081ad..b4c93eab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,11 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM docker.io/golang:1.16 AS builder +ARG COMMIT RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . -RUN make clean binary +RUN make COMMIT=$COMMIT clean binary RUN echo '{\n\ "storage": {\n\ "rootDirectory": "/var/lib/registry"\n\ diff --git a/Dockerfile-arch b/Dockerfile-arch index 17b192bd..bcbb8275 100644 --- a/Dockerfile-arch +++ b/Dockerfile-arch @@ -2,11 +2,12 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM docker.io/golang:1.16 AS builder +ARG COMMIT ARG ARCH RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . -RUN make ARCH=$ARCH clean binary +RUN make COMMIT=$COMMIT ARCH=$ARCH clean binary RUN echo '{\n\ "storage": {\n\ "rootDirectory": "/var/lib/registry"\n\ diff --git a/Dockerfile-arch-minimal b/Dockerfile-arch-minimal index 13b993c2..d1c6d324 100644 --- a/Dockerfile-arch-minimal +++ b/Dockerfile-arch-minimal @@ -2,11 +2,12 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM docker.io/golang:1.16 AS builder +ARG COMMIT ARG ARCH RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . -RUN make ARCH=$ARCH clean binary-minimal +RUN make COMMIT=$COMMIT ARCH=$ARCH clean binary-minimal RUN echo '{\n\ "storage": {\n\ "rootDirectory": "/var/lib/registry"\n\ diff --git a/Dockerfile-conformance b/Dockerfile-conformance index 0b3660a1..6d54006a 100644 --- a/Dockerfile-conformance +++ b/Dockerfile-conformance @@ -2,11 +2,12 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM docker.io/golang:1.16-alpine AS builder +ARG COMMIT RUN apk --update add 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 clean binary +RUN make COMMIT=$COMMIT 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 e0b674f2..d39a9b91 100644 --- a/Dockerfile-minimal +++ b/Dockerfile-minimal @@ -2,10 +2,11 @@ # Stage 1: Install certs, build binary, create default config file # --- FROM docker.io/golang:1.16 AS builder +ARG COMMIT RUN mkdir -p /go/src/github.com/project-zot/zot WORKDIR /go/src/github.com/project-zot/zot COPY . . -RUN make clean binary-minimal +RUN make COMMIT=$COMMIT clean binary-minimal RUN echo '{\n\ "storage": {\n\ "rootDirectory": "/var/lib/registry"\n\ diff --git a/Makefile b/Makefile index bdaf6698..2a4bf719 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ export GO111MODULE=on TOP_LEVEL=$(shell git rev-parse --show-toplevel) COMMIT_HASH=$(shell git describe --always --tags --long) GO_VERSION=$(shell go version | awk '{print $$3}') -COMMIT=$(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH)) +COMMIT ?= $(if $(shell git status --porcelain --untracked-files=no),$(COMMIT_HASH)-dirty,$(COMMIT_HASH)) CONTAINER_RUNTIME := $(shell command -v podman 2> /dev/null || echo docker) PATH := bin:$(PATH) TMPDIR := $(shell mktemp -d)