From 88a82f887f20059fad6a45a7fc11326f2b4591d8 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Wed, 31 Dec 2025 00:47:01 +0100 Subject: [PATCH] update dockerfile, css build and alpine images --- Dockerfile | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index de1f68d..0717d66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,34 @@ -FROM python:3.11-slim +# --- STAGE 1: CSS Builder --- +FROM node:18-alpine AS css-builder +WORKDIR /app +COPY package*.json tailwind.config.js ./ +COPY ./static/src/input.css ./static/src/input.css +COPY ./templates ./templates +RUN npm install && npx tailwindcss -i ./static/src/input.css -o ./static/dist/css/output.css --minify +# --- STAGE 2: Final App (Python) --- + -ENV PYTHONDONTWRITEBYTECODE 1 -ENV PYTHONUNBUFFERED 1 +# --- STAGE 2: Python Builder (Compile dependencies) --- +FROM python:3.11-alpine AS py-builder +WORKDIR /app +COPY requirements.txt . +# Install into a local folder to copy easily +RUN pip install --prefix=/install --no-cache-dir -r requirements.txt +# --- STAGE 3: Final Minimal Image --- +FROM python:3.11-alpine WORKDIR /app -RUN apt-get update && apt-get install -y --no-install-recommends \ - build-essential \ - && rm -rf /var/lib/apt/lists/* - -COPY requirements.txt . -RUN pip install --no-cache-dir -r requirements.txt +# Copy only the installed python packages from py-builder +COPY --from=py-builder /install /usr/local +# Copy only the compiled CSS from css-builder +COPY --from=css-builder /app/static/dist/css/output.css ./static/dist/css/output.css +# Copy application code COPY . . -EXPOSE 5000 - +# Clean up any unneeded source files to save space +RUN rm -rf static/src tailwind.config.js package*.json requirements.txt # Initialize DB, then start Gunicorn CMD python -c "from app import app, db; app.app_context().push(); db.create_all()" && \ gunicorn --bind 0.0.0.0:5000 app:app \ No newline at end of file