Skip to content

Commit f05aa2f

Browse files
authored
Merge pull request #160 from SenseUnit/buildinfo_ver
Use buildinfo for version
2 parents ff2990c + 7c85410 commit f05aa2f

File tree

4 files changed

+14
-23
lines changed

4 files changed

+14
-23
lines changed

.github/workflows/docker-ci.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ jobs:
2424
uses: actions/checkout@v4
2525
with:
2626
fetch-depth: 0
27-
-
28-
name: Find Git Tag
29-
id: tagger
30-
uses: jimschubert/query-tag-action@v2
31-
with:
32-
include: 'v*'
33-
exclude: '*-rc*'
34-
commit-ish: 'HEAD'
35-
skip-unshallow: 'true'
36-
abbrev: 7
3727
-
3828
name: Set up QEMU
3929
uses: docker/setup-qemu-action@v3
@@ -72,7 +62,6 @@ jobs:
7262
push: true
7363
tags: ${{ steps.scratch_meta.outputs.tags }}
7464
labels: ${{ steps.scratch_meta.outputs.labels }}
75-
build-args: 'GIT_DESC=${{steps.tagger.outputs.tag}}'
7665
-
7766
name: Docker alpine meta
7867
id: alpine_meta
@@ -100,4 +89,3 @@ jobs:
10089
push: true
10190
tags: ${{ steps.alpine_meta.outputs.tags }}
10291
labels: ${{ steps.alpine_meta.outputs.labels }}
103-
build-args: 'GIT_DESC=${{steps.tagger.outputs.tag}}'

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
FROM --platform=$BUILDPLATFORM golang AS build
22

3-
ARG GIT_DESC=undefined
4-
53
WORKDIR /go/src/github.com/SenseUnit/dumbproxy
64
COPY . .
75
ARG TARGETOS TARGETARCH
8-
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -a -tags netgo -ldflags '-s -w -extldflags "-static" -X main.version='"$GIT_DESC"
6+
RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -a -tags netgo -ldflags '-s -w -extldflags "-static"'
97
RUN mkdir /.dumbproxy
108

119
FROM scratch AS scratch

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
PROGNAME = dumbproxy
22
OUTSUFFIX = bin/$(PROGNAME)
3-
VERSION := $(shell git describe)
43
BUILDOPTS = -a -tags netgo -trimpath -asmflags -trimpath
5-
LDFLAGS = -ldflags '-s -w -extldflags "-static" -X main.version=$(VERSION)'
6-
LDFLAGS_NATIVE = -ldflags '-s -w -X main.version=$(VERSION)'
4+
LDFLAGS = -ldflags '-s -w -extldflags "-static"'
5+
LDFLAGS_NATIVE = -ldflags '-s -w'
76

87
NDK_CC_ARM = $(abspath ../../ndk-toolchain-arm/bin/arm-linux-androideabi-gcc)
98
NDK_CC_ARM64 = $(abspath ../../ndk-toolchain-arm64/bin/aarch64-linux-android21-clang)

main.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"os/signal"
2424
"path/filepath"
2525
"runtime"
26+
"runtime/debug"
2627
"strconv"
2728
"strings"
2829
"syscall"
@@ -50,10 +51,7 @@ import (
5051
_ "golang.org/x/crypto/x509roots/fallback"
5152
)
5253

53-
var (
54-
home, _ = os.UserHomeDir()
55-
version = "undefined"
56-
)
54+
var home, _ = os.UserHomeDir()
5755

5856
func perror(msg string) {
5957
fmt.Fprintln(os.Stderr, "")
@@ -480,7 +478,7 @@ func run() int {
480478

481479
// handle special invocation modes
482480
if args.showVersion {
483-
fmt.Println(version)
481+
fmt.Println(version())
484482
return 0
485483
}
486484

@@ -1109,6 +1107,14 @@ func readConfig(filename string) error {
11091107
return nil
11101108
}
11111109

1110+
func version() string {
1111+
bi, ok := debug.ReadBuildInfo()
1112+
if !ok {
1113+
return "unknown"
1114+
}
1115+
return bi.Main.Version
1116+
}
1117+
11121118
func main() {
11131119
os.Exit(run())
11141120
}

0 commit comments

Comments
 (0)