-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (50 loc) · 2.76 KB
/
Dockerfile
File metadata and controls
60 lines (50 loc) · 2.76 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
# Base image provides Python 3.12 (from runpod/pytorch:1.0.3-cu1281-torch291-ubuntu2204)
FROM runpod/pytorch:1.0.3-cu1281-torch291-ubuntu2204
# Use the base image's Python as-is to preserve pre-installed packages (torch, cuda libs).
# The pytorch base image provides its own Python with torch already installed.
# Symlinking to /usr/bin/python3.X would switch to a bare system Python without torch.
# Validate that the base image provides the expected Python version.
ARG EXPECTED_PYTHON_VERSION=3.12
RUN python --version && \
actual=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')") && \
if [ "$actual" != "$EXPECTED_PYTHON_VERSION" ]; then \
echo "ERROR: Expected Python $EXPECTED_PYTHON_VERSION but base image provides $actual" && exit 1; \
fi
WORKDIR /app
# Prevent interactive prompts during package installation
ENV DEBIAN_FRONTEND=noninteractive
# Set timezone to avoid tzdata prompts
ENV TZ=Etc/UTC
# Enable HuggingFace transfer acceleration
ENV HF_HUB_ENABLE_HF_TRANSFER=1
# Relocate HuggingFace cache outside /root/.cache to exclude from volume sync
ENV HF_HOME=/hf-cache
# Configure APT cache to persist under /root/.cache for volume sync
RUN mkdir -p /root/.cache/apt/archives/partial \
&& echo 'Dir::Cache "/root/.cache/apt";' > /etc/apt/apt.conf.d/01cache
# Install system dependencies and uv
# Note: build-essential not pre-installed to reduce image size (400MB savings)
# Automatic detection will install it when needed (no manual action required)
# Advanced: Users can pre-install via system_dependencies=["build-essential"]
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates git \
&& curl -LsSf https://astral.sh/uv/install.sh | sh \
&& cp ~/.local/bin/uv /usr/local/bin/uv \
&& chmod +x /usr/local/bin/uv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy app code and install dependencies
# Use --python to target the base image's Python (preserves torch in its site-packages)
COPY README.md pyproject.toml uv.lock ./
COPY src/ ./
RUN uv export --format requirements-txt --no-dev --no-hashes > requirements.txt \
&& uv pip install --python $(which python) --break-system-packages -r requirements.txt
# Install numpy for the base image's Python version.
# The runpod/pytorch image ships torch but not numpy. Flash build excludes numpy
# from tarballs (BASE_IMAGE_PACKAGES) to save tarball space (~30 MB), so numpy
# must be provided here in the base image.
RUN python -m pip install --no-cache-dir numpy
# Verify torch and numpy are available from the base image
RUN python -c "import torch; print(f'torch {torch.__version__} CUDA {torch.cuda.is_available()}')" \
&& python -c "import numpy; print(f'numpy {numpy.__version__}')"
CMD ["python", "handler.py"]