Skip to content

Commit

Permalink
add buildinfo and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 3, 2023
1 parent b306465 commit d2f4731
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bin
tmp
example/config/test.yaml
test.yaml
minccino
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ builds:
- goos: windows
goarch: arm64
mod_timestamp: "{{ .CommitTimestamp }}"
ldflags:
- -s -w -X github.com/ethpandaops/minccino/pkg/coordinator/buildinfo.BuildRelease={{.Tag}} -X github.com/ethpandaops/minccino/pkg/coordinator/buildinfo.BuildVersion={{.ShortCommit}}
checksum:
name_template: 'checksums.txt'
snapshot:
Expand Down
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# minccino
VERSION := $(shell git rev-parse --short HEAD)
GOLDFLAGS += -X 'github.com/ethpandaops/minccino/pkg/coordinator/buildinfo.BuildVersion="$(VERSION)"'
GOLDFLAGS += -X 'github.com/ethpandaops/minccino/pkg/coordinator/buildinfo.BuildRelease="$(RELEASE)"'

.PHONY: all test clean

all: build

test:
go test ./...

build:
@echo version: $(VERSION)
go build -v -o bin/ -ldflags="-s -w $(GOLDFLAGS)" .

clean:
rm -f bin/*
14 changes: 14 additions & 0 deletions pkg/coordinator/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package buildinfo

import "fmt"

var BuildVersion string
var BuildRelease string

func GetVersion() string {
if BuildRelease == "" {
return fmt.Sprintf("git-%v", BuildVersion)
} else {
return fmt.Sprintf("%v (git-%v)", BuildRelease, BuildVersion)
}
}
2 changes: 2 additions & 0 deletions pkg/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"time"

"github.com/ethpandaops/minccino/pkg/coordinator/buildinfo"
"github.com/ethpandaops/minccino/pkg/coordinator/clients"
"github.com/ethpandaops/minccino/pkg/coordinator/test"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -32,6 +33,7 @@ func NewCoordinator(config *Config, log logrus.FieldLogger, metricsPort, lameDuc
// Run executes the coordinator until completion.
func (c *Coordinator) Run(ctx context.Context) error {
c.log.
WithField("build_version", buildinfo.GetVersion()).
WithField("metrics_port", c.metricsPort).
WithField("lame_duck_seconds", c.lameDuckSeconds).
Info("starting coordinator")
Expand Down

0 comments on commit d2f4731

Please sign in to comment.