Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ builds:
- arm64
ldflags:
- -s -w
- -X main.version={{.Version}}
- -X main.commit={{.Commit}}
- -X main.date={{.Date}}
- -X main.buildVersion={{.Version}}
- -X main.buildCommit={{.Commit}}
- -X main.buildDate={{.Date}}

- id: osctrl-api
main: ./cmd/api
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ tls-static:

# Build Admin UI
admin:
go build -o $(OUTPUT)/$(ADMIN_NAME) $(ADMIN_CODE)
go build $(BUILD_ARGS) -o $(OUTPUT)/$(ADMIN_NAME) $(ADMIN_CODE)

# Build Admin UI statically
admin-static:
go build $(STATIC_ARGS) -o $(OUTPUT)/$(ADMIN_NAME) -a $(ADMIN_CODE)
go build $(BUILD_ARGS) $(STATIC_ARGS) -o $(OUTPUT)/$(ADMIN_NAME) -a $(ADMIN_CODE)

# Build API
api:
Expand Down
33 changes: 28 additions & 5 deletions cmd/admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ const (
defaultInactive int = 72
)

// Build-time metadata (overridden via -ldflags "-X main.buildVersion=... -X main.buildCommit=... -X main.buildDate=...")
var (
buildVersion = serviceVersion
buildCommit = "unknown"
buildDate = "unknown"
)

// Global general variables
var (
err error
Expand Down Expand Up @@ -652,6 +659,16 @@ func main() {
app.Version = serviceVersion
app.Description = appDescription
app.Flags = flags
// Customize version output (supports `--version` and `version` command)
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate)
}
// Add -v alias to the global --version flag
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version information",
}
// Define this command for help to exit when help flag is passed
app.Commands = []*cli.Command{
{
Expand All @@ -662,13 +679,19 @@ func main() {
},
},
}
app.Action = cliAction
// Start service only for default action; version/help won't trigger this
app.Action = func(c *cli.Context) error {
if err := cliAction(c); err != nil {
return err
}
// Initialize service logger
initializeLoggers(flagParams.ConfigValues)
// Service starts!
osctrlAdminService()
return nil
}
if err := app.Run(os.Args); err != nil {
fmt.Printf("app.Run error: %s", err.Error())
os.Exit(1)
}
// Initialize service logger
initializeLoggers(flagParams.ConfigValues)
// Service starts!
osctrlAdminService()
}
2 changes: 0 additions & 2 deletions cmd/tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ func main() {
app.Version = buildVersion
app.Description = appDescription
app.Flags = flags

// Customize version output (supports `--version` and `version` command)
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s version=%s commit=%s date=%s\n", serviceName, buildVersion, buildCommit, buildDate)
Expand All @@ -430,7 +429,6 @@ func main() {
Aliases: []string{"v"},
Usage: "Print version information",
}

// Define commands
app.Commands = []*cli.Command{
{
Expand Down
Loading