From f8a310288a2865480cd8169714c208da9f5f6859 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Sun, 20 Mar 2022 01:13:42 +0500 Subject: [PATCH] Provide more metadata with images This assigns the OCI spec labels to images pushed to GHCR, and enables image users to see current tool version instead of just v0+HEAD. --- .github/workflows/docker.yml | 10 ++++++++++ Dockerfile | 13 ++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 21cef48..cb8f8f1 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -43,3 +43,13 @@ jobs: tags: | ghcr.io/${{ github.repository }}:latest ghcr.io/${{ github.repository }}:${{ env.tag_name }} + build-args: | + gmnhg_version=${{ env.tag_name }} + # TODO: set org.opencontainers.image.revision when this gets + # fixed: https://github.com/actions/checkout/issues/209 + labels: | + org.opencontainers.image.url="${{ github.server_url }}/${{ github.repository }}" + org.opencontainers.image.source=${{ github.repositoryUrl }} + org.opencontainers.image.version=${{ env.tag_name }} + org.opencontainers.image.licenses=GPL-3.0 + org.opencontainers.image.title=gmnhg diff --git a/Dockerfile b/Dockerfile index 9c29895..85c4d45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,16 +3,19 @@ FROM docker.io/library/golang:1.18-alpine AS builder WORKDIR /src ENV CGO_ENABLED=0 -ENV GO111MODULE=on -ENV GOFLAGS="-trimpath -ldflags=-linkmode=external" RUN apk add --no-cache git gcc musl-dev COPY . /src/ -RUN \ - go build -v -o /tmp/gmnhg ./cmd/gmnhg && \ - go build -v -o /tmp/md2gmn ./cmd/md2gmn +ARG gmnhg_version=v0+HEAD +RUN go build \ + -v \ + -trimpath \ + -ldflags="-linkmode=external -X main.version=${gmnhg_version}" \ + -o /tmp/ \ + ./cmd/gmnhg \ + ./cmd/md2gmn FROM docker.io/library/alpine:3.15 AS runner