diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eb36c6e..d58ae38 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -523,6 +523,10 @@ jobs: - name: Checkout code uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Set build date + id: build_date + run: echo "date=$(date -u +%Y-%m-%d)" >> $GITHUB_OUTPUT + - name: Set up Docker Buildx uses: docker/setup-buildx-action@d7f5e7f509e45cec5c76c4d5afdd7de93d0b3df5 # v4.1.0 @@ -552,6 +556,10 @@ jobs: push: true tags: ${{ steps.meta-service.outputs.tags }} labels: ${{ steps.meta-service.outputs.labels }} + build-args: | + VERSION=v${{ needs.validate.outputs.version }} + COMMIT=${{ github.sha }} + DATE=${{ steps.build_date.outputs.date }} cache-from: type=gha cache-to: type=gha,mode=max @@ -574,6 +582,10 @@ jobs: push: true tags: ${{ steps.meta-web.outputs.tags }} labels: ${{ steps.meta-web.outputs.labels }} + build-args: | + VERSION=v${{ needs.validate.outputs.version }} + COMMIT=${{ github.sha }} + DATE=${{ steps.build_date.outputs.date }} cache-from: type=gha cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile index 0d46ed3..26762d3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,12 @@ ARG TARGETARCH ARG TARGETOS ARG TARGETVARIANT +# Version info injected at build time; defaults keep local builds working. +# The release workflow passes VERSION, COMMIT, and DATE via --build-arg. +ARG VERSION=dev +ARG COMMIT=unknown +ARG DATE=unknown + WORKDIR /app # Copy go mod and sum files @@ -19,16 +25,24 @@ COPY . . # Build the soundtouch-service RUN if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \ - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} go build -o /soundtouch-service ./cmd/soundtouch-service; \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} \ + go build -trimpath -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ + -o /soundtouch-service ./cmd/soundtouch-service; \ else \ - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /soundtouch-service ./cmd/soundtouch-service; \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ + -o /soundtouch-service ./cmd/soundtouch-service; \ fi # Build the soundtouch-web RUN if [ "${TARGETARCH}" = "arm" ] && [ -n "${TARGETVARIANT}" ]; then \ - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} go build -o /soundtouch-web ./cmd/soundtouch-web; \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GOARM=${TARGETVARIANT#v} \ + go build -trimpath -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ + -o /soundtouch-web ./cmd/soundtouch-web; \ else \ - CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /soundtouch-web ./cmd/soundtouch-web; \ + CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -trimpath -ldflags="-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" \ + -o /soundtouch-web ./cmd/soundtouch-web; \ fi # soundtouch-service image