diff --git a/Dockerfile b/Dockerfile index 37b468b..b1fc0ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,16 +10,17 @@ RUN apk add --update gcc musl-dev COPY --from=modules /go/pkg /go/pkg COPY . /app WORKDIR /app + +ARG KOMPANION_VERSION=local +ENV KOMPANION_VERSION=$KOMPANION_VERSION + RUN GOOS=linux GOARCH=amd64 \ - go build -tags migrate -o /bin/app ./cmd/app + go build -ldflags "-X main.Version=$KOMPANION_VERSION" -tags migrate -o /bin/app ./cmd/app # Step 3: Final FROM golang:1.22.5-alpine ENV GIN_MODE=release -ARG KOMPANION_VERSION=local -ENV KOMPANION_VERSION=$KOMPANION_VERSION - WORKDIR / COPY --from=builder /app/config /config COPY --from=builder /app/migrations /migrations diff --git a/cmd/app/main.go b/cmd/app/main.go index dde959a..0e279b9 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -7,9 +7,11 @@ import ( "github.com/vanadium23/kompanion/internal/app" ) +var Version = "dev" + func main() { // Configuration - cfg, err := config.NewConfig() + cfg, err := config.NewConfig(Version) if err != nil { log.Fatalf("Config error: %s", err) } diff --git a/config/config.go b/config/config.go index 2456854..396e119 100644 --- a/config/config.go +++ b/config/config.go @@ -61,12 +61,7 @@ type ( ) // NewConfig - reads from env, validates and returns the config. -func NewConfig() (*Config, error) { - app, err := readAppConfig() - if err != nil { - return nil, err - } - +func NewConfig(version string) (*Config, error) { auth, err := readAuthConfig() if err != nil { return nil, err @@ -98,7 +93,10 @@ func NewConfig() (*Config, error) { } return &Config{ - App: app, + App: App{ + Name: "kompanion", + Version: version, + }, Auth: auth, HTTP: http, Log: log, @@ -108,13 +106,6 @@ func NewConfig() (*Config, error) { }, nil } -func readAppConfig() (App, error) { - return App{ - Name: "kompanion", - Version: "0.0.1", - }, nil -} - func readAuthConfig() (Auth, error) { username := readPrefixedEnv("AUTH_USERNAME") password := readPrefixedEnv("AUTH_PASSWORD") diff --git a/docker-compose-integration.yml b/docker-compose-integration.yml index 8f65afd..84f5552 100644 --- a/docker-compose-integration.yml +++ b/docker-compose-integration.yml @@ -5,6 +5,13 @@ services: tmpfs: - /pgtmpfs + app: + build: + context: . + dockerfile: Dockerfile + args: + - KOMPANION_VERSION=integration + integration: build: context: . diff --git a/integration-test/integration_test.go b/integration-test/integration_test.go index 5dba4b9..70a137f 100644 --- a/integration-test/integration_test.go +++ b/integration-test/integration_test.go @@ -59,6 +59,16 @@ func healthCheck(attempts int) error { return err } +func TestWebFooterVersion(t *testing.T) { + Test(t, + Description("Footer Version"), + Get(basePath+"/"), + Expect().Status().Equal(http.StatusOK), + Expect().Body().String().Contains("github.com/vanadium23/kompanion"), + Expect().Body().String().Contains("integration"), + ) +} + // New tests based on controller/web // login/page func TestWebAuthUser(t *testing.T) { diff --git a/internal/app/app.go b/internal/app/app.go index b04c59f..dfca835 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -65,7 +65,7 @@ func Run(cfg *config.Config) { // HTTP Server handler := gin.New() - web.NewRouter(handler, l, authService, progress, shelf, rs) + web.NewRouter(handler, l, authService, progress, shelf, rs, cfg.Version) v1.NewRouter(handler, l, authService, progress, shelf) opds.NewRouter(handler, l, authService, progress, shelf) webdav.NewRouter(handler, authService, l, rs, cfg.StatsStorage.Path) diff --git a/internal/controller/http/web/router.go b/internal/controller/http/web/router.go index 0c07570..2871ae3 100644 --- a/internal/controller/http/web/router.go +++ b/internal/controller/http/web/router.go @@ -37,6 +37,7 @@ func NewRouter( p sync.Progress, shelf library.Shelf, stats stats.ReadingStats, + version string, ) { // Options handler.Use(gin.Logger()) @@ -66,6 +67,9 @@ func NewRouter( "LoadTimes": func(startTime time.Time) string { return fmt.Sprint(time.Since(startTime).Nanoseconds()/1e6) + "ms" }, + "Version": func() string { + return template.HTMLEscapeString(version) + }, } handler.HTMLRender = ginview.New(config) diff --git a/web/templates/layouts/master.html b/web/templates/layouts/master.html index a5bc182..f5a280c 100644 --- a/web/templates/layouts/master.html +++ b/web/templates/layouts/master.html @@ -38,7 +38,7 @@

- Powered by KOmpanion, Version: TDB, Page: {{ LoadTimes .startTime }} + Powered by KOmpanion, Version: {{ Version }}, Page: {{ LoadTimes .startTime }}