Include the version in the initial log output

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2023-07-30 13:51:16 +01:00
parent bfe1115cb5
commit 15625050c7
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78
3 changed files with 6 additions and 2 deletions

View File

@ -37,3 +37,5 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args:
VERSION: ${{ steps.meta.outputs.version }}

View File

@ -4,6 +4,7 @@ ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
ARG VERSION="dev"
RUN apk update && apk add -U --no-cache ca-certificates
@ -12,7 +13,7 @@ ADD go.mod go.sum ./
RUN go mod download
ADD main.go .
ADD pkg/ ./pkg
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s" -o tailscale-exporter main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags="-w -s -X 'main.Version=${VERSION}'" -o tailscale-exporter main.go
FROM --platform=${TARGETPLATFORM:-linux/amd64} scratch
WORKDIR /app/

View File

@ -11,6 +11,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var Version = "dev"
var addr string
func init() {
@ -32,7 +33,7 @@ func main() {
metrics.Collect(client, reg)
http.Handle("/metrics", promhttp.HandlerFor(reg, promhttp.HandlerOpts{Registry: reg}))
log.Printf("tailscale-exporter")
log.Printf("tailscale-exporter - %s", Version)
log.Printf("Listening on %s", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}