From a0abbc3071452c829e19fcb2433dcf10f8e1a4c7 Mon Sep 17 00:00:00 2001 From: elij Date: Tue, 12 Dec 2023 10:27:31 -0800 Subject: [PATCH] add VERSION and GITHASH metadata to docker image --- .github/workflows/publish-docker.yml | 12 +++++++++--- .github/workflows/publish-github.yml | 9 ++++++++- examples/Dockerfile | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index e0137fc8..040afc27 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -37,11 +37,17 @@ jobs: - name: Build Container if: success() + env: + DOCKER_BUILDKIT: 1 run: | TAG=$(git describe --tags) - docker build -f examples/Dockerfile -t cactus4docker/go-camo:${TAG} . - # also tag as latest? - # docker tag cactus4docker/go-camo:${TAG} cactus4docker/go-camo:latest + GITHASH="$(git rev-parse HEAD)" + docker build \ + --build-arg GITHASH=${GITHASH} \ + --build-arg VERSION=${TAG} \ + -f examples/Dockerfile \ + -t cactus4docker/go-camo:${TAG} \ + . - name: Publish Container if: success() diff --git a/.github/workflows/publish-github.yml b/.github/workflows/publish-github.yml index bdd940f0..3480309c 100644 --- a/.github/workflows/publish-github.yml +++ b/.github/workflows/publish-github.yml @@ -8,6 +8,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + DOCKER_BUILDKIT: 1 jobs: build: @@ -43,7 +44,13 @@ jobs: if: success() run: | TAG=$(git describe --tags) - docker build -f examples/Dockerfile -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG} . + GITHASH="$(git rev-parse HEAD)" + docker build \ + --build-arg GITHASH=${GITHASH} \ + --build-arg VERSION=${TAG} \ + -f examples/Dockerfile \ + -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${TAG} \ + . - name: Publish Container if: success() diff --git a/examples/Dockerfile b/examples/Dockerfile index 168f8b37..e342133e 100644 --- a/examples/Dockerfile +++ b/examples/Dockerfile @@ -1,5 +1,7 @@ FROM alpine:latest RUN apk add --no-cache ca-certificates +ARG GITHASH +ARG VERSION COPY build/bin/* /bin/ EXPOSE 8080/tcp USER nobody