Update dockerfile
This commit is contained in:
+34
-11
@@ -1,32 +1,55 @@
|
|||||||
# -------- Stage 1: base --------
|
# --------------------------------------------------
|
||||||
|
# Base Image
|
||||||
|
# --------------------------------------------------
|
||||||
FROM python:3.11-slim
|
FROM python:3.11-slim
|
||||||
|
|
||||||
# -------- Env --------
|
# --------------------------------------------------
|
||||||
|
# Environment
|
||||||
|
# --------------------------------------------------
|
||||||
ENV PYTHONUNBUFFERED=1 \
|
ENV PYTHONUNBUFFERED=1 \
|
||||||
PYTHONDONTWRITEBYTECODE=1
|
PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
# -------- System deps (minimal) --------
|
# --------------------------------------------------
|
||||||
|
# System Dependencies (minimal)
|
||||||
|
# --------------------------------------------------
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
curl \
|
curl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# -------- Workdir --------
|
# --------------------------------------------------
|
||||||
|
# Workdir
|
||||||
|
# --------------------------------------------------
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# -------- Dependencies --------
|
# --------------------------------------------------
|
||||||
|
# Python Dependencies
|
||||||
|
# --------------------------------------------------
|
||||||
COPY requirements.txt .
|
COPY requirements.txt .
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
RUN pip install --no-cache-dir -r requirements.txt
|
||||||
|
|
||||||
# -------- App --------
|
# --------------------------------------------------
|
||||||
COPY app.py .
|
# App
|
||||||
|
# --------------------------------------------------
|
||||||
|
COPY . .
|
||||||
|
|
||||||
# -------- Non-root user --------
|
# --------------------------------------------------
|
||||||
|
# Create cache directory (important!)
|
||||||
|
# --------------------------------------------------
|
||||||
|
RUN mkdir -p /app/cache
|
||||||
|
|
||||||
|
# --------------------------------------------------
|
||||||
|
# Security: Non-root user
|
||||||
|
# --------------------------------------------------
|
||||||
RUN useradd -m appuser
|
RUN useradd -m appuser
|
||||||
USER appuser
|
USER appuser
|
||||||
|
|
||||||
# -------- Healthcheck --------
|
# --------------------------------------------------
|
||||||
|
# Healthcheck
|
||||||
|
# --------------------------------------------------
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
|
||||||
CMD curl -f http://localhost:5000/healthz || exit 1
|
CMD curl -f http://localhost:5000/healthz || exit 1
|
||||||
|
|
||||||
# -------- Run --------
|
# --------------------------------------------------
|
||||||
CMD ["python", "app.py"]
|
# Start (Production)
|
||||||
|
# --------------------------------------------------
|
||||||
|
CMD ["gunicorn", "-w", "2", "-k", "gthread", "-t", "60", "-b", "0.0.0.0:5000", "app:app"]
|
||||||
|
|||||||
Reference in New Issue
Block a user