-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (42 loc) · 1.82 KB
/
Dockerfile
File metadata and controls
56 lines (42 loc) · 1.82 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
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
# Disable Python downloads, because we want to use the system interpreter
# across both images. If using a managed Python version, it needs to be
# copied from the build image into the final image; see `standalone.Dockerfile`
# for an example.
ENV UV_PYTHON_DOWNLOADS=0
WORKDIR /app
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project --no-dev
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-dev --group=telemetry
FROM python:3.12-slim-bookworm
# It is important to use the image that matches the builder, as the path to the
# Python executable must be the same, e.g., using `python:3.11-slim-bookworm` will fail.
# Set environment variables
ENV LANG=C.UTF-8
ENV LC_ALL=C.UTF-8
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONFAULTHANDLER=1
WORKDIR /app
RUN useradd app; \
apt-get update; \
apt-get install -y --no-install-recommends libpq-dev wget -y; \
rm -rf /var/lib/apt/lists/*
# Copy the virtual environment from the builder
COPY --from=builder --chown=app:app /app/.venv ./.venv/
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:${PATH}"
# Copy the application files
COPY --chown=app:app ./app ./
RUN chmod +x /app/entrypoint.sh
USER app
EXPOSE 8080
# Optional: add a healthcheck (adjust the URL/path to match your app)
HEALTHCHECK --interval=30s --timeout=3s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["opentelemetry-instrument", "uvicorn", "main:app", "--host=0.0.0.0", "--port=8080"]