Files
bookhoard/Dockerfile
T
john-okeefe 5d93577078 fix(tests): Add missing addFolderToLibrary call to TestMediaItemISBNNormalization
- TestMediaItemISBNNormalization was missing library folder creation
- Caused HTTP 400 errors when creating media items
- addFolderToLibrary call was accidentally removed from line 73
- Tests now properly create library with folder before adding media items

This fixes the root cause of ISBN normalization test failures where
media-item creation failed due to missing library folder requirement.
2026-02-11 15:32:09 -05:00

94 lines
2.3 KiB
Docker

# Build stage
FROM golang:1.25-alpine AS builder
WORKDIR /app
# Install Node.js, npm, and curl for Tailwind CSS building
RUN apk add --no-cache nodejs npm curl
# Install sqlc
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
# Install templ
RUN go install github.com/a-h/templ/cmd/templ@latest
# Copy package files and install npm dependencies
COPY package*.json ./
RUN npm install
# Copy source code
COPY . .
# Download dependencies
RUN go mod tidy
# Generate sqlc code
RUN cd internal/database && sqlc generate
# Generate templ code
RUN cd templates && templ generate
# Build Tailwind CSS and download htmx
RUN npm run build:css:prod
RUN npm run postinstall
# Build TypeScript to JavaScript
RUN npm run build:ts
# Build the application
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/server
# Test runner stage - includes Go runtime and test dependencies
# This stage is ONLY used for running tests, never deployed to production
FROM golang:1.25-alpine AS test-runner
RUN apk --no-cache add ca-certificates curl
WORKDIR /app
# Copy everything from builder (includes compiled binary, source code, and dependencies)
COPY --from=builder /app ./
# 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"]
# Final stage
FROM alpine:latest
RUN apk --no-cache add ca-certificates curl
# 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"]