Skip to content

Commit

Permalink
Adds version information to the software:
Browse files Browse the repository at this point in the history
- adds version flag which is printed on startup
- adds build information (version, commit hash) to grpc server info structure
  • Loading branch information
nwaldispuehl committed Jul 15, 2023
1 parent 2b40e6c commit e04737b
Show file tree
Hide file tree
Showing 16 changed files with 443 additions and 59 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ jobs:
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.head_ref }}
COMMIT=${{ github.sha }}
- name: Inspect Docker image
run: docker image inspect ${{ steps.meta.outputs.tags }}
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ jobs:
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.head_ref }}
COMMIT=${{ github.sha }}
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ FROM golang:1.20.5-alpine as server
RUN apk add --no-cache gcc musl-dev
WORKDIR /code
ENV CGO_ENABLED=1
ARG VERSION=development
ARG COMMIT="-"
COPY ./go.mod ./
COPY ./go.sum ./
RUN go mod download
Expand All @@ -21,6 +23,9 @@ COPY ./main.go ./main.go
COPY ./cmd/ ./cmd/
COPY ./pkg/ ./pkg/
COPY ./internal/ ./internal/
COPY ./buildinfo/ ./buildinfo/
RUN echo "Using: Version: ${VERSION}, Commit: ${COMMIT}"
RUN go generate buildinfo/buildinfo.go
RUN go build -o wg-access-server

### Server
Expand Down
29 changes: 29 additions & 0 deletions buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package buildinfo

import (
"strings"
_ "embed"
)

//go:generate sh get_version.sh
//go:embed version.txt
var VersionRaw string

//go:generate sh get_commit.sh
//go:embed commit.txt
var CommitHashRaw string

func Version() string {
return strings.TrimSpace(VersionRaw)
}

func CommitHash() string {
return strings.TrimSpace(CommitHashRaw)
}

func ShortCommitHash() string {
if 7 < len(CommitHash()) {
return CommitHash()[0:7]
}
return CommitHash()
}
1 change: 1 addition & 0 deletions buildinfo/commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-
6 changes: 6 additions & 0 deletions buildinfo/get_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
if [ -z "${COMMIT}" ]; then
echo "-" > commit.txt
else
echo "${COMMIT}" > commit.txt
fi
6 changes: 6 additions & 0 deletions buildinfo/get_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
if [ -z "$VERSION" ] ; then
echo "development" > version.txt
else
echo "${VERSION}" > version.txt
fi
1 change: 1 addition & 0 deletions buildinfo/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
development
6 changes: 5 additions & 1 deletion cmd/serve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/freifunkMUC/wg-access-server/internal/storage"
"github.com/freifunkMUC/wg-access-server/pkg/authnz"
"github.com/freifunkMUC/wg-access-server/pkg/authnz/authconfig"
"github.com/freifunkMUC/wg-access-server/buildinfo"
)

func Register(app *kingpin.Application) *servecmd {
Expand Down Expand Up @@ -80,6 +81,9 @@ func (cmd *servecmd) Name() string {
func (cmd *servecmd) Run() {
conf := cmd.ReadConfig()

// Software banner
logrus.Infof("+++ wg-access-server %s (%s)", buildinfo.Version(), buildinfo.ShortCommitHash())

// Get the server's IP addresses within the VPN
var vpnip, vpnipv6 netip.Prefix
var err error
Expand Down Expand Up @@ -125,7 +129,7 @@ func (cmd *servecmd) Run() {
defer wgimpl.Close()
wg = wgimpl

logrus.Infof("Starting WireGuard server on :%d", conf.WireGuard.Port)
logrus.Infof("Starting WireGuard on :%d", conf.WireGuard.Port)

wgconfig := &wgembed.ConfigFile{
Interface: wgembed.IfaceConfig{
Expand Down
2 changes: 2 additions & 0 deletions internal/services/server_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/freifunkMUC/wg-access-server/internal/network"
"github.com/freifunkMUC/wg-access-server/pkg/authnz/authsession"
"github.com/freifunkMUC/wg-access-server/proto/proto"
"github.com/freifunkMUC/wg-access-server/buildinfo"
)

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

Expand Down
10 changes: 10 additions & 0 deletions proto/buildinfo.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

package proto;

option go_package = "github.com/freifunkMUC/wg-access-server/proto/proto";

message BuildInfo {
string version = 1;
string commit = 2;
}
154 changes: 154 additions & 0 deletions proto/proto/buildinfo.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e04737b

Please sign in to comment.