Skip to content

Commit

Permalink
Pass build time variables while compiling (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Aug 10, 2020
1 parent f6e4200 commit 38919ba
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
17 changes: 9 additions & 8 deletions Makefile
Expand Up @@ -7,6 +7,7 @@ GIT_BRANCH=`git rev-parse --symbolic-full-name --abbrev-ref HEAD`
GIT_DIRTY=`git diff-index --quiet HEAD -- || echo "dirty-"`
VERSION=`git describe --always`
GO_VERSION=`go version | awk '{print $$3}'`
BUILD_FLAGS="-X main.gitCommit=${GIT_COMMIT} -X main.version=${VERSION} -X main.goVersion=${GO_VERSION} -X main.buildDate=${BUILD_DATE}"

default: build test lint gen-doc check-changelog
release: deps build test lint gen-doc
Expand All @@ -23,17 +24,17 @@ imports: off
`go env GOPATH`/bin/goimports -w tools pkg internal cmd

build: imports
go build -o ./cmd/revad/revad ./cmd/revad
go build -o ./cmd/reva/reva ./cmd/reva
go build -ldflags ${BUILD_FLAGS} -o ./cmd/revad/revad ./cmd/revad
go build -ldflags ${BUILD_FLAGS} -o ./cmd/reva/reva ./cmd/reva

tidy:
go mod tidy

build-revad: imports
go build -o ./cmd/revad/revad ./cmd/revad
go build -ldflags ${BUILD_FLAGS} -o ./cmd/revad/revad ./cmd/revad

build-reva: imports
go build -o ./cmd/reva/reva ./cmd/reva
go build -ldflags ${BUILD_FLAGS} -o ./cmd/reva/reva ./cmd/reva

test: off
go test -race ./...
Expand All @@ -51,8 +52,8 @@ deps:
cd /tmp && go get golang.org/x/tools/cmd/goimports

build-ci: off
go build -o ./cmd/revad/revad ./cmd/revad
go build -o ./cmd/reva/reva ./cmd/reva
go build -ldflags ${BUILD_FLAGS} -o ./cmd/revad/revad ./cmd/revad
go build -ldflags ${BUILD_FLAGS} -o ./cmd/reva/reva ./cmd/reva

lint-ci:
go run tools/check-license/check-license.go
Expand All @@ -71,9 +72,9 @@ ci: build-ci test lint-ci

# to be run in Docker build
build-revad-docker: off
go build -o ./cmd/revad/revad ./cmd/revad
go build -ldflags ${BUILD_FLAGS} -o ./cmd/revad/revad ./cmd/revad
build-reva-docker: off
go build -o ./cmd/reva/reva ./cmd/reva
go build -ldflags ${BUILD_FLAGS} -o ./cmd/reva/reva ./cmd/reva
clean:
rm -rf dist

Expand Down
7 changes: 7 additions & 0 deletions changelog/unreleased/build-time-vars.md
@@ -0,0 +1,7 @@
Bugfix: Pass build time variables while compiling

We provide the option of viewing various configuration and version options in
both reva CLI as well as the reva daemon, but we didn't actually have these
values in the first place. This PR adds that info at compile time.

https://github.com/cs3org/reva/pull/1069
4 changes: 0 additions & 4 deletions cmd/reva/main.go
Expand Up @@ -23,8 +23,6 @@ import (
"fmt"
"os"
"strings"

"github.com/cs3org/reva/pkg/sysinfo"
)

var (
Expand All @@ -43,8 +41,6 @@ func init() {
}

func main() {
// initiliaze the global system information
sysinfo.InitSystemInfo(&sysinfo.RevaVersion{Version: version, BuildDate: buildDate, GitCommit: gitCommit, GoVersion: goVersion})

cmds := []*command{
versionCommand(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/revad/main.go
Expand Up @@ -52,7 +52,7 @@ var (
func main() {
flag.Parse()

// initiliaze the global system information
// initialize the global system information
sysinfo.InitSystemInfo(&sysinfo.RevaVersion{Version: version, BuildDate: buildDate, GitCommit: gitCommit, GoVersion: goVersion})

handleVersionFlag()
Expand Down
3 changes: 3 additions & 0 deletions examples/ocmd/ocmd-server-1.toml
Expand Up @@ -113,6 +113,9 @@ address = "0.0.0.0:19001"
[http.services.dataprovider]
driver = "localhome"

[http.services.prometheus]
[http.services.sysinfo]

[http.services.dataprovider.drivers.localhome]
user_layout = "{{.Username}}"

Expand Down
3 changes: 3 additions & 0 deletions examples/ocmd/ocmd-server-2.toml
Expand Up @@ -96,6 +96,9 @@ address = "0.0.0.0:17001"
[http.services.dataprovider]
driver = "localhome"

[http.services.prometheus]
[http.services.sysinfo]

[http.services.dataprovider.drivers.localhome]
user_layout = "{{.Username}}"

Expand Down

0 comments on commit 38919ba

Please sign in to comment.