diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index fec956e..8c32a8d 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -14,16 +14,6 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - - - name: Find Git Tag - id: tagger - uses: jimschubert/query-tag-action@v2 - with: - include: 'v*' - exclude: '*-rc*' - commit-ish: 'HEAD' - skip-unshallow: 'true' - abbrev: 7 - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -59,4 +49,3 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - build-args: 'GIT_DESC=${{steps.tagger.outputs.tag}}' diff --git a/Dockerfile b/Dockerfile index d2d73dc..df7524c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,9 @@ FROM --platform=$BUILDPLATFORM golang:1 AS build -ARG GIT_DESC=undefined - WORKDIR /go/src/github.com/Snawoot/opera-proxy COPY . . ARG TARGETOS TARGETARCH -RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -a -tags netgo -ldflags '-s -w -extldflags "-static" -X main.version='"$GIT_DESC" +RUN GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=0 go build -a -tags netgo -ldflags '-s -w -extldflags "-static"' ADD https://curl.haxx.se/ca/cacert.pem /certs.crt RUN chmod 0644 /certs.crt diff --git a/Makefile b/Makefile index f78fd13..8edcf9e 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,8 @@ PROGNAME = opera-proxy OUTSUFFIX = bin/$(PROGNAME) -VERSION := $(shell git describe) BUILDOPTS = -a -tags netgo -trimpath -asmflags -trimpath -LDFLAGS = -ldflags '-s -w -extldflags "-static" -X main.version=$(VERSION)' -LDFLAGS_NATIVE = -ldflags '-s -w -X main.version=$(VERSION)' +LDFLAGS = -ldflags '-s -w -extldflags "-static"' +LDFLAGS_NATIVE = -ldflags '-s -w' NDK_CC_ARM = $(abspath ../../ndk-toolchain-arm/bin/arm-linux-androideabi-gcc) NDK_CC_ARM64 = $(abspath ../../ndk-toolchain-arm64/bin/aarch64-linux-android21-clang) diff --git a/main.go b/main.go index 07c1a4a..5413a9e 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ import ( "net/http" "net/url" "os" + "runtime/debug" "strconv" "strings" "time" @@ -35,10 +36,6 @@ const ( PROXY_SUFFIX = "sec-tunnel.com" ) -var ( - version = "undefined" -) - func perror(msg string) { fmt.Fprintln(os.Stderr, "") fmt.Fprintln(os.Stderr, msg) @@ -209,7 +206,7 @@ func proxyFromURLWrapper(u *url.URL, next xproxy.Dialer) (xproxy.Dialer, error) func run() int { args := parse_args() if args.showVersion { - fmt.Println(version) + fmt.Println(version()) return 0 } @@ -588,3 +585,11 @@ func retryPolicy(retries int, retryInterval time.Duration, logger *clog.CondLogg return err } } + +func version() string { + bi, ok := debug.ReadBuildInfo() + if !ok { + return "unknown" + } + return bi.Main.Version +}