Skip to content

Commit

Permalink
feat(commands): go build info (#5775)
Browse files Browse the repository at this point in the history
Include go build info in the authelia build-info command.

Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
  • Loading branch information
james-d-elliott committed Aug 4, 2023
1 parent 8785b10 commit 37ee009
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/content/en/reference/guides/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ to be used by administrators of their individual *Authelia* installs.
### Prometheus

*Authelia* supports exporting [Prometheus] metrics. These metrics are served on a separate port at the `/metrics` path
when configured. If metrics are enabled the metrics listener listens on `0.0.0.0:9959` as per the officially
when configured. If metrics are enabled the metrics listener listens on `:9959` as per the officially
[registered port] unless configured otherwise.

#### Recorded Metrics
Expand Down
33 changes: 32 additions & 1 deletion internal/commands/build-info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package commands
import (
"fmt"
"runtime"
"runtime/debug"
"strings"

"github.com/spf13/cobra"

Expand All @@ -26,8 +28,37 @@ func newBuildInfoCmd(ctx *CmdCtx) (cmd *cobra.Command) {

// BuildInfoRunE is the RunE for the authelia build-info command.
func (ctx *CmdCtx) BuildInfoRunE(_ *cobra.Command, _ []string) (err error) {
var (
info *debug.BuildInfo
ok bool
)

if info, ok = debug.ReadBuildInfo(); !ok {
return fmt.Errorf("failed to read build info")
}

b := &strings.Builder{}

b.WriteString(fmt.Sprintf(fmtAutheliaBuildGo, info.GoVersion, info.Main.Path, info.Path))

if len(info.Settings) != 0 {
b.WriteString(" Settings:\n")

for _, setting := range info.Settings {
b.WriteString(fmt.Sprintf(" %s: %s\n", setting.Key, setting.Value))
}
}

if len(info.Deps) != 0 {
b.WriteString(" Dependencies:\n")

for _, dep := range info.Deps {
b.WriteString(fmt.Sprintf(" %s@%s (%s)\n", dep.Path, dep.Version, dep.Sum))
}
}

_, err = fmt.Printf(fmtAutheliaBuild, utils.BuildTag, utils.BuildState, utils.BuildBranch, utils.BuildCommit,
utils.BuildNumber, runtime.GOOS, runtime.GOARCH, utils.BuildDate, utils.BuildExtra)
utils.BuildNumber, runtime.GOOS, runtime.GOARCH, utils.BuildDate, utils.BuildExtra, b.String())

return err
}
7 changes: 7 additions & 0 deletions internal/commands/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Build OS: %s
Build Arch: %s
Build Date: %s
Extra: %s
Go: %s
`
fmtAutheliaBuildGo = `
Version: %s
Module Path: %s
Executable Path: %s
`

cmdAutheliaBuildInfoShort = "Show the build information of Authelia"
Expand Down

0 comments on commit 37ee009

Please sign in to comment.