From 6ec6234a7584024f233bde4a446842697fb6746f Mon Sep 17 00:00:00 2001 From: Gamosoft Date: Thu, 12 Mar 2026 11:10:58 +0100 Subject: [PATCH] minimize for docker image --- Dockerfile | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 814d663..7b9cd61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,36 @@ -# Stage 1: Install dependencies +# 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 FROM python:3.11-slim AS builder WORKDIR /app @@ -13,7 +45,7 @@ RUN pip install --no-cache-dir --upgrade pip && \ 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 -# Stage 2: Final minimal image +# Stage 3: Final minimal image FROM python:3.11-slim WORKDIR /app @@ -21,9 +53,11 @@ WORKDIR /app # Copy only installed packages (no pip cache, no build artifacts) COPY --from=builder /install /usr/local -# Copy application files +# Copy minified frontend from minifier stage +COPY --from=minifier /build/frontend ./frontend + +# Copy other application files COPY backend ./backend -COPY frontend ./frontend COPY config.yaml . COPY VERSION . COPY plugins ./plugins @@ -47,4 +81,3 @@ HEALTHCHECK --interval=60s --timeout=3s --start-period=5s --retries=3 \ # Run the application (shell form to allow environment variable expansion) # 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 -