diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2021-06-18 14:35:43 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-18 14:35:43 +1000 |
| commit | 0d7b33022c659444617d15c95c3cbfc66561689b (patch) | |
| tree | e06f6f06260136d18301df2bfa17b47945a5ef88 /cmd/authelia-scripts/helpers.go | |
| parent | ef3c2faeb5a8d4ae30fa55fdaed5718e32f11364 (diff) | |
build: add enhanced information (#2067)
This commit adjusts the build flags to include version information in the LDFLAGS using the -X options. Additionally this makes the information recorded at build time more comprehensive. All build information can now be obtained via the `authelia build` command, and the `authelia version` command is now `authelia --version`. Lastly this adjusts the Dockerfile to utilize docker cache more effectively.
Diffstat (limited to 'cmd/authelia-scripts/helpers.go')
| -rw-r--r-- | cmd/authelia-scripts/helpers.go | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/cmd/authelia-scripts/helpers.go b/cmd/authelia-scripts/helpers.go new file mode 100644 index 000000000..2b71d1e65 --- /dev/null +++ b/cmd/authelia-scripts/helpers.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "strings" + "time" + + "github.com/authelia/authelia/internal/utils" +) + +func getXFlags(branch, build, extra string) (flags []string, err error) { + if branch == "" { + out, _, err := utils.RunCommandAndReturnOutput("git rev-parse --abbrev-ref HEAD") + if err != nil { + return flags, err + } + + if out == "" { + branch = "master" + } else { + branch = out + } + } + + gitTagCommit, _, err := utils.RunCommandAndReturnOutput("git rev-list --tags --max-count=1") + if err != nil { + return flags, err + } + + tag, _, err := utils.RunCommandAndReturnOutput("git describe --tags --abbrev=0 " + gitTagCommit) + if err != nil { + return flags, err + } + + commit, _, err := utils.RunCommandAndReturnOutput("git rev-parse HEAD") + if err != nil { + return flags, err + } + + var states []string + + if gitTagCommit == commit { + states = append(states, "tagged") + } else { + states = append(states, "untagged") + } + + if _, exitCode, _ := utils.RunCommandAndReturnOutput("git diff --quiet"); exitCode != 0 { + states = append(states, "dirty") + } else { + states = append(states, "clean") + } + + if build == "" { + build = "manual" + } + + return []string{ + fmt.Sprintf(fmtLDFLAGSX, "BuildBranch", branch), + fmt.Sprintf(fmtLDFLAGSX, "BuildTag", tag), + fmt.Sprintf(fmtLDFLAGSX, "BuildCommit", commit), + fmt.Sprintf(fmtLDFLAGSX, "BuildDate", time.Now().Format("Mon, 02 Jan 2006 15:04:05 -0700")), + fmt.Sprintf(fmtLDFLAGSX, "BuildState", strings.Join(states, " ")), + fmt.Sprintf(fmtLDFLAGSX, "BuildExtra", extra), + fmt.Sprintf(fmtLDFLAGSX, "BuildNumber", build), + }, nil +} |
