NoteDiscovery/Dockerfile

83 lines
2.6 KiB
Docker
Raw Normal View History

2026-03-12 10:10:58 +00:00
# Stage 1: Minify frontend assets
FROM node:20-alpine AS minifier
WORKDIR /build
# Install minification tools (esbuild for JS, html-minifier-terser for HTML)
RUN npm install -g esbuild html-minifier-terser
# Copy frontend files
COPY frontend/ ./frontend/
# Minify JavaScript (esbuild is ~100x faster than terser)
RUN esbuild frontend/app.js --minify --outfile=frontend/app.js --allow-overwrite && \
esbuild frontend/sw.js --minify --outfile=frontend/sw.js --allow-overwrite
# Minify HTML files (handles inline CSS and JS too)
RUN html-minifier-terser \
--collapse-whitespace \
--remove-comments \
--remove-redundant-attributes \
--minify-css true \
--minify-js true \
-o frontend/index.html \
frontend/index.html && \
html-minifier-terser \
--collapse-whitespace \
--remove-comments \
--minify-css true \
--minify-js true \
-o frontend/login.html \
frontend/login.html
# Stage 2: Install Python dependencies
2025-11-11 10:24:43 +00:00
FROM python:3.11-slim AS builder
2025-11-05 16:48:41 +00:00
WORKDIR /app
2025-11-11 11:22:03 +00:00
# Install Python packages
2025-11-05 16:48:41 +00:00
COPY requirements.txt .
2025-11-11 11:22:03 +00:00
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir --prefix=/install -r requirements.txt && \
# Clean up unnecessary files to reduce image size
find /install -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /install -type f -name "*.pyc" -delete && \
find /install -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true && \
find /install -type d -name "*.dist-info" -exec rm -rf {}/RECORD {} + 2>/dev/null || true
2026-03-12 10:10:58 +00:00
# Stage 3: Final minimal image
2025-11-11 10:24:43 +00:00
FROM python:3.11-slim
WORKDIR /app
2025-11-11 11:22:03 +00:00
# Copy only installed packages (no pip cache, no build artifacts)
COPY --from=builder /install /usr/local
2025-11-05 16:48:41 +00:00
2026-03-12 10:10:58 +00:00
# Copy minified frontend from minifier stage
COPY --from=minifier /build/frontend ./frontend
# Copy other application files
2025-11-05 16:48:41 +00:00
COPY backend ./backend
COPY config.yaml .
COPY VERSION .
2025-11-05 16:48:41 +00:00
COPY plugins ./plugins
COPY themes ./themes
COPY locales ./locales
2025-11-05 16:48:41 +00:00
# Create data directory
RUN mkdir -p data
2025-11-05 16:48:41 +00:00
# Expose port (default, can be overridden)
2025-11-05 16:48:41 +00:00
EXPOSE 8000
# Set default port (can be overridden via environment variable)
ENV PORT=8000
# Health check (uses PORT env var)
2025-11-11 11:22:03 +00:00
HEALTHCHECK --interval=60s --timeout=3s --start-period=5s --retries=3 \
CMD python -c "import os, urllib.request; urllib.request.urlopen(f'http://localhost:{os.getenv(\"PORT\", \"8000\")}/health')"
2025-11-05 16:48:41 +00:00
# Run the application (shell form to allow environment variable expansion)
2026-02-02 17:33:53 +00:00
# Use exec to replace shell with uvicorn (receives SIGTERM directly for graceful shutdown)
CMD exec uvicorn backend.main:app --host 0.0.0.0 --port $PORT --timeout-graceful-shutdown 2