From 1e6afc96ff8356056421b4a549e53c4ef17406a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Mon, 3 Jul 2023 13:53:09 +0200 Subject: [PATCH 1/6] feat: use of embed to add the version info - we're missing the values during runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- .gitignore | 3 +++ Makefile | 17 +++++++++++++++-- cmd/celestia/version.go | 8 ++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 24c3851f21..89c3832d76 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ vendor /cel-key coverage.txt go.work + +# embeded files +cmd/celestia/*.txt \ No newline at end of file diff --git a/Makefile b/Makefile index 310e65cbe0..267b4946be 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ SHELL=/usr/bin/env bash PROJECTNAME=$(shell basename "$(PWD)") -LDFLAGS=-ldflags="-X 'main.buildTime=$(shell date)' -X 'main.lastCommit=$(shell git rev-parse HEAD)' -X 'main.semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'" +DOCKER_TAG := $(shell git rev-parse --short=7 HEAD) +LDFLAGS=-ldflags="-X 'main.buildTime=$(shell date)'" ifeq (${PREFIX},) PREFIX := /usr/local endif @@ -16,8 +17,14 @@ install-hooks: @git config core.hooksPath .githooks .PHONY: install-hooks +## gen-embeded: Generate the embeded files for celestia-node binary. +gen-embeded: + @printf '%s' "$$(git describe --tags --abbrev=0 --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)" > cmd/celestia/semanticVersion.txt + @printf '%s' "$$(git rev-parse HEAD)" > cmd/celestia/lastCommit.txt +.PHONY: gen-embeded + ## build: Build celestia-node binary. -build: +build: gen-embeded @echo "--> Building Celestia" @go build -o build/ ${LDFLAGS} ./cmd/celestia .PHONY: build @@ -174,3 +181,9 @@ adr-gen: @echo "--> Generating ADR" @curl -sSL https://raw.githubusercontent.com/celestiaorg/.github/main/adr-template.md > docs/architecture/adr-$(NUM)-$(TITLE).md .PHONY: adr-gen + +## docker-build: Builds the Docker container +docker-build: + @echo "--> Docker build... [$(DOCKER_TAG)]" + @docker build -t ghcr.io/celestiaorg/$(PROJECTNAME):$(DOCKER_TAG) . +.PHONY: docker-build diff --git a/cmd/celestia/version.go b/cmd/celestia/version.go index 462f17b474..6c3b01b372 100644 --- a/cmd/celestia/version.go +++ b/cmd/celestia/version.go @@ -4,12 +4,16 @@ import ( "fmt" "runtime" + _ "embed" + "github.com/spf13/cobra" ) var ( - buildTime string - lastCommit string + buildTime string + //go:embed lastCommit.txt + lastCommit string + //go:embed semanticVersion.txt semanticVersion string systemVersion = fmt.Sprintf("%s/%s", runtime.GOARCH, runtime.GOOS) From 0a1776d89e09b64c1e9de7633c0df758820fa162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Mon, 3 Jul 2023 13:54:45 +0200 Subject: [PATCH 2/6] fix: add EOF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 89c3832d76..ef364ba3fc 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ coverage.txt go.work # embeded files -cmd/celestia/*.txt \ No newline at end of file +cmd/celestia/*.txt From ce37ccef0cca802db31e1d6f46b9e3c54e9007b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Mon, 3 Jul 2023 14:05:31 +0200 Subject: [PATCH 3/6] feat: rename make MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 267b4946be..e89b1e9ed9 100644 --- a/Makefile +++ b/Makefile @@ -17,14 +17,14 @@ install-hooks: @git config core.hooksPath .githooks .PHONY: install-hooks -## gen-embeded: Generate the embeded files for celestia-node binary. -gen-embeded: +## gen-embed: Generate the embed files for celestia-node binary. +gen-embed: @printf '%s' "$$(git describe --tags --abbrev=0 --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)" > cmd/celestia/semanticVersion.txt @printf '%s' "$$(git rev-parse HEAD)" > cmd/celestia/lastCommit.txt -.PHONY: gen-embeded +.PHONY: gen-embed ## build: Build celestia-node binary. -build: gen-embeded +build: gen-embed @echo "--> Building Celestia" @go build -o build/ ${LDFLAGS} ./cmd/celestia .PHONY: build From 35ffb8275312ca8578a3231b3b0caa869ba11ec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Mon, 3 Jul 2023 14:09:49 +0200 Subject: [PATCH 4/6] fix: typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ef364ba3fc..cf08657e53 100644 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,5 @@ vendor coverage.txt go.work -# embeded files +# embedded files cmd/celestia/*.txt From 8364c578e8304c8e2478fdc96bca6ffb83051e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Mon, 3 Jul 2023 14:28:14 +0200 Subject: [PATCH 5/6] fix: ignore during tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- cmd/celestia/version.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/celestia/version.go b/cmd/celestia/version.go index 6c3b01b372..894ea581ac 100644 --- a/cmd/celestia/version.go +++ b/cmd/celestia/version.go @@ -1,3 +1,4 @@ +// +build: !test package main import ( From 679d0f5fee21f38614178590d5c849b1363a29d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Ramon=20Ma=C3=B1es?= Date: Mon, 3 Jul 2023 17:27:34 +0200 Subject: [PATCH 6/6] feat: use go:buid version >go17 - commenst to the embed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jose Ramon Mañes --- cmd/celestia/version.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/celestia/version.go b/cmd/celestia/version.go index 894ea581ac..88933f6e6c 100644 --- a/cmd/celestia/version.go +++ b/cmd/celestia/version.go @@ -1,4 +1,5 @@ -// +build: !test +//go:build !test + package main import ( @@ -13,8 +14,10 @@ import ( var ( buildTime string //go:embed lastCommit.txt + // The go:embed directive embeds the content of the lastCommit.txt file into the lastCommit string variable. lastCommit string //go:embed semanticVersion.txt + // The go:embed directive embeds the content of the semanticVersion.txt file into the semanticVersion string variable. semanticVersion string systemVersion = fmt.Sprintf("%s/%s", runtime.GOARCH, runtime.GOOS)