Skip to content

Commit 5873b25

Browse files
authored
Merge pull request #93 from cailloumajor/build-version
fix: set project version in binary when building Docker image
2 parents d3d8bd3 + d3ec41a commit 5873b25

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

Diff for: .github/workflows/release.yml

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
- name: Build and push
3131
uses: docker/build-push-action@v6
3232
with:
33+
build-args: |
34+
PROJECT_VERSION=${{ steps.meta.outputs.version }}
3335
platforms: linux/amd64,linux/arm64
3436
push: true
3537
tags: ${{ steps.meta.outputs.tags }}

Diff for: Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ COPY go.mod go.sum *.go ./
1212
COPY cmd ./cmd
1313
COPY internal ./internal
1414

15+
ARG PROJECT_VERSION
16+
RUN test -n "${PROJECT_VERSION}"
17+
1518
ARG TARGETPLATFORM
1619
ENV CGO_ENABLED=0
17-
RUN xx-go build -o bin/ -v ./... && \
20+
RUN xx-go build -ldflags "-X main.projectVersion=${PROJECT_VERSION}" -o bin/ -v ./... && \
1821
xx-verify bin/*
1922

2023
# hadolint ignore=DL3006

Diff for: integration/docker-compose.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ services:
99
- ./docker-tests.sh:/usr/local/bin/docker-tests.sh:ro
1010

1111
docker-socket-proxy:
12-
build: ..
12+
build:
13+
context: ..
14+
args:
15+
- PROJECT_VERSION=integration-tests
1316
command:
1417
- /usr/local/bin/docker-socket-proxy
1518
- -api-listen

Diff for: integration/smoke_test.sh

+7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export DOCKER_SOCKET_GID
4949
# Start the service
5050
docker compose up -d --build --quiet-pull docker-socket-proxy
5151

52+
# Check that version was set at build.
53+
got=$(docker compose exec docker-socket-proxy /usr/local/bin/docker-socket-proxy -version)
54+
expected="docker-socket-proxy version integration-tests"
55+
if [ "$got" != "$expected" ]; then
56+
die "unexpected version information, expected \"$expected\", got \"$got\""
57+
fi
58+
5259
# Wait for the service to be ready
5360
max_attempts=5
5461
wait_success=

0 commit comments

Comments
 (0)