Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (33 loc) · 1.65 KB
/
Copy pathDockerfile
File metadata and controls
39 lines (33 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# One image, four roles: gateway, worker, CV service, and (behind nginx) the page.
# Which role a container plays is decided by its environment and command in
# docker-compose.yml.
FROM python:3.12-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /srv/pond
COPY requirements.txt .
RUN pip install --retries 10 -r requirements.txt \
&& useradd --create-home --uid 1000 pond \
&& mkdir -p /data /srv/pond/.cache && chown pond /data /srv/pond/.cache
COPY app ./app
COPY static ./static
COPY data ./data
USER pond
EXPOSE 5000
# Sized for a 512 MB container (Render's free tier): the contour path's
# four-grid ensemble does not fit, and asking for it gets a 422 rather than an OOM.
ENV POND_API_DEFAULT_ENSEMBLE=false \
POND_API_ALLOW_ENSEMBLE=false \
POND_STORE_PATH=/data/ponds.sqlite3
# glibc gives each threadpool thread its own malloc arena and rarely hands freed NumPy
# buffers back, so a busy CV service sat at 190-355 MB idle and was OOM-killed at 512 MB
# by the next pair of imagery requests. Two arenas keep it at 110-145 MB.
ENV MALLOC_ARENA_MAX=2
HEALTHCHECK --interval=15s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import os,urllib.request; urllib.request.urlopen('http://127.0.0.1:' + os.environ.get('PORT', '5000') + '/health', timeout=2)" || exit 1
# Shell form so $PORT expands: platforms like Render assign the port at runtime and
# route to whatever the container listens on. Local `docker run`/compose leave PORT
# unset and get the same 5000 as before.
CMD uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-5000} --workers 1 --timeout-keep-alive 65