From 93c8179dae2f1b1f484718cf7c42cfd882a8f7c1 Mon Sep 17 00:00:00 2001 From: Marcus Kida Date: Thu, 19 Feb 2026 11:19:47 +0100 Subject: [PATCH] Show deployment version --- Dockerfile | 3 ++- compose.yml | 5 ++++- main.go | 10 ++++++++++ static/app.js | 14 ++++++++++++++ static/index.html | 2 +- static/style.css | 4 ++++ 6 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ea6f28a..0c6f7d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,11 @@ FROM golang:1.25-alpine AS builder +ARG GIT_COMMIT=unknown WORKDIR /build COPY go.mod go.sum ./ RUN go mod download COPY *.go ./ COPY migrations/ ./migrations/ -RUN CGO_ENABLED=0 go build -o dmrmap . +RUN CGO_ENABLED=0 go build -ldflags "-X main.version=${GIT_COMMIT}" -o dmrmap . FROM alpine:3.19 WORKDIR /app diff --git a/compose.yml b/compose.yml index a274412..60d6e77 100644 --- a/compose.yml +++ b/compose.yml @@ -10,7 +10,10 @@ services: restart: unless-stopped dmrmap: - build: . + build: + context: . + args: + GIT_COMMIT: ${GIT_COMMIT:-unknown} depends_on: - postgres environment: diff --git a/main.go b/main.go index da53ec7..df1c856 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,8 @@ import ( "os" ) +var version = "dev" + func main() { dsn := envOr("DATABASE_URL", "postgres://dmrmap:dmrmap@localhost:5432/dmrmap?sslmode=disable") jsonPath := envOr("JSON_PATH", "rptrs.json") @@ -38,6 +40,7 @@ func main() { mux.HandleFunc("/api/repeaters/route", handleRouteRepeaters(db)) mux.HandleFunc("/api/repeater", handleRepeaterByID(db)) mux.HandleFunc("/api/repeaters/search", handleSearchRepeaters(db)) + mux.HandleFunc("/api/version", handleVersion()) if adminToken := os.Getenv("ADMIN_TOKEN"); adminToken != "" { mux.HandleFunc("/admin/", handleAdminPage()) @@ -58,6 +61,13 @@ func main() { log.Fatal(http.ListenAndServe(addr, mux)) } +func handleVersion() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.Write([]byte(`{"version":"` + version + `"}`)) + } +} + func envOr(key, fallback string) string { if v := os.Getenv(key); v != "" { return v diff --git a/static/app.js b/static/app.js index 9a8e519..dec72cc 100644 --- a/static/app.js +++ b/static/app.js @@ -1515,6 +1515,20 @@ window.addEventListener("hashchange", checkHash); + // === Version === + fetch("/api/version") + .then(function (resp) { return resp.json(); }) + .then(function (data) { + if (data.version && data.version !== "dev" && data.version !== "unknown") { + var el = document.getElementById("app-version"); + if (el) { + el.textContent = data.version; + el.parentElement.style.display = ""; + } + } + }) + .catch(function () {}); + // === Init === fetchTgRegistry(); diff --git a/static/index.html b/static/index.html index b6483b6..d4490ec 100644 --- a/static/index.html +++ b/static/index.html @@ -73,7 +73,7 @@ Routing by OSRM. Map by OpenStreetMap. Built by DA6KM.
- Impressum · Datenschutz · Source
+ Impressum · Datenschutz · Source