Skip to content

Commit b2e0275

Browse files
committed
Read binary version using BuildInfo
1 parent c13ebca commit b2e0275

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
FROM docker.io/library/golang:alpine as builder
22

3-
ARG PB_BUILD_VERSION
4-
53
ARG CLI_VERSION=0.0.6
64
ARG CLI_PLATFORM=linux_amd64
75

@@ -13,7 +11,7 @@ RUN set -ex \
1311
&& apk add --no-cache build-base ca-certificates curl \
1412
&& go mod download \
1513
&& go mod verify \
16-
&& PB_BUILD_VERSION="$PB_BUILD_VERSION" make build \
14+
&& make build \
1715
&& chmod +x /build/out/pushbits \
1816
&& curl -q -s -S -L -o /tmp/pbcli_${CLI_VERSION}.tar.gz https://github.com/pushbits/cli/releases/download/v${CLI_VERSION}/pbcli_${CLI_VERSION}_${CLI_PLATFORM}.tar.gz \
1917
&& tar -C /usr/local/bin -xvf /tmp/pbcli_${CLI_VERSION}.tar.gz pbcli \

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,10 @@ TESTS_DIR := ./tests
55
GO_FILES := $(shell find . -type f \( -iname '*.go' \))
66
GO_MODULE := github.com/pushbits/server
77

8-
PB_BUILD_VERSION ?= $(shell git describe --tags)
9-
ifeq ($(PB_BUILD_VERSION),)
10-
_ := $(error Cannot determine build version)
11-
endif
12-
138
.PHONY: build
149
build:
1510
mkdir -p $(OUT_DIR)
16-
go build -ldflags="-w -s -X main.version=$(PB_BUILD_VERSION)" -o $(OUT_DIR)/pushbits ./cmd/pushbits
11+
go build -ldflags="-w -s" -o $(OUT_DIR)/pushbits ./cmd/pushbits
1712

1813
.PHONY: clean
1914
clean:
@@ -63,7 +58,6 @@ swag: build
6358
.PHONY: docker_build_dev
6459
docker_build_dev:
6560
podman build \
66-
--build-arg=PB_BUILD_VERSION=dev \
6761
-t local/pushbits .
6862

6963
.PHONY: run_postgres_debug

cmd/pushbits/main.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44
import (
55
"os"
66
"os/signal"
7+
"runtime/debug"
78
"syscall"
89

910
"github.com/pushbits/server/internal/authentication/credentials"
@@ -15,8 +16,6 @@ import (
1516
"github.com/pushbits/server/internal/runner"
1617
)
1718

18-
var version string
19-
2019
func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
2120
c := make(chan os.Signal, 2)
2221
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
@@ -30,11 +29,13 @@ func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
3029
}
3130

3231
func printStarupMessage() {
33-
if len(version) == 0 {
34-
log.L.Panic("Version not set")
35-
} else {
36-
log.L.Printf("Starting PushBits %s", version)
32+
buildInfo, ok := debug.ReadBuildInfo()
33+
if !ok {
34+
log.L.Fatalln("Build info not available")
35+
return
3736
}
37+
38+
log.L.Printf("Starting PushBits %s", buildInfo.Main.Version)
3839
}
3940

4041
// @title PushBits Server API Documentation

0 commit comments

Comments
 (0)