Skip to content

Commit

Permalink
Add build information to binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Jan 29, 2020
1 parent ed51af1 commit 8a46068
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
25 changes: 20 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@
.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
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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions cmd/hypervisor/commands/gen-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ var (
output string
replace bool
configLocType = pathutil.WorkingDirLoc
testenv bool
testEnv bool
)

// nolint:gochecknoinits
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
Expand All @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package buildinfo

const unknown = "unknown"

var (
Version = unknown
Commit = unknown
Date = unknown
)

0 comments on commit 8a46068

Please sign in to comment.