-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (38 loc) · 1.28 KB
/
Dockerfile
File metadata and controls
59 lines (38 loc) · 1.28 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
ARG PYTHON_VERSION=3.12
ARG PORT=8080
# --- Build stage ---
FROM python:${PYTHON_VERSION}-slim AS builder
ARG PORT
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=${PORT}
WORKDIR /app
# Copy uv from official image for better security and updates
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY pyproject.toml uv.lock* ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-install-project
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked
# --- Runtime stage ---
FROM python:${PYTHON_VERSION}-slim
ARG PORT
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=${PORT} \
PATH="/app/.venv/bin:$PATH"
WORKDIR /app
RUN groupadd -r appuser && \
useradd -r -g appuser -u 1000 -s /sbin/nologin appuser
COPY --from=builder --chown=appuser:appuser /app/.venv /app/.venv
COPY --chown=appuser:appuser . .
RUN chmod -R 555 /app/fq_server && \
chmod 555 /app/*.py && \
chmod 444 /app/default.conf /app/pyproject.toml
USER appuser
EXPOSE ${PORT}
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import httpx; httpx.get('http://127.0.0.1:${PORT}/metrics/')" || exit 1
ENTRYPOINT ["sh", "-c"]
CMD ["exec uvicorn asgi:app --host 0.0.0.0 --port ${PORT}"]