Files
mal/Dockerfile

58 lines
1.4 KiB
Docker

FROM golang:1.25-bookworm AS builder
WORKDIR /app
# Enable CGO for sqlite3
ENV CGO_ENABLED=1
# Install sqlc for code generation
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.30.0
# Install build dependencies for bun + assets
RUN apt-get update && apt-get install -y ca-certificates sqlite3 curl unzip && rm -rf /var/lib/apt/lists/*
RUN curl -fsSL https://bun.sh/install | bash
ENV PATH="/root/.bun/bin:${PATH}"
ENV GOPROXY=direct
COPY go.mod go.sum ./
RUN go mod download
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
# Copy all source files
COPY . .
# Ensure dist is clean at build time (belt + suspenders)
RUN rm -rf dist/ && bun run build:assets
# Generate sqlc code
RUN sqlc generate
# Build the server and CLI tools
RUN go build -ldflags="-s -w" -o main_server ./cmd/server
FROM debian:bookworm-slim
WORKDIR /app
# Required at runtime (sqlite)
RUN apt-get update && apt-get install -y ca-certificates sqlite3 && rm -rf /var/lib/apt/lists/*
# Create data directory for sqlite
RUN mkdir -p /app/data
# Set DATABASE_FILE to use the persistent volume
ENV DATABASE_FILE=/app/data/mal.db
COPY --from=builder /app/main_server .
COPY --from=builder /app/templates ./templates
COPY --from=builder /app/static ./static
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/internal/database/migrations ./migrations
COPY docker/entrypoint.sh ./entrypoint.sh
EXPOSE 3000
ENTRYPOINT ["./entrypoint.sh"]