-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
44 lines (29 loc) · 1.07 KB
/
Dockerfile
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
# Base image for building the virtual environment
FROM python:3.11-bookworm AS builder
ENV PATH="/root/.cargo/bin:$PATH" \
UV_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple" \
PIP_INDEX_URL="https://mirrors.cernet.edu.cn/pypi/web/simple"
# Install uv and tools
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
WORKDIR /app
COPY pyproject.toml .
# Create and install dependencies in the virtual environment
RUN uv sync
# Separate stage for validation (build and test)
FROM builder AS validator
WORKDIR /app
COPY . .
# Run build and test as part of the validation
RUN make build && make test
# Final image for running the application
FROM python:3.11-slim-bookworm
LABEL author="X Author Name"
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
WORKDIR /app
# Copy the virtual environment and application code
COPY --from=builder /app/.venv /app/.venv
COPY src ./src
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
CMD ["python", "src/example_py/app.py"]