Skip to content

Commit 23918dd

Browse files
committed
impl: show version on login page
1 parent 669238f commit 23918dd

File tree

7 files changed

+44
-11
lines changed

7 files changed

+44
-11
lines changed

.dockerignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
.git
21
.github
32
node_modules
43
docs

.github/workflows/docker.yml

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
- name: Build and push Docker image
6161
uses: docker/build-push-action@v5
6262
with:
63+
context: .
6364
push: true
6465
tags: ${{ steps.meta.outputs.tags }}
6566
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,14 @@ COPY ./go.sum .
1919
RUN go mod download
2020

2121
COPY . .
22+
2223
COPY --from=frontend-builder /build/internal/web/static/styles.css /build/internal/web/static/styles.css
23-
RUN CGO_ENABLED=0 go build -o /build/ldap-passwd
24+
RUN \
25+
PACKAGE="github.com/netresearch/ldap-manager/internal" && \
26+
VERSION="$(git describe --tags --always --abbrev=0 --match='v[0-9]*.[0-9]*.[0-9]*' 2> /dev/null | sed 's/^.//')" && \
27+
COMMIT_HASH="$(git rev-parse --short HEAD)" && \
28+
BUILD_TIMESTAMP=$(date '+%Y-%m-%dT%H:%M:%S') && \
29+
CGO_ENABLED=0 go build -o /build/ldap-passwd -ldflags="-s -w -X '${PACKAGE}.Version=${VERSION}' -X '${PACKAGE}.CommitHash=${COMMIT_HASH}' -X '${PACKAGE}.BuildTimestamp=${BUILD_TIMESTAMP}'"
2430

2531
FROM alpine:3 AS runner
2632

internal/build.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package internal
2+
3+
import "fmt"
4+
5+
var (
6+
Version = "dev"
7+
CommitHash = "n/a"
8+
BuildTimestamp = "n/a"
9+
)
10+
11+
func FormatVersion() string {
12+
if Version == "dev" {
13+
return "Development version"
14+
}
15+
16+
return fmt.Sprintf("%s (%s, built at %s)", Version, CommitHash, BuildTimestamp)
17+
}

internal/web/auth.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package web
22

33
import (
44
"github.com/gofiber/fiber/v2"
5+
"github.com/netresearch/ldap-manager/internal"
56
"github.com/rs/zerolog/log"
67
)
78

@@ -54,5 +55,6 @@ func (a *App) loginHandler(c *fiber.Ctx) error {
5455
"title": "Login",
5556
"headscripts": "",
5657
"flashes": []Flash{},
58+
"version": internal.FormatVersion(),
5759
}, "layouts/base")
5860
}

internal/web/views/login.html

+14-9
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@
3535
Login
3636
</button>
3737

38-
<p class="text-center text-xs text-gray-500">
39-
Powered by
40-
<a
41-
href="https://github.com/netresearch/ldap-manager"
42-
class="break-keep outline-none transition-colors hocus:text-white hocus:underline hocus:decoration-white"
43-
>
44-
netresearch/ldap-manager
45-
</a>
46-
</p>
38+
<div class="text-center text-xs text-gray-500">
39+
<p>
40+
Powered by
41+
42+
<a
43+
href="https://github.com/netresearch/ldap-manager"
44+
class="break-keep outline-none transition-colors hocus:text-white hocus:underline hocus:decoration-white"
45+
>
46+
netresearch/ldap-manager
47+
</a>
48+
</p>
49+
50+
<p>{{ .version }}</p>
51+
</div>
4752
</form>

main.go

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"os"
55

6+
"github.com/netresearch/ldap-manager/internal"
67
"github.com/netresearch/ldap-manager/internal/options"
78
"github.com/netresearch/ldap-manager/internal/web"
89
"github.com/rs/zerolog"
@@ -12,6 +13,8 @@ import (
1213
func main() {
1314
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
1415

16+
log.Info().Msgf("LDAP Manager %s starting...", internal.FormatVersion())
17+
1518
opts := options.Parse()
1619
log.Logger = log.Logger.Level(opts.LogLevel)
1720

0 commit comments

Comments
 (0)