Skip to content

Commit e04737b

Browse files
committed
Adds version information to the software:
- adds version flag which is printed on startup - adds build information (version, commit hash) to grpc server info structure
1 parent 2b40e6c commit e04737b

16 files changed

+443
-59
lines changed

.github/workflows/build.yml

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ jobs:
4343
cache-to: type=gha,mode=max
4444
tags: ${{ steps.meta.outputs.tags }}
4545
labels: ${{ steps.meta.outputs.labels }}
46+
build-args: |
47+
VERSION=${{ github.head_ref }}
48+
COMMIT=${{ github.sha }}
4649
4750
- name: Inspect Docker image
4851
run: docker image inspect ${{ steps.meta.outputs.tags }}

.github/workflows/publish.yml

+3
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ jobs:
5454
cache-to: type=gha,mode=max
5555
tags: ${{ steps.meta.outputs.tags }}
5656
labels: ${{ steps.meta.outputs.labels }}
57+
build-args: |
58+
VERSION=${{ github.head_ref }}
59+
COMMIT=${{ github.sha }}

Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ FROM golang:1.20.5-alpine as server
1212
RUN apk add --no-cache gcc musl-dev
1313
WORKDIR /code
1414
ENV CGO_ENABLED=1
15+
ARG VERSION=development
16+
ARG COMMIT="-"
1517
COPY ./go.mod ./
1618
COPY ./go.sum ./
1719
RUN go mod download
@@ -21,6 +23,9 @@ COPY ./main.go ./main.go
2123
COPY ./cmd/ ./cmd/
2224
COPY ./pkg/ ./pkg/
2325
COPY ./internal/ ./internal/
26+
COPY ./buildinfo/ ./buildinfo/
27+
RUN echo "Using: Version: ${VERSION}, Commit: ${COMMIT}"
28+
RUN go generate buildinfo/buildinfo.go
2429
RUN go build -o wg-access-server
2530

2631
### Server

buildinfo/buildinfo.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package buildinfo
2+
3+
import (
4+
"strings"
5+
_ "embed"
6+
)
7+
8+
//go:generate sh get_version.sh
9+
//go:embed version.txt
10+
var VersionRaw string
11+
12+
//go:generate sh get_commit.sh
13+
//go:embed commit.txt
14+
var CommitHashRaw string
15+
16+
func Version() string {
17+
return strings.TrimSpace(VersionRaw)
18+
}
19+
20+
func CommitHash() string {
21+
return strings.TrimSpace(CommitHashRaw)
22+
}
23+
24+
func ShortCommitHash() string {
25+
if 7 < len(CommitHash()) {
26+
return CommitHash()[0:7]
27+
}
28+
return CommitHash()
29+
}

buildinfo/commit.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-

buildinfo/get_commit.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
if [ -z "${COMMIT}" ]; then
3+
echo "-" > commit.txt
4+
else
5+
echo "${COMMIT}" > commit.txt
6+
fi

buildinfo/get_version.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
if [ -z "$VERSION" ] ; then
3+
echo "development" > version.txt
4+
else
5+
echo "${VERSION}" > version.txt
6+
fi

buildinfo/version.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
development

cmd/serve/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/freifunkMUC/wg-access-server/internal/storage"
3434
"github.com/freifunkMUC/wg-access-server/pkg/authnz"
3535
"github.com/freifunkMUC/wg-access-server/pkg/authnz/authconfig"
36+
"github.com/freifunkMUC/wg-access-server/buildinfo"
3637
)
3738

3839
func Register(app *kingpin.Application) *servecmd {
@@ -80,6 +81,9 @@ func (cmd *servecmd) Name() string {
8081
func (cmd *servecmd) Run() {
8182
conf := cmd.ReadConfig()
8283

84+
// Software banner
85+
logrus.Infof("+++ wg-access-server %s (%s)", buildinfo.Version(), buildinfo.ShortCommitHash())
86+
8387
// Get the server's IP addresses within the VPN
8488
var vpnip, vpnipv6 netip.Prefix
8589
var err error
@@ -125,7 +129,7 @@ func (cmd *servecmd) Run() {
125129
defer wgimpl.Close()
126130
wg = wgimpl
127131

128-
logrus.Infof("Starting WireGuard server on :%d", conf.WireGuard.Port)
132+
logrus.Infof("Starting WireGuard on :%d", conf.WireGuard.Port)
129133

130134
wgconfig := &wgembed.ConfigFile{
131135
Interface: wgembed.IfaceConfig{

internal/services/server_service.go

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/freifunkMUC/wg-access-server/internal/network"
1414
"github.com/freifunkMUC/wg-access-server/pkg/authnz/authsession"
1515
"github.com/freifunkMUC/wg-access-server/proto/proto"
16+
"github.com/freifunkMUC/wg-access-server/buildinfo"
1617
)
1718

1819
type ServerService struct {
@@ -73,6 +74,7 @@ func (s *ServerService) Info(ctx context.Context, req *proto.InfoReq) (*proto.In
7374
ClientConfigDnsServers: clientConfigDnsServers(s.Config),
7475
ClientConfigDnsSearchDomain: s.Config.ClientConfig.DNSSearchDomain,
7576
ClientConfigMtu: int32(s.Config.ClientConfig.MTU),
77+
BuildInfo: &proto.BuildInfo{Version: buildinfo.Version(), Commit: buildinfo.ShortCommitHash()},
7678
}, nil
7779
}
7880

proto/buildinfo.proto

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
syntax = "proto3";
2+
3+
package proto;
4+
5+
option go_package = "github.com/freifunkMUC/wg-access-server/proto/proto";
6+
7+
message BuildInfo {
8+
string version = 1;
9+
string commit = 2;
10+
}

proto/proto/buildinfo.pb.go

+154
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)