-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (46 loc) · 3.63 KB
/
Dockerfile
File metadata and controls
61 lines (46 loc) · 3.63 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
60
61
# ────────────────────────────────────────────────────────────────────────────┐
FROM python:3.13 AS base
# ────────────────────────────────────────────────────────────────────────────┘
WORKDIR /app
# Install uv.
# Docs: https://docs.astral.sh/uv/#installation
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN sh /uv-installer.sh && rm /uv-installer.sh
ENV PATH="/root/.local/bin/:$PATH"
# Copy only the files necessary for installing Python packages.
COPY pyproject.toml /app
COPY uv.lock /app
EXPOSE 8000
# ────────────────────────────────────────────────────────────────────────────┐
FROM base AS production
# ────────────────────────────────────────────────────────────────────────────┘
# Install Python packages listed in `uv.lock`.
# Docs: https://docs.astral.sh/uv/concepts/projects/sync/#syncing-the-environment
RUN uv sync --all-extras
# Copy all files from the repository into the image.
COPY . /app
# Use Uvicorn to serve the FastAPI application on port 8000, accepting HTTP requests from any host.
CMD [ "uv", "run", "uvicorn", "--app-dir", "/app/src", "server:app", "--host", "0.0.0.0", "--port", "8000" ]
# ────────────────────────────────────────────────────────────────────────────┐
FROM base AS development
# ────────────────────────────────────────────────────────────────────────────┘
# Install Python packages listed in `uv.lock`, including development-specific ones.
# Docs: https://docs.astral.sh/uv/concepts/projects/sync/#syncing-the-environment
RUN uv sync --all-extras --dev
# Copy all files from the repository into the image.
COPY . /app
# Run the FastAPI development server on port 8000, accepting HTTP requests from any host.
# Reference: https://fastapi.tiangolo.com/deployment/manually/
CMD [ "uv", "run", "fastapi", "dev", "--host", "0.0.0.0", "/app/src/server.py" ]
# ────────────────────────────────────────────────────────────────────────────┐
FROM development AS test
# ────────────────────────────────────────────────────────────────────────────┘
# Create a local virtual environment directory
# This is necessary for keeping the test environment isolated from
# running server environment in /app/.venv
RUN mkdir -p /app_venv
ENV VIRTUAL_ENV="/app_venv"
# This target inherits from development and is used for running tests
# No additional setup needed as development already has dev dependencies
# --active flag ensures that the local virtual environment is used
CMD [ "uv", "run", "--active", "pytest", "-v" ]