File tree Expand file tree Collapse file tree 3 files changed +10
-5
lines changed
Expand file tree Collapse file tree 3 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -62,12 +62,13 @@ jobs:
6262 - name : 编译二进制文件
6363 run : |
6464 cd src
65+ VERSION=${{ steps.version.outputs.version }}
6566
6667 # Linux AMD64
67- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-amd64 .
68+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.Version=${VERSION} " -o ../build/hubproxy/hubproxy-linux-amd64 .
6869
6970 # Linux ARM64
70- CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" -o ../build/hubproxy/hubproxy-linux-arm64 .
71+ CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.Version=${VERSION} " -o ../build/hubproxy/hubproxy-linux-arm64 .
7172
7273 # 压缩二进制文件
7374 upx -9 ../build/hubproxy/hubproxy-linux-amd64
Original file line number Diff line number Diff line change 11FROM golang:1.25-alpine AS builder
22
33ARG TARGETARCH
4+ ARG VERSION=dev
45
56WORKDIR /app
67COPY src/go.mod src/go.sum ./
78RUN go mod download && apk add upx
89
910COPY src/ .
1011
11- RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-s -w" -trimpath -o hubproxy . && upx -9 hubproxy
12+ RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -ldflags="-s -w -X main.Version=${VERSION} " -trimpath -o hubproxy . && upx -9 hubproxy
1213
1314FROM alpine
1415
@@ -17,4 +18,4 @@ WORKDIR /root/
1718COPY --from=builder /app/hubproxy .
1819COPY --from=builder /app/config.toml .
1920
20- CMD ["./hubproxy" ]
21+ CMD ["./hubproxy" ]
Original file line number Diff line number Diff line change 4040 serviceStartTime = time .Now ()
4141)
4242
43+ var Version = "dev"
44+
4345func buildRouter (cfg * config.AppConfig ) * gin.Engine {
4446 gin .SetMode (gin .ReleaseMode )
4547 router := gin .Default ()
@@ -148,7 +150,7 @@ func main() {
148150 fmt .Printf ("H2c: 已启用\n " )
149151 }
150152
151- fmt .Printf ("版本号: v1.2.1 \n " )
153+ fmt .Printf ("版本号: %s \n " , Version )
152154 fmt .Printf ("项目地址: https://github.com/sky22333/hubproxy\n " )
153155
154156 // 创建HTTP2服务器
@@ -205,6 +207,7 @@ func initHealthRoutes(router *gin.Engine) {
205207 c .JSON (http .StatusOK , gin.H {
206208 "ready" : true ,
207209 "service" : "hubproxy" ,
210+ "version" : Version ,
208211 "start_time_unix" : serviceStartTime .Unix (),
209212 "uptime_sec" : uptimeSec ,
210213 "uptime_human" : uptimeHuman ,
You can’t perform that action at this time.
0 commit comments