Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use embedded files instead of ldflags to get the build info during runtime #2421

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ vendor
/cel-key
coverage.txt
go.work

# embedded files
cmd/celestia/*.txt
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -16,8 +17,14 @@ install-hooks:
@git config core.hooksPath .githooks
.PHONY: install-hooks

## 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-embed

## build: Build celestia-node binary.
build:
build: gen-embed
@echo "--> Building Celestia"
@go build -o build/ ${LDFLAGS} ./cmd/celestia
.PHONY: build
Expand Down Expand Up @@ -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
9 changes: 7 additions & 2 deletions cmd/celestia/version.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// +build: !test
package main

import (
"fmt"
"runtime"

_ "embed"

"github.com/spf13/cobra"
)

var (
buildTime string
lastCommit string
buildTime string
//go:embed lastCommit.txt

Check failure on line 15 in cmd/celestia/version.go

View workflow job for this annotation

GitHub Actions / go-ci / Unit Tests Coverage

pattern lastCommit.txt: no matching files found

Check failure on line 15 in cmd/celestia/version.go

View workflow job for this annotation

GitHub Actions / go-ci / Run Unit Tests with Race Detector

pattern lastCommit.txt: no matching files found
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to document this lastCommit.txt here.
And exclude it from the the go test executor

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my commetn

Copy link
Member