From 8351e352871f9403f613b319f750174564b79b28 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 | 2 +- clientapi/routing/routing.go | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/build/docker/Dockerfile.monolith b/build/docker/Dockerfile.monolith index 3180e9626..0745f696e 100644 --- a/build/docker/Dockerfile.monolith +++ b/build/docker/Dockerfile.monolith @@ -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 ef4f8cafa..b39112154 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" "github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/util" @@ -44,16 +42,8 @@ import ( userapi "github.com/matrix-org/dendrite/userapi/api" ) -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. @@ -128,7 +118,7 @@ func Setup( "v1.0", "v1.1", "v1.2", - }, UnstableFeatures: unstableFeatures, CommitHash: commitHash}, + }, UnstableFeatures: unstableFeatures, CommitHash: CommitHash}, } }), ).Methods(http.MethodGet, http.MethodOptions)