Skip to content

Commit bd3ce08

Browse files
authored
build(docker): fix binary versions in image (#1062)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 52c11f8 commit bd3ce08

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

.github/workflows/publish.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ jobs:
170170
platforms: linux/${{ matrix.arch }}
171171
tags: ${{ steps.meta.outputs.tags }}
172172
labels: ${{ steps.meta.outputs.labels }}
173+
build-args: |
174+
VERSION=${{ github.ref_type == 'tag' && github.ref_name || '' }}
175+
COMMIT_HASH=${{ github.sha }}
173176
- name: Attest Docker Hub image
174177
uses: actions/attest-build-provenance@977bb373ede98d70efdf65b84cb5f73e068dcc2a # v3.0.0 https://github.com/actions/attest-build-provenance/releases/tag/v3.0.0
175178
with:

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
FROM ghcr.io/blinklabs-io/go:1.25.4-1 AS build
22

3+
ARG VERSION
4+
ARG COMMIT_HASH
5+
ENV VERSION=${VERSION}
6+
ENV COMMIT_HASH=${COMMIT_HASH}
7+
38
WORKDIR /code
49
RUN go env -w GOCACHE=/go-cache
510
RUN go env -w GOMODCACHE=/gomod-cache

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ BINARIES=$(shell cd $(ROOT_DIR)/cmd && ls -1 | grep -v ^common)
1010
# Extract Go module name from go.mod
1111
GOMODULE=$(shell grep ^module $(ROOT_DIR)/go.mod | awk '{ print $$2 }')
1212

13-
# Set version strings based on git tag and current ref
14-
GO_LDFLAGS=-ldflags "-s -w -X '$(GOMODULE)/internal/version.Version=$(shell git describe --tags --exact-match 2>/dev/null)' -X '$(GOMODULE)/internal/version.CommitHash=$(shell git rev-parse --short HEAD)'"
13+
# Set version strings: use env vars if set, else git
14+
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null)
15+
COMMIT_HASH ?= $(shell git rev-parse --short HEAD)
16+
GO_LDFLAGS=-ldflags "-s -w -X '$(GOMODULE)/internal/version.Version=$(VERSION)' -X '$(GOMODULE)/internal/version.CommitHash=$(COMMIT_HASH)'"
1517

1618
.PHONY: all build mod-tidy clean format golines test bench test-load-profile
1719

1820
# Default target
19-
all: build test bench
21+
all: format golines build test
2022

2123
# Build target
2224
build: $(BINARIES)

0 commit comments

Comments
 (0)