Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 5 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,7 +93,10 @@ func NewConfig() (*Config, error) {
}

return &Config{
App: app,
App: App{
Name: "kompanion",
Version: version,
},
Auth: auth,
HTTP: http,
Log: log,
Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions docker-compose-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ services:
tmpfs:
- /pgtmpfs

app:
build:
context: .
dockerfile: Dockerfile
args:
- KOMPANION_VERSION=integration

integration:
build:
context: .
Expand Down
10 changes: 10 additions & 0 deletions integration-test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/http/web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewRouter(
p sync.Progress,
shelf library.Shelf,
stats stats.ReadingStats,
version string,
) {
// Options
handler.Use(gin.Logger())
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion web/templates/layouts/master.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<!-- Simple Footer -->
<hr> <!-- Adds a nice divider line -->
<p style="text-align: center; color: var(--text-color-alt);">
Powered by KOmpanion, Version: TDB, Page: <strong>{{ LoadTimes .startTime }}</strong>
Powered by <a href="https://github.com/vanadium23/kompanion/">KOmpanion</a>, Version: <strong>{{ Version }}</strong>, Page: <strong>{{ LoadTimes .startTime }}</strong>
</p>
</footer>

Expand Down
Loading