From f681e54bef745cb6d769615d56e2c36cca552955 Mon Sep 17 00:00:00 2001 From: Brian Meek Date: Thu, 15 Sep 2022 15:00:36 -0700 Subject: [PATCH] Add commit hash to routing version API Signed-off-by: Brian Meek --- build/docker/Dockerfile.monolith | 4 ++-- clientapi/routing/routing.go | 16 +++------------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/build/docker/Dockerfile.monolith b/build/docker/Dockerfile.monolith index bb02934cd..0745f696e 100644 --- a/build/docker/Dockerfile.monolith +++ b/build/docker/Dockerfile.monolith @@ -1,4 +1,4 @@ -FROM docker.io/golang:1.18-alpine AS base +FROM docker.io/golang:1.19-alpine AS base RUN apk --update --no-cache add bash build-base @@ -7,7 +7,7 @@ WORKDIR /build COPY . /build RUN mkdir -p bin -RUN go build -trimpath -o bin/ ./cmd/dendrite-monolith-server +RUN go build -ldflags="-X 'routing.CommitHash=`git rev-list -1 HEAD`'" -trimpath -o bin/ ./cmd/dendrite-monolith-server RUN go build -trimpath -o bin/ ./cmd/create-account RUN go build -trimpath -o bin/ ./cmd/generate-keys diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index b5c18fbd2..fa4793417 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -19,8 +19,6 @@ import ( "net/http" "strings" - "runtime/debug" - "github.com/gorilla/mux" appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/clientapi/api" @@ -43,16 +41,8 @@ import ( "github.com/sirupsen/logrus" ) -var commitHash = func() string { - if info, ok := debug.ReadBuildInfo(); ok { - for _, setting := range info.Settings { - if setting.Key == "vcs.revision" { - return setting.Value - } - } - } - return "" -}() +// Added in build script Cokerfile.monolith +var CommitHash string // Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client // to clients which need to make outbound HTTP requests. @@ -126,7 +116,7 @@ func Setup( "v1.0", "v1.1", "v1.2", - }, UnstableFeatures: unstableFeatures, CommitHash: commitHash}, + }, UnstableFeatures: unstableFeatures, CommitHash: CommitHash}, } }), ).Methods(http.MethodGet, http.MethodOptions)