Skip to content

Commit 1373086

Browse files
authored
fix: cli version in docker image (#2341)
Add version arg in Dockerfile Build with version in build script add build arg in goreleaser
1 parent 3f183cd commit 1373086

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

.goreleaser.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ dockers:
5555
- cmd
5656
- internal
5757
- .git
58+
build_flag_templates:
59+
- "--build-arg=VERSION={{ .Version }}"
5860

5961
release:
6062
github:

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM golang:1.15-alpine as builder
22

33
ENV BUILD_IN_DOCKER true
4+
ARG VERSION
45

56
# ca-certificates is needed to add the certificates on the next image
67
# since it's FROM scratch, it does not have any certificates

scripts/build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ LDFLAGS=(
1212

1313
# If we are build from the dockerfile only build required binary
1414
if [[ "${BUILD_IN_DOCKER}" == "true" ]]; then
15-
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags "${LDFLAGS[*]}" ./cmd/scw
15+
if [[ "${VERSION}" != "" ]]; then
16+
LDFLAGS+=(-X main.Version="${VERSION}")
17+
fi
18+
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags "${LDFLAGS[*]} " ./cmd/scw
1619
exit 0
1720
fi
1821

0 commit comments

Comments
 (0)