-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.gpu
More file actions
75 lines (61 loc) · 3.12 KB
/
Copy pathDockerfile.gpu
File metadata and controls
75 lines (61 loc) · 3.12 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
FROM nvidia/cuda:12.6.0-cudnn-devel-ubuntu22.04
# Copy uv binary from official image
COPY --from=ghcr.io/astral-sh/uv:0.11.7 /uv /bin/
WORKDIR /app
# Install native compilation tools
RUN apt-get update && \
apt-get install -y make gcc build-essential vim git openssh-server && \
rm -rf /var/lib/apt/lists/*
# Install python since base image has no python installation
RUN uv python install 3.12
# ARG accepts dynamic versions from CI/CD (e.g., --build-arg BUILD_VERSION=1.2.0).
# Defaults to "0.0.0" for local builds.
ARG BUILD_VERSION=0.0.0
# Hatchling uses hatch-vcs, which delegates Git tag resolution to setuptools_scm under the hood.
# Because .git/ is excluded in .dockerignore (to reduce build context size and maximize cache hits),
# setuptools_scm fails to read repository tags. Setting SETUPTOOLS_SCM_PRETEND_VERSION overrides
# this check and sets the package version to $BUILD_VERSION during `uv sync`.
# In GitHub Actions, BUILD_VERSION is passed dynamically at build time.
ENV SETUPTOOLS_SCM_PRETEND_VERSION=$BUILD_VERSION
# Forces Python to print logs immediately so they appear in real-time without buffering
ENV PYTHONUNBUFFERED=1
# Pre-compiles GPU code for all major NVIDIA generations
ENV TORCH_CUDA_ARCH_LIST="7.5;8.0;8.6;8.9;9.0;10.0"
# Cache layer: install third-party dependencies first
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-install-project --frozen
# Copy source code and perform final package installation
COPY . .
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen
# Install codefinetuner globally as a uv tool
RUN --mount=type=cache,target=/root/.cache/uv \
uv tool install codefinetuner
# Activate tool binaries and project virtual environment globally (for non-SSH containers)
ENV PATH="/root/.local/bin:/app/.venv/bin:$PATH"
# - profile.d: Ensures the 'codefinetuner' tool is found and executable over SSH.
# - .bashrc: Ensures the terminal shell starts directly inside the /app project directory.
RUN echo 'export PATH="/root/.local/bin:/app/.venv/bin:$PATH"' > /etc/profile.d/toolpath.sh && \
echo 'cd /app' >> /root/.bashrc
# SSH Entrypoint:
# 1. 'ssh-keygen -A': Generates unique cryptographic host keys dynamically.
# 2. Key Resolution: Reads 'PUBLIC_KEY' or fallback 'SSH_PUBLIC_KEY'.
# 3. Key Injection: Provisions '/root/.ssh', writes 'authorized_keys' safely via printf, and sets permissions.
# 4. Profile Target configuration: Appends 'cd /app' to the bash profile configuration to land in the workspace immediately on login.
# 5. 'mkdir -p /run/sshd': Creates the privilege-separation directory required by sshd to start.
# 6. '/usr/sbin/sshd': Launches the OpenSSH server daemon on Port 22.
# 7. 'sleep infinity': Keeps the container running.
CMD ["sh", "-c", "\
ssh-keygen -A && \
PUB_KEY=\"${PUBLIC_KEY:-$SSH_PUBLIC_KEY}\" && \
if [ -n \"$PUB_KEY\" ]; then \
mkdir -p /root/.ssh && \
printf '%s\n' \"$PUB_KEY\" >> /root/.ssh/authorized_keys && \
chmod 700 /root/.ssh && \
chmod 600 /root/.ssh/authorized_keys; \
fi && \
mkdir -p /run/sshd && \
/usr/sbin/sshd && \
sleep infinity \
"]