-
Notifications
You must be signed in to change notification settings - Fork 20
/
Dockerfile
74 lines (59 loc) · 1.77 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Multi-stage Dockerfile to build a lean Docker image for qabot
# Stage 1: Build stage
FROM python:3.12 AS build
# Install system dependencies
RUN <<EOT
apt-get update -qy
apt-get install -qyy \
-o APT::Install-Recommends=false \
-o APT::Install-Suggests=false \
build-essential \
ca-certificates
rm -rf /var/lib/apt/lists/*
EOT
# Install UV
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set environment variables
ENV UV_LINK_MODE=copy \
UV_COMPILE_BYTECODE=1 \
UV_PYTHON_DOWNLOADS=never \
UV_PYTHON=python3.12 \
UV_PROJECT_ENVIRONMENT=/app
# Set working directory
WORKDIR /app
# Copy pyproject.toml and uv.lock to install dependencies
COPY pyproject.toml /_lock/
COPY uv.lock /_lock/
# Sync dependencies using UV, but don't install the project yet
RUN --mount=type=cache,target=/root/.cache \
cd /_lock && \
uv sync --frozen --no-dev --no-install-project
# Copy the application code to the build stage
COPY . /app
# Install only the application (without dependencies)
RUN --mount=type=cache,target=/root/.cache \
uv pip install --no-deps /app
# Runtime Stage
FROM python:3.12
# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
VIRTUAL_ENV=/app/.venv \
PATH="/app/bin:$PATH"
# Set working directory
WORKDIR /app
# Install runtime dependencies (no build tools or UV)
RUN <<EOT
apt-get update -qy
apt-get install -qyy \
-o APT::Install-Recommends=false \
-o APT::Install-Suggests=false \
python3.12 \
libpython3.12
apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
EOT
# Copy the virtual environment and application from the build stage
COPY --from=build /app /app
# Set the entrypoint to the qabot command line tool
ENTRYPOINT ["python", "-m", "qabot.cli"]