39 lines
1.5 KiB
Docker
39 lines
1.5 KiB
Docker
# syntax=docker/dockerfile:1
|
|
|
|
# --- Dépendances --------------------------------------------------------------
|
|
FROM python:3.12-slim AS builder
|
|
ENV PIP_NO_CACHE_DIR=1 PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
WORKDIR /build
|
|
COPY requirements.txt .
|
|
RUN python -m venv /opt/venv && /opt/venv/bin/pip install -r requirements.txt
|
|
|
|
# --- Tests (lancés par la CI : docker build --target test) --------------------
|
|
FROM builder AS test
|
|
COPY requirements-dev.txt .
|
|
RUN /opt/venv/bin/pip install -r requirements-dev.txt
|
|
COPY . .
|
|
RUN /opt/venv/bin/ruff check . \
|
|
&& /opt/venv/bin/ruff format --check . \
|
|
&& /opt/venv/bin/pytest -q
|
|
|
|
# --- Image d'exécution ------------------------------------------------------
|
|
FROM python:3.12-slim AS runtime
|
|
ARG APP_VERSION=dev
|
|
ENV PATH=/opt/venv/bin:$PATH \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
APP_VERSION=${APP_VERSION} \
|
|
DATABASE_URL=sqlite:////data/api.db
|
|
RUN groupadd --gid 10001 app \
|
|
&& useradd --uid 10001 --gid app --no-create-home --shell /usr/sbin/nologin app \
|
|
&& mkdir /data && chown app:app /data
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
WORKDIR /app
|
|
COPY app ./app
|
|
COPY web ./web
|
|
USER app
|
|
EXPOSE 8000
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
|
CMD ["python", "-c", "import urllib.request,sys; sys.exit(urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=3).status != 200)"]
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--proxy-headers", "--forwarded-allow-ips", "*"]
|