diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index 5070f60..80881ab 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -37,3 +37,5 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + build-args: + VERSION: ${{ steps.meta.outputs.version }} diff --git a/Dockerfile b/Dockerfile index 338fe2c..26160d4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/main.go b/main.go index 580884b..344276e 100644 --- a/main.go +++ b/main.go @@ -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)) }