From 8a46068224ece29d9e239e0782dcfbcef106db50 Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 29 Jan 2020 22:38:33 +0400 Subject: [PATCH] Add build information to binaries --- Makefile | 25 ++++++++++++++++++++----- cmd/hypervisor/commands/gen-config.go | 12 ++++++------ pkg/buildinfo/buildinfo.go | 9 +++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 pkg/buildinfo/buildinfo.go diff --git a/Makefile b/Makefile index 6dac85287a..9a1c1bb216 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,13 @@ .PHONY : docker-apps docker-bin docker-volume .PHONY : docker-run docker-stop +VERSION := 0.1.0 # 0.1.0 is the first possible version in semver + +RFC_3339 := "+%Y-%m-%dT%H:%M:%SZ" +DATE := $(shell date -u $(RFC_3339)) +COMMIT := $(shell git rev-list -1 HEAD) + +PROJECT_BASE := github.com/SkycoinProject/skywire-mainnet OPTS?=GO111MODULE=on DOCKER_IMAGE?=skywire-runner # docker image to use for running skywire-visor.`golang`, `buildpack-deps:stretch-scm` is OK too DOCKER_NETWORK?=SKYNET @@ -14,7 +21,16 @@ DOCKER_NODE?=SKY01 DOCKER_OPTS?=GO111MODULE=on GOOS=linux # go options for compiling for docker container TEST_OPTS?=-race -tags no_ci -cover -timeout=5m TEST_OPTS_NOCI?=-race -cover -timeout=5m -v -BUILD_OPTS?= + +BUILDINFO_PATH := $(PROJECT_BASE)/pkg/buildinfo + +BUILDINFO_VERSION := -X $(BUILDINFO_PATH).Version=$(VERSION) +BUILDINFO_DATE := -X $(BUILDINFO_PATH).Date=$(DATE) +BUILDINFO_COMMIT := -X $(BUILDINFO_PATH).Commit=$(COMMIT) + +BUILDINFO?=-ldflags="$(BUILDINFO_VERSION) $(BUILDINFO_DATE) $(BUILDINFO_COMMIT)" + +BUILD_OPTS?=$(BUILDINFO) check: lint test ## Run linters and tests @@ -75,9 +91,9 @@ install-linters: ## Install linters ${OPTS} go get -u golang.org/x/tools/cmd/goimports format: ## Formats the code. Must have goimports installed (use make install-linters). - ${OPTS} goimports -w -local github.com/SkycoinProject/skywire ./pkg - ${OPTS} goimports -w -local github.com/SkycoinProject/skywire ./cmd - ${OPTS} goimports -w -local github.com/SkycoinProject/skywire ./internal + ${OPTS} goimports -w -local ${PROJECT_BASE} ./pkg + ${OPTS} goimports -w -local ${PROJECT_BASE} ./cmd + ${OPTS} goimports -w -local ${PROJECT_BASE} ./internal dep: ## Sorts dependencies ${OPTS} go mod vendor -v @@ -158,7 +174,6 @@ run-syslog: ## Run syslog-ng in docker. Logs are mounted under /tmp/syslog -docker container rm syslog-ng -f docker run -d -p 514:514/udp -v /tmp/syslog:/var/log --name syslog-ng balabit/syslog-ng:latest - integration-startup: ## Starts up the required transports between `skywire-visor`s of interactive testing environment ./integration/startup.sh diff --git a/cmd/hypervisor/commands/gen-config.go b/cmd/hypervisor/commands/gen-config.go index e6e223ca29..0461a6e0fb 100644 --- a/cmd/hypervisor/commands/gen-config.go +++ b/cmd/hypervisor/commands/gen-config.go @@ -15,7 +15,7 @@ var ( output string replace bool configLocType = pathutil.WorkingDirLoc - testenv bool + testEnv bool ) // nolint:gochecknoinits @@ -23,13 +23,13 @@ func init() { outputUsage := "path of output config file. Uses default of 'type' flag if unspecified." replaceUsage := "whether to allow rewrite of a file that already exists." configLocTypeUsage := fmt.Sprintf("config generation mode. Valid values: %v", pathutil.AllConfigLocationTypes()) - testEnv := "whether to use production or test deployment service." + testEnvUsage := "whether to use production or test deployment service." rootCmd.AddCommand(genConfigCmd) genConfigCmd.Flags().StringVarP(&output, "output", "o", "", outputUsage) genConfigCmd.Flags().BoolVarP(&replace, "replace", "r", false, replaceUsage) genConfigCmd.Flags().VarP(&configLocType, "type", "m", configLocTypeUsage) - genConfigCmd.Flags().BoolVarP(&testenv, "testing-environment", "t", false, testEnv) + genConfigCmd.Flags().BoolVarP(&testEnv, "testing-environment", "t", false, testEnvUsage) } // nolint:gochecknoglobals @@ -50,11 +50,11 @@ var genConfigCmd = &cobra.Command{ var conf hypervisor.Config switch configLocType { case pathutil.WorkingDirLoc: - conf = hypervisor.GenerateWorkDirConfig(testenv) + conf = hypervisor.GenerateWorkDirConfig(testEnv) case pathutil.HomeLoc: - conf = hypervisor.GenerateHomeConfig(testenv) + conf = hypervisor.GenerateHomeConfig(testEnv) case pathutil.LocalLoc: - conf = hypervisor.GenerateLocalConfig(testenv) + conf = hypervisor.GenerateLocalConfig(testEnv) default: log.Fatalln("invalid config type:", configLocType) } diff --git a/pkg/buildinfo/buildinfo.go b/pkg/buildinfo/buildinfo.go new file mode 100644 index 0000000000..07e0bc2ee0 --- /dev/null +++ b/pkg/buildinfo/buildinfo.go @@ -0,0 +1,9 @@ +package buildinfo + +const unknown = "unknown" + +var ( + Version = unknown + Commit = unknown + Date = unknown +)