Files
bookhoard/Dockerfile
T
John O'Keefe 902cbe5915 feat(audiobooks): Batch A — foundation, m4b ingest, playback sync, web player
Phase 1 (foundation): 'audiobooks' library type seeded (schema + DB);
audio_metadata JSONB on media_items (the kobo_metadata precedent —
only audio paths read it); reading_progress.audio_offset_seconds for
the honest {chapter, offset} locator; extensions/mimes registered for
ALL breadth formats (m4b/m4a/mp3/flac — deliberate per the DOC/LIT
doctrine, m4b scans richly first); classifyFormatGroup 'audiobook'
case (gotcha 39 recomputes on rescan); Go mime table extended at boot
so media elements accept the streams; ffmpeg/ffprobe in the image
(8.1.2 — also the xHE-AAC identification tripwire).

Phase 2 (ingest): sidecar-first (Libation/ABS metadata.json —
narrators/ASIN/curated chapters), ffprobe fallback/filler (duration,
bitrate, codec/profile, embedded chapters). Fixed three real
parser brittlenesses the Libation sidecar exposed: series accepts
string OR array-of-objects, publishedYear accepts number OR string,
ffprobe chapter timings accept number OR string (flexFloat). Folder-
structure fallback now runs on the UPDATE path too (rescans were
clearing sidecar-absent series/author); audio facts re-derive on
every rescan (gotcha 39).

Phase 3 (playback + sync): GET /api/media-items/:id/chapters (the
format-abstraction list); streaming rides the existing cookie-authed
Range /uploads path; PUT progress carries audio_offset_seconds +
elapsed_seconds (honest wall-clock playing time) — the reading-
history capture prefers player-reported elapsed over the inter-push
delta, same 2h ceiling; reading_mode='audio' marks the row.

Phase 4 (web player): dedicated audio reader page (foliate not
involved) — cover, chapter title, whole-book scrubber, skip ± (chips
1/5/10/15/30s, default 10s), speed (0.75×–2×), chapter list with
jump-to, Media Session lockscreen/notification transport, periodic
playing-only progress pushes, position restore on open.

Verified live: ingest of the Libation sample (Gardens of the Moon —
title/author/series/cover/date from sidecar+folders, 34 chapters,
26h duration, aac/LC); chapters endpoint; the reader route serving
the player; playback with position restore (0:57 round-trip);
progress rows in audio mode; wall-clock session rows in
reading_history.
2026-10-15 16:14:34 -04:00

115 lines
3.8 KiB
Docker

# Build stage
FROM golang:1.26-alpine AS builder
WORKDIR /app
# Install system tools (cached well)
RUN apk add --no-cache nodejs npm curl git
# Install Go tools (cached well)
RUN wget -O /tmp/sqlc.tar.gz https://github.com/sqlc-dev/sqlc/releases/download/v1.31.0/sqlc_1.31.0_linux_amd64.tar.gz && \
tar -xzf /tmp/sqlc.tar.gz -C /usr/local/bin sqlc && \
rm /tmp/sqlc.tar.gz
RUN --mount=type=cache,target=/root/go/pkg/mod \
go install github.com/a-h/templ/cmd/templ@v0.3.1020
# Copy package files and install npm dependencies (cached unless package.json changes)
COPY package*.json ./
# npm cache mount renamed from /root/.npm: the old volume held a stale
# foliate-js tarball (name@version reuse) that --no-cache and builder prune
# could not evict; a new mount id guarantees a clean fetch.
RUN --mount=type=cache,target=/root/.npm-cache2 \
npm install
# Copy Go mod files (cached unless go.mod changes)
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/root/go/pkg/mod \
go mod download
# Copy source code (this layer changes frequently)
COPY . .
# Generate code (only these rebuild on source changes)
RUN cd internal/database && sqlc generate
RUN cd templates && templ generate
# Build frontend assets (only these rebuild on web/ changes)
RUN npm run build:css:prod
RUN npm run build:ts
# App version baked into the binary (shown in Admin → Settings → About).
# Declared after `COPY . .` so a version bump only invalidates this layer.
# The release workflow passes the git tag, e.g. APP_VERSION=v1.5.
ARG APP_VERSION=dev
# Build Go binary (cached unless Go files or generated code changes)
RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo \
-ldflags "-X bookhoard/internal/version.Version=${APP_VERSION}" \
-o main ./cmd/server
# Materialize the Go module cache into an image layer so the test-runner
# stage can restore it. GOMODCACHE is /go/pkg/mod; cache mounts elsewhere are
# ignored by the go tool, and without this copy `go test` in the tests
# container re-downloads every dependency on each invocation.
RUN cp -r /go/pkg/mod /app/go-module-cache
# Test runner stage - includes Go runtime and test dependencies
# This stage is ONLY used for running tests, never deployed to production
FROM golang:1.26-alpine AS test-runner
RUN apk --no-cache add ca-certificates curl poppler-utils
WORKDIR /app
# Copy everything from builder (includes compiled binary, source code, and dependencies)
COPY --from=builder /app ./
# Restore the materialized Go module cache so `go test` works offline.
RUN mkdir -p /go/pkg/mod && cp -r /app/go-module-cache/. /go/pkg/mod/ && rm -rf /app/go-module-cache
# Install kepubify for conversion tests
RUN wget -O /usr/bin/kepubify https://github.com/pgaskin/kepubify/releases/latest/download/kepubify-linux-64bit \
&& chmod +x /usr/bin/kepubify
# Set test environment variables
ENV TEST_MODE=true
ENV RATE_LIMIT_ENABLED=false
ENV REQUESTS_PER_MINUTE=1000
# Default command for running tests
CMD ["go", "test", "./cmd/server/tests", "-v", "-timeout", "5m", "-parallel=1", "-short"]
# Final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates curl poppler-utils ffmpeg
# Install kepubify for EPUB→KEPUB conversion
RUN wget -O /usr/bin/kepubify https://github.com/pgaskin/kepubify/releases/latest/download/kepubify-linux-64bit \
&& chmod +x /usr/bin/kepubify
WORKDIR /root/
# Copy the binary from builder stage
COPY --from=builder /app/main .
# Copy database schema (if needed for initialization)
COPY --from=builder /app/database/schema ./database/schema
# Copy generated templates
COPY --from=builder /app/templates ./templates
# Copy web assets (HTML, CSS, JS, etc.)
COPY --from=builder /app/web ./web
# Copy documentation
COPY --from=builder /app/docs ./docs
# Expose port
EXPOSE 8765
# Run the binary
CMD ["./main"]