Merge pull request 'Add version display in UI footer' (#8) from feat/version-display into main
This commit was merged in pull request #8.
This commit is contained in:
@@ -48,6 +48,8 @@ jobs:
|
|||||||
runs-on: games
|
runs-on: games
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0 # Need full history for git describe
|
||||||
|
|
||||||
- name: Sync to deploy directory
|
- name: Sync to deploy directory
|
||||||
run: |
|
run: |
|
||||||
@@ -59,4 +61,8 @@ jobs:
|
|||||||
mkdir -p $DEPLOY_DIR/data
|
mkdir -p $DEPLOY_DIR/data
|
||||||
|
|
||||||
- name: Rebuild and restart
|
- name: Rebuild and restart
|
||||||
run: cd $DEPLOY_DIR && docker compose up -d --build --remove-orphans
|
run: |
|
||||||
|
cd $DEPLOY_DIR
|
||||||
|
VERSION=$(git describe --tags --always)
|
||||||
|
COMMIT=$(git rev-parse --short HEAD)
|
||||||
|
VERSION=$VERSION COMMIT=$COMMIT docker compose up -d --build --remove-orphans
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
FROM docker.io/golang:1.25.4-alpine AS build
|
FROM docker.io/golang:1.25.4-alpine AS build
|
||||||
|
|
||||||
|
ARG VERSION=dev
|
||||||
|
ARG COMMIT=unknown
|
||||||
|
|
||||||
RUN apk add --no-cache upx
|
RUN apk add --no-cache upx
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
@@ -10,7 +13,8 @@ COPY . .
|
|||||||
RUN go tool templ generate
|
RUN go tool templ generate
|
||||||
RUN go tool gotailwind -i assets/css/input.css -o assets/css/output.css --minify
|
RUN go tool gotailwind -i assets/css/input.css -o assets/css/output.css --minify
|
||||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
CGO_ENABLED=0 go build -ldflags="-s" -o /bin/games .
|
MODULE=$(head -1 go.mod | awk '{print $2}') && \
|
||||||
|
CGO_ENABLED=0 go build -ldflags="-s -X $MODULE/version.Version=$VERSION -X $MODULE/version.Commit=$COMMIT" -o /bin/games .
|
||||||
RUN upx -9 -k /bin/games
|
RUN upx -9 -k /bin/games
|
||||||
|
|
||||||
FROM scratch
|
FROM scratch
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
services:
|
services:
|
||||||
games:
|
games:
|
||||||
build: .
|
build:
|
||||||
|
context: .
|
||||||
|
args:
|
||||||
|
VERSION: ${VERSION:-dev}
|
||||||
|
COMMIT: ${COMMIT:-unknown}
|
||||||
container_name: games
|
container_name: games
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package layouts
|
package layouts
|
||||||
|
|
||||||
import "github.com/ryanhamamura/games/config"
|
import (
|
||||||
|
"github.com/ryanhamamura/games/config"
|
||||||
|
"github.com/ryanhamamura/games/version"
|
||||||
|
)
|
||||||
|
|
||||||
templ Base(title string) {
|
templ Base(title string) {
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -16,6 +19,9 @@ templ Base(title string) {
|
|||||||
<div data-init="@get('/reload', {retryMaxCount: 1000, retryInterval:20, retryMaxWaitMs:200})"></div>
|
<div data-init="@get('/reload', {retryMaxCount: 1000, retryInterval:20, retryMaxWaitMs:200})"></div>
|
||||||
}
|
}
|
||||||
{ children... }
|
{ children... }
|
||||||
|
<footer class="fixed bottom-1 right-2 text-xs text-gray-500">
|
||||||
|
{ version.Version }
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
}
|
}
|
||||||
|
|||||||
3
main.go
3
main.go
@@ -20,6 +20,7 @@ import (
|
|||||||
"github.com/ryanhamamura/games/router"
|
"github.com/ryanhamamura/games/router"
|
||||||
"github.com/ryanhamamura/games/sessions"
|
"github.com/ryanhamamura/games/sessions"
|
||||||
"github.com/ryanhamamura/games/snake"
|
"github.com/ryanhamamura/games/snake"
|
||||||
|
"github.com/ryanhamamura/games/version"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/go-chi/chi/v5/middleware"
|
"github.com/go-chi/chi/v5/middleware"
|
||||||
@@ -45,7 +46,7 @@ func main() {
|
|||||||
func run(ctx context.Context) error {
|
func run(ctx context.Context) error {
|
||||||
cfg := config.Global
|
cfg := config.Global
|
||||||
addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
|
addr := fmt.Sprintf("%s:%s", cfg.Host, cfg.Port)
|
||||||
slog.Info("server starting", "addr", addr)
|
slog.Info("server starting", "addr", addr, "version", version.Version, "commit", version.Commit)
|
||||||
defer slog.Info("server shutdown complete")
|
defer slog.Info("server shutdown complete")
|
||||||
|
|
||||||
eg, egctx := errgroup.WithContext(ctx)
|
eg, egctx := errgroup.WithContext(ctx)
|
||||||
|
|||||||
10
version/version.go
Normal file
10
version/version.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// Package version holds build-time version information injected via ldflags.
|
||||||
|
package version
|
||||||
|
|
||||||
|
// Version and Commit are set at build time via:
|
||||||
|
//
|
||||||
|
// -ldflags "-X github.com/ryanhamamura/games/version.Version=... -X github.com/ryanhamamura/games/version.Commit=..."
|
||||||
|
var (
|
||||||
|
Version = "dev"
|
||||||
|
Commit = "unknown"
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user