# --- STAGE 1: CSS Builder --- FROM node:18-alpine AS css-builder WORKDIR /app COPY package.json ./ COPY 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) --- # --- 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 # 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 . . # 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