diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index c1b44ef..2a312fc 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -31,6 +31,18 @@ jobs: uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1 with: images: ctferio/ctfd-setup + + - name: Git commit date + id: infos + run: | + # trim version prefix + version=${{ github.ref_name }} + version="${version#"v"}" + echo "version=$version" >> "$GITHUB_OUTPUT" + + # output date per RFC 3339 + date="$(git log -1 --format=%cd --date=format:%Y-%m-%dT%H:%M:%SZ)" + echo "date=$date" >> "$GITHUB_OUTPUT" - name: Build and push Docker image uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 @@ -40,6 +52,14 @@ jobs: sbom: true # may not produce SBOM in manifest if the image has no filesystem (e.g. "FROM scratch") tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: | + VERSION=$VERSION + COMMIT=$COMMIT + COMMIT_DATE=$COMMIT_DATE + env: + VERSION: ${{ steps.infos.outputs.version }} + COMMIT: ${{ github.sha }} + COMMIT_DATE: ${{ steps.infos.outputs.date }} # This step calls the container workflow to generate provenance and push it to # the container registry. diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 27d2a14..d7ca07e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -37,7 +37,6 @@ jobs: args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - VERSION_LDFLAGS: ${{ steps.ldflags.outputs.version }} - name: Generate subject id: hash diff --git a/Dockerfile b/Dockerfile index e0a04d3..14f2276 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,13 @@ RUN go mod download COPY . . ENV CGO_ENABLED=0 -RUN go build -cover -o /go/bin/ctfd-setup cmd/ctfd-setup/main.go +ARG VERSION="dev" +ARG COMMIT +ARG COMMIT_DATE +RUN go build -cover \ + -ldflags="-s -w -X 'main.Version="$VERSION"' -X 'main.Commit="$COMMIT"' -X 'main.CommitDate="$COMMIT_DATE"'" \ + -o /go/bin/ctfd-setup \ + cmd/ctfd-setup/main.go diff --git a/cmd/ctfd-setup/main.go b/cmd/ctfd-setup/main.go index b9ded69..1b0d39c 100644 --- a/cmd/ctfd-setup/main.go +++ b/cmd/ctfd-setup/main.go @@ -18,7 +18,6 @@ var ( Version = "dev" Commit = "" CommitDate = "" - TreeState = "" ) const ( @@ -437,10 +436,9 @@ func main() { }, Version: Version, Metadata: map[string]any{ - "version": Version, - "commit": Commit, - "date": CommitDate, - "treeState": TreeState, + "version": Version, + "commit": Commit, + "date": CommitDate, }, }