mirror of
https://github.com/pushbits/server.git
synced 2025-04-28 17:56:50 +02:00
Read binary version using BuildInfo
This commit is contained in:
parent
c13ebca593
commit
b2e0275917
3 changed files with 9 additions and 16 deletions
|
@ -1,7 +1,5 @@
|
||||||
FROM docker.io/library/golang:alpine as builder
|
FROM docker.io/library/golang:alpine as builder
|
||||||
|
|
||||||
ARG PB_BUILD_VERSION
|
|
||||||
|
|
||||||
ARG CLI_VERSION=0.0.6
|
ARG CLI_VERSION=0.0.6
|
||||||
ARG CLI_PLATFORM=linux_amd64
|
ARG CLI_PLATFORM=linux_amd64
|
||||||
|
|
||||||
|
@ -13,7 +11,7 @@ RUN set -ex \
|
||||||
&& apk add --no-cache build-base ca-certificates curl \
|
&& apk add --no-cache build-base ca-certificates curl \
|
||||||
&& go mod download \
|
&& go mod download \
|
||||||
&& go mod verify \
|
&& go mod verify \
|
||||||
&& PB_BUILD_VERSION="$PB_BUILD_VERSION" make build \
|
&& make build \
|
||||||
&& chmod +x /build/out/pushbits \
|
&& chmod +x /build/out/pushbits \
|
||||||
&& 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 \
|
&& 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 \
|
||||||
&& tar -C /usr/local/bin -xvf /tmp/pbcli_${CLI_VERSION}.tar.gz pbcli \
|
&& tar -C /usr/local/bin -xvf /tmp/pbcli_${CLI_VERSION}.tar.gz pbcli \
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -5,15 +5,10 @@ TESTS_DIR := ./tests
|
||||||
GO_FILES := $(shell find . -type f \( -iname '*.go' \))
|
GO_FILES := $(shell find . -type f \( -iname '*.go' \))
|
||||||
GO_MODULE := github.com/pushbits/server
|
GO_MODULE := github.com/pushbits/server
|
||||||
|
|
||||||
PB_BUILD_VERSION ?= $(shell git describe --tags)
|
|
||||||
ifeq ($(PB_BUILD_VERSION),)
|
|
||||||
_ := $(error Cannot determine build version)
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
mkdir -p $(OUT_DIR)
|
mkdir -p $(OUT_DIR)
|
||||||
go build -ldflags="-w -s -X main.version=$(PB_BUILD_VERSION)" -o $(OUT_DIR)/pushbits ./cmd/pushbits
|
go build -ldflags="-w -s" -o $(OUT_DIR)/pushbits ./cmd/pushbits
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
|
@ -63,7 +58,6 @@ swag: build
|
||||||
.PHONY: docker_build_dev
|
.PHONY: docker_build_dev
|
||||||
docker_build_dev:
|
docker_build_dev:
|
||||||
podman build \
|
podman build \
|
||||||
--build-arg=PB_BUILD_VERSION=dev \
|
|
||||||
-t local/pushbits .
|
-t local/pushbits .
|
||||||
|
|
||||||
.PHONY: run_postgres_debug
|
.PHONY: run_postgres_debug
|
||||||
|
|
|
@ -4,6 +4,7 @@ package main
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"runtime/debug"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/pushbits/server/internal/authentication/credentials"
|
"github.com/pushbits/server/internal/authentication/credentials"
|
||||||
|
@ -15,8 +16,6 @@ import (
|
||||||
"github.com/pushbits/server/internal/runner"
|
"github.com/pushbits/server/internal/runner"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version string
|
|
||||||
|
|
||||||
func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
|
func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
|
||||||
c := make(chan os.Signal, 2)
|
c := make(chan os.Signal, 2)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
|
@ -30,11 +29,13 @@ func setupCleanup(db *database.Database, dp *dispatcher.Dispatcher) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func printStarupMessage() {
|
func printStarupMessage() {
|
||||||
if len(version) == 0 {
|
buildInfo, ok := debug.ReadBuildInfo()
|
||||||
log.L.Panic("Version not set")
|
if !ok {
|
||||||
} else {
|
log.L.Fatalln("Build info not available")
|
||||||
log.L.Printf("Starting PushBits %s", version)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.L.Printf("Starting PushBits %s", buildInfo.Main.Version)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @title PushBits Server API Documentation
|
// @title PushBits Server API Documentation
|
||||||
|
|
Loading…
Add table
Reference in a new issue