From 610c5d4b3f26fe8a1943788a5197052e5f6bd211 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 31 May 2022 11:00:49 +0200 Subject: [PATCH 1/3] Print commit hash and build time. --- Makefile | 6 +++--- build/build.go | 9 +++++++++ build/debug_off.go | 6 ++++++ build/debug_on.go | 6 ++++++ build/release_dev.go | 6 ++++++ build/release_standard.go | 6 ++++++ build/release_testing.go | 6 ++++++ main.go | 3 ++- 8 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 build/build.go create mode 100644 build/debug_off.go create mode 100644 build/debug_on.go create mode 100644 build/release_dev.go create mode 100644 build/release_standard.go create mode 100644 build/release_testing.go diff --git a/Makefile b/Makefile index ca1b7787..cfb54df7 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ # These variables get inserted into ./build/commit.go -BUILD_TIME=$(shell date) +BUILD_TIME=$(shell date -u) GIT_REVISION=$(shell git rev-parse --short HEAD) GIT_DIRTY=$(shell git diff-index --quiet HEAD -- || echo "✗-") -ldflags= -X github.com/SkynetLabs/skynet-accounts/build.GitRevision=${GIT_DIRTY}${GIT_REVISION} \ +ldflags= -X "github.com/SkynetLabs/skynet-accounts/build.GitRevision=${GIT_DIRTY}${GIT_REVISION}" \ -X "github.com/SkynetLabs/skynet-accounts/build.BuildTime=${BUILD_TIME}" racevars= history_size=3 halt_on_error=1 atexit_sleep_ms=2000 @@ -124,7 +124,7 @@ dev-race: # release builds and installs release binaries. release: - go install -tags='netgo' -ldflags='-s -w $(ldflags)' $(release-pkgs) + go install -tags='netgo dev' -ldflags='-s -w $(ldflags)' $(release-pkgs) release-race: GORACE='$(racevars)' go install -race -tags='netgo' -ldflags='-s -w $(ldflags)' $(release-pkgs) release-util: diff --git a/build/build.go b/build/build.go new file mode 100644 index 00000000..d5d74f5b --- /dev/null +++ b/build/build.go @@ -0,0 +1,9 @@ +package build + +// GitRevision and BuildTime get assigned via the Makefile when built. +var ( + // GitRevision is the git commit hash used when built + GitRevision string + // BuildTime is the date and time the build was completed + BuildTime string +) diff --git a/build/debug_off.go b/build/debug_off.go new file mode 100644 index 00000000..edd7789e --- /dev/null +++ b/build/debug_off.go @@ -0,0 +1,6 @@ +// +build !debug + +package build + +// DEBUG set to false turns the debugging off +const DEBUG = false diff --git a/build/debug_on.go b/build/debug_on.go new file mode 100644 index 00000000..eab60313 --- /dev/null +++ b/build/debug_on.go @@ -0,0 +1,6 @@ +// +build debug + +package build + +// DEBUG set to true turns the debugging on +const DEBUG = true diff --git a/build/release_dev.go b/build/release_dev.go new file mode 100644 index 00000000..69cc259e --- /dev/null +++ b/build/release_dev.go @@ -0,0 +1,6 @@ +// +build dev + +package build + +// Release refers to the dev release mode. +const Release = "dev" diff --git a/build/release_standard.go b/build/release_standard.go new file mode 100644 index 00000000..39971c21 --- /dev/null +++ b/build/release_standard.go @@ -0,0 +1,6 @@ +// +build !testing,!dev + +package build + +// Release refers to the standard release mode. +const Release = "standard" diff --git a/build/release_testing.go b/build/release_testing.go new file mode 100644 index 00000000..e6aeedfb --- /dev/null +++ b/build/release_testing.go @@ -0,0 +1,6 @@ +// +build testing + +package build + +// Release refers to the testing release mode. +const Release = "testing" diff --git a/main.go b/main.go index 9a592f9c..7a85c984 100644 --- a/main.go +++ b/main.go @@ -10,13 +10,13 @@ import ( "strings" "github.com/SkynetLabs/skynet-accounts/api" + "github.com/SkynetLabs/skynet-accounts/build" "github.com/SkynetLabs/skynet-accounts/database" "github.com/SkynetLabs/skynet-accounts/email" "github.com/SkynetLabs/skynet-accounts/jwt" "github.com/SkynetLabs/skynet-accounts/metafetcher" "github.com/joho/godotenv" "github.com/stripe/stripe-go/v72" - "gitlab.com/SkynetLabs/skyd/build" "gitlab.com/SkynetLabs/skyd/skymodules" "github.com/sirupsen/logrus" @@ -264,5 +264,6 @@ func main() { if err != nil { log.Fatal(errors.AddContext(err, "failed to build the API")) } + fmt.Printf("Starting Accounts.\nGitRevision: %v (built %v)\n", build.GitRevision, build.BuildTime) logger.Fatal(server.ListenAndServe(3000)) } From 4754bc703b853d56feefcfa7c73ad95e446d33f6 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Tue, 31 May 2022 11:14:31 +0200 Subject: [PATCH 2/3] Use logger instead of fmt.Prinf. --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 7a85c984..50ea5aa5 100644 --- a/main.go +++ b/main.go @@ -264,6 +264,6 @@ func main() { if err != nil { log.Fatal(errors.AddContext(err, "failed to build the API")) } - fmt.Printf("Starting Accounts.\nGitRevision: %v (built %v)\n", build.GitRevision, build.BuildTime) + log.Printf("Starting Accounts.\nGitRevision: %v (built %v)\n", build.GitRevision, build.BuildTime) logger.Fatal(server.ListenAndServe(3000)) } From 442fdda4fe55ce482a244f830555aa8db2a85330 Mon Sep 17 00:00:00 2001 From: Ivaylo Novakov Date: Wed, 1 Jun 2022 18:31:11 +0200 Subject: [PATCH 3/3] Remove debug code. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index cfb54df7..bf385e2c 100644 --- a/Makefile +++ b/Makefile @@ -124,7 +124,7 @@ dev-race: # release builds and installs release binaries. release: - go install -tags='netgo dev' -ldflags='-s -w $(ldflags)' $(release-pkgs) + go install -tags='netgo' -ldflags='-s -w $(ldflags)' $(release-pkgs) release-race: GORACE='$(racevars)' go install -race -tags='netgo' -ldflags='-s -w $(ldflags)' $(release-pkgs) release-util: