33 lines
1.2 KiB
Docker
33 lines
1.2 KiB
Docker
# Runtime image for the lab3 API. The base tag is pinned; dependencies are
|
|
# installed from requirements.txt, never from a mutable latest tag.
|
|
|
|
FROM python:3.12.7-slim-bookworm
|
|
|
|
ENV PYTHONDONTWRITEBYTECODE=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
WORKDIR /app
|
|
|
|
RUN groupadd --system --gid 10001 app \
|
|
&& useradd --system --uid 10001 --gid app --home-dir /app --shell /usr/sbin/nologin app
|
|
|
|
COPY requirements.txt ./
|
|
RUN python -m pip install --requirement requirements.txt
|
|
|
|
COPY app ./app
|
|
COPY migrations ./migrations
|
|
COPY student-tests ./student-tests
|
|
|
|
USER app
|
|
EXPOSE 8080
|
|
|
|
HEALTHCHECK --interval=5s --timeout=3s --start-period=20s --retries=6 \
|
|
CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health/ready', timeout=2).read()"]
|
|
|
|
# One gunicorn worker with a bounded thread pool per API replica. SIGTERM is
|
|
# handled gracefully: in-flight requests finish before the process exits, so the
|
|
# load balancer can drain the replica during a rolling update.
|
|
CMD ["gunicorn", "--bind=0.0.0.0:8080", "--workers=1", "--threads=16", "--timeout=30", "--graceful-timeout=20", "--keep-alive=5", "--access-logfile=-", "--error-logfile=-", "app.main:app"]
|