diff --git a/Makefile b/Makefile index 2acc917d4f31294c3574a01b2d2d881bf85a28d2..8a99c7b8c8cb0c4774190c1a310328ef02f8a57d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,7 @@ +CURRENT_DATE=$(shell eval "date -u +'%Y-%m-%d at %H:%M:%S'") +GIT_COMMIT=$(shell eval "git rev-parse HEAD") +BUILD_FLAGS=-ldflags="-X 'nexus-common/buildversion.buildDate=$(CURRENT_DATE)' -X 'nexus-common/buildversion.gitCommit=$(GIT_COMMIT)'" + SERVER_BASEDIR=$(PREFIX)/nexus-server SERVER_CERTS_DIR=$(SERVER_BASEDIR)/certs SERVER_CERT=$(SERVER_CERTS_DIR)/server-cert.pem @@ -60,10 +64,10 @@ check_prefix_var: build_srv: src/server tools/genpwd @echo "[Building nexus-server]" - @cd src/server && go build . + @cd src/server && go build $(BUILD_FLAGS) . @echo "OK" @echo "Building genpwd" - @cd tools/genpwd && go build . + @cd tools/genpwd && go build $(BUILD_FLAGS) . @echo "OK" clean_srv: @@ -198,7 +202,7 @@ set_permissions_srv: #------------------------------------------------------------------------- -BUILD_CLIENT_FLAGS=build -buildvcs=false +BUILD_CLIENT_FLAGS=-buildvcs=false # To force a full recompile: # BUILD_FLAGS=build -a BUILD_DIR_CLIENT=build @@ -279,11 +283,11 @@ xbuild_client: check_bin_var check_server_var copy_resources_client $(SRC_CLIENT cd $(SRC_ABS_CLIENT)/$(BIN) ;\ go clean . ;\ if [ $$os = "linux" ]; then \ - GOARCH=$$arch GOOS=$$os CGO_ENABLED=0 go $(BUILD_CLIENT_FLAGS) -o $(BUILD_ABS_CLIENT)/$$arch/$$os/ ;\ + GOARCH=$$arch GOOS=$$os CGO_ENABLED=0 go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) -o $(BUILD_ABS_CLIENT)/$$arch/$$os/ ;\ #strip -s $(BUILD_ABS_CLIENT)/$$arch/$$os/$(BIN) ;\ #upx $(BUILD_ABS_CLIENT)/$$arch/$$os/$(BIN) ;\ else \ - GOARCH=$$arch GOOS=$$os go $(BUILD_CLIENT_FLAGS) -o $(BUILD_ABS_CLIENT)/$$arch/$$os/ ;\ + GOARCH=$$arch GOOS=$$os go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) -o $(BUILD_ABS_CLIENT)/$$arch/$$os/ ;\ fi \ fi \ done \ @@ -294,17 +298,17 @@ $(BUILD_DIR_CLIENT): build_nexush: check_server_var copy_resources_client $(BUILD_DIR_CLIENT) $(SRC_CLIENT)/nexush @echo "[Building nexush into $(BUILD_DIR_CLIENT) directory]" - @cd $(SRC_CLIENT)/nexush && go $(BUILD_CLIENT_FLAGS) && mv nexush $(BUILD_ABS_CLIENT) + @cd $(SRC_CLIENT)/nexush && go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) && mv nexush $(BUILD_ABS_CLIENT) build_nexus-cli: check_server_var copy_resources_client $(BUILD_DIR_CLIENT) $(SRC_CLIENT)/nexus-cli @echo "[Building nexus-cli into $(BUILD_DIR_CLIENT) directory]" - @cd $(SRC_CLIENT)/nexus-cli && go $(BUILD_CLIENT_FLAGS) && mv nexus-cli $(BUILD_ABS_CLIENT) + @cd $(SRC_CLIENT)/nexus-cli && go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) && mv nexus-cli $(BUILD_ABS_CLIENT) build_nexus-exam: check_server_var check_nexus_exam_vars copy_resources_client $(BUILD_DIR_CLIENT) $(SRC_CLIENT)/nexus-exam @echo "[Building nexus-exam into $(BUILD_DIR_CLIENT) directory]" @echo -n '$(value EXAM_USER)' > $(NEXUS_EXAM_USER_CREDS_FILE) @echo -n '$(value EXAM_PWD)' > $(NEXUS_EXAM_PWD_CREDS_FILE) - @cd $(SRC_CLIENT)/nexus-exam && go $(BUILD_CLIENT_FLAGS) && mv nexus-exam $(BUILD_ABS_CLIENT) + @cd $(SRC_CLIENT)/nexus-exam && go build $(BUILD_FLAGS) $(BUILD_CLIENT_FLAGS) && mv nexus-exam $(BUILD_ABS_CLIENT) @strip -s $(BUILD_DIR_CLIENT)/nexus-exam @upx -q $(BUILD_DIR_CLIENT)/nexus-exam @rm $(NEXUS_EXAM_USER_CREDS_FILE) $(NEXUS_EXAM_PWD_CREDS_FILE) @@ -324,7 +328,7 @@ tests: check_login_var tests/run_tests build_nexus-cli $(BUILD_DIR_CLIENT)/nexus .PHONY: clean_client tests # To build a static executable: -# CGO_ENABLED=0 go build +# CGO_ENABLED=0 go build $(BUILD_FLAGS) # @echo " build_client build $(BIN) binaries for the specified OS/architecture" # @echo " valid OS values: linux, windows, darwin" diff --git a/src/client/nexus-cli/go.mod b/src/client/nexus-cli/go.mod index 00c72579ed96178c49c03d559528b38a621e1156..da7359696ca162397118b37d84317cec43de564f 100644 --- a/src/client/nexus-cli/go.mod +++ b/src/client/nexus-cli/go.mod @@ -1,6 +1,8 @@ module nexus-cli -go 1.18 +go 1.22.2 + +replace nexus-common/buildversion => ../../common/buildversion replace nexus-common/caps => ../../common/caps @@ -69,6 +71,7 @@ require ( golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect nexus-client/exec v0.0.0-00010101000000-000000000000 // indirect + nexus-common/buildversion v0.0.0-00010101000000-000000000000 // indirect nexus-common/caps v0.0.0-00010101000000-000000000000 // indirect nexus-common/params v0.0.0-00010101000000-000000000000 // indirect nexus-common/template v0.0.0-00010101000000-000000000000 // indirect diff --git a/src/client/nexus-cli/nexus-cli.go b/src/client/nexus-cli/nexus-cli.go index 77e6c2607ec0d9185f42313ea7090dff80d39bb1..6d24cf41210e70eaabb53478ef06245e91fa0c5b 100644 --- a/src/client/nexus-cli/nexus-cli.go +++ b/src/client/nexus-cli/nexus-cli.go @@ -5,6 +5,7 @@ import ( "path" "strings" "nexus-common/utils" + "nexus-common/buildversion" u "nexus-client/utils" g "nexus-client/globals" "nexus-client/defaults" @@ -68,7 +69,8 @@ var cmdList = []cmd.Command { func run() int { var appname = path.Base(os.Args[0]) clientVersion := version.Get() - u.PrintlnErr(appname+" version "+clientVersion.String()) + u.PrintlnErr(appname+" version "+clientVersion.String()+" (commit "+buildversion.GitCommit()+")") + u.PrintlnErr("Built on "+buildversion.BuildDate()) if len(os.Args) < 2 { u.PrintlnErr("USAGE: "+appname+" CMD") diff --git a/src/client/nexus-exam/go.mod b/src/client/nexus-exam/go.mod index aabdefab4a053661db3fc7d7e1e8a3dabf2d595a..a601602b1c9f0c7c1ac1e4aecb498a5dd714b85b 100644 --- a/src/client/nexus-exam/go.mod +++ b/src/client/nexus-exam/go.mod @@ -1,6 +1,8 @@ module nexus-exam -go 1.18 +go 1.22.2 + +replace nexus-common/buildversion => ../../common/buildversion replace nexus-common/caps => ../../common/caps @@ -84,6 +86,7 @@ require ( nexus-client/globals v0.0.0-00010101000000-000000000000 // indirect nexus-client/utils v0.0.0-00010101000000-000000000000 // indirect nexus-client/version v0.0.0-00010101000000-000000000000 // indirect + nexus-common/buildversion v0.0.0-00010101000000-000000000000 // indirect nexus-common/caps v0.0.0-00010101000000-000000000000 // indirect nexus-common/params v0.0.0-00010101000000-000000000000 // indirect nexus-common/utils v0.0.0-00010101000000-000000000000 // indirect diff --git a/src/client/nexus-exam/nexus-exam.go b/src/client/nexus-exam/nexus-exam.go index 846d19a97b6a7a7c15a03141fc0081cbe7e63d9c..041cd84b54758250bee7c18a95764e1b981b722d 100644 --- a/src/client/nexus-exam/nexus-exam.go +++ b/src/client/nexus-exam/nexus-exam.go @@ -2,6 +2,7 @@ package main import ( "os" + "path" "time" "bytes" "errors" @@ -11,9 +12,11 @@ import ( "encoding/json" "nexus-common/vm" "nexus-common/params" + "nexus-common/buildversion" e "nexus-client/exec" u "nexus-client/utils" g "nexus-client/globals" + "nexus-client/version" "nexus-client/defaults" "nexus-client/cmdLogin" "fyne.io/fyne/v2" @@ -160,6 +163,11 @@ func refreshToken(parent fyne.Window) { } func run() int { + var appname = path.Base(os.Args[0]) + clientVersion := version.Get() + u.PrintlnErr(appname+" version "+clientVersion.String()+" (commit "+buildversion.GitCommit()+")") + u.PrintlnErr("Built on "+buildversion.BuildDate()) + hypervisorCheck() if err := e.CheckRemoteViewer(); err != nil { diff --git a/src/client/nexush/go.mod b/src/client/nexush/go.mod index 4ca9722a2b215709ca71b6580619c2fdd5ce3f24..30d7fd435ce0d4fded4e0cfae0ed04040ff004b3 100644 --- a/src/client/nexush/go.mod +++ b/src/client/nexush/go.mod @@ -1,6 +1,8 @@ module nexush -go 1.18 +go 1.22.2 + +replace nexus-common/buildversion => ../../common/buildversion replace nexus-common/caps => ../../common/caps @@ -72,6 +74,7 @@ require ( golang.org/x/sys v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect nexus-client/exec v0.0.0-00010101000000-000000000000 // indirect + nexus-common/buildversion v0.0.0-00010101000000-000000000000 // indirect nexus-common/caps v0.0.0-00010101000000-000000000000 // indirect nexus-common/params v0.0.0-00010101000000-000000000000 // indirect nexus-common/template v0.0.0-00010101000000-000000000000 // indirect diff --git a/src/client/nexush/nexush.go b/src/client/nexush/nexush.go index 8dd6aee57bd1cb79f10bdc78107204634a416028..bbd5ef199697e1f57a0581b39833273c78240cf3 100644 --- a/src/client/nexush/nexush.go +++ b/src/client/nexush/nexush.go @@ -11,6 +11,7 @@ import ( "golang.org/x/term" u "nexus-client/utils" "nexus-common/utils" + "nexus-common/buildversion" g "nexus-client/globals" "nexus-client/defaults" "nexus-client/version" @@ -80,7 +81,8 @@ var savedTermState *term.State = nil func run() int { var appname = path.Base(os.Args[0]) clientVersion := version.Get() - u.PrintlnErr(appname+" version "+clientVersion.String()) + u.PrintlnErr(appname+" version "+clientVersion.String()+" (commit "+buildversion.GitCommit()+")") + u.PrintlnErr("Built on "+buildversion.BuildDate()) if len(os.Args) < 2 { u.PrintlnErr("USAGE: "+appname+" EMAIL") diff --git a/src/common/buildversion/go.mod b/src/common/buildversion/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..d6fed8cc54f89ce68eaac906bf11ca4b98833ee0 --- /dev/null +++ b/src/common/buildversion/go.mod @@ -0,0 +1,3 @@ +module nexus-common/buildversion + +go 1.22.2 diff --git a/src/common/buildversion/version.go b/src/common/buildversion/version.go new file mode 100644 index 0000000000000000000000000000000000000000..a184bf141c5146e63fe6a8ef8aba19b2912c26c8 --- /dev/null +++ b/src/common/buildversion/version.go @@ -0,0 +1,15 @@ +package buildversion + +var ( + // These variables are replaced by ldflags at build time + gitCommit = "n/a" + buildDate = "n/a" +) + +func GitCommit() string { + return gitCommit +} + +func BuildDate() string { + return buildDate +} \ No newline at end of file diff --git a/src/server/go.mod b/src/server/go.mod index d2012684d587ecc42e359f5730d81623b6992620..f3ad7f59cd38b4d60c7592731d678a6d30337178 100644 --- a/src/server/go.mod +++ b/src/server/go.mod @@ -1,6 +1,8 @@ module nexus-server -go 1.18 +go 1.22.2 + +replace nexus-common/buildversion => ../common/buildversion replace nexus-common/template => ../common/template @@ -64,6 +66,7 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect + nexus-common/buildversion v0.0.0-00010101000000-000000000000 // indirect nexus-common/caps v0.0.0-00010101000000-000000000000 // indirect nexus-common/params v0.0.0-00010101000000-000000000000 // indirect nexus-common/template v0.0.0-00010101000000-000000000000 // indirect diff --git a/src/server/nexus-server.go b/src/server/nexus-server.go index 5ecf67490382f2d63f0eff6a5f0b68fe214f33aa..eb5a200d8bcaa50c8512f575b7963d397b8d4d30 100644 --- a/src/server/nexus-server.go +++ b/src/server/nexus-server.go @@ -12,6 +12,7 @@ import ( "nexus-server/config" "nexus-server/cleaner" "nexus-server/version" + "nexus-common/buildversion" "github.com/sirupsen/logrus" ) @@ -22,7 +23,8 @@ func main() { var appname = path.Base(os.Args[0]) serverVersion := version.Get() - log.Info(appname+" version "+serverVersion.String()) + log.Info(appname+" version "+serverVersion.String()+" (commit "+buildversion.GitCommit()+")") + log.Info("Built on "+buildversion.BuildDate()) // Initialize the RNG' seed to the current time. utils.RandInit()