-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
60 lines (46 loc) · 1.3 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Build stage
FROM python:3.12-slim AS builder
# Install uv
COPY --from=ghcr.io/astral-sh/uv:0.5.21 /uv /uvx /bin/
# Change to app directory
WORKDIR /app
# Install build dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
libgomp1 \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Create venv and install dependencies
RUN uv venv
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"
# Copy dependency files first
COPY pyproject.toml uv.lock ./
# Install using uv sync which handles git dependencies better
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync
# Copy the project files
COPY . .
# Runtime stage
FROM python:3.12-slim
WORKDIR /app
# Install runtime dependencies and copy uv
COPY --from=ghcr.io/astral-sh/uv:0.5.21 /uv /uvx /bin/
RUN apt-get update && \
apt-get install -y --no-install-recommends \
git \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Copy application files first (needed for uv sync)
COPY . .
# Create fresh venv in runtime and install from lock file
RUN uv venv && \
uv sync --frozen
# Set environment variables
ENV VIRTUAL_ENV=/app/.venv
ENV PATH="/app/.venv/bin:$PATH"
ENV PYTHONUNBUFFERED=1
# Use uv run for the default command
# CMD ["uv", "run", "python", "-m", "predict"]
CMD ["/bin/bash"]