-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
177 lines (138 loc) · 4.55 KB
/
Dockerfile
File metadata and controls
177 lines (138 loc) · 4.55 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# Multi-stage build for optimized DiffML Docker image
# Supports both CPU and GPU (CUDA) environments
# Build stage
FROM python:3.11-slim as builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
POETRY_VERSION=1.7.0 \
POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1
# Install system dependencies and Poetry
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
git \
&& curl -sSL https://install.python-poetry.org | python3 - \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Add Poetry to PATH
ENV PATH="$POETRY_HOME/bin:$PATH"
# Set working directory
WORKDIR /app
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Install dependencies
RUN poetry install --no-root --no-dev
# Copy source code
COPY src ./src
COPY scripts ./scripts
COPY configs ./configs
# Install the package
RUN poetry install --no-dev
# Runtime stage - CPU version
FROM python:3.11-slim as cpu-runtime
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH"
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -m -u 1000 diffml && \
mkdir -p /app /data /results && \
chown -R diffml:diffml /app /data /results
# Set working directory
WORKDIR /app
# Copy from builder
COPY --from=builder --chown=diffml:diffml /app/.venv /app/.venv
COPY --from=builder --chown=diffml:diffml /app/src ./src
COPY --from=builder --chown=diffml:diffml /app/scripts ./scripts
COPY --from=builder --chown=diffml:diffml /app/configs ./configs
# Copy additional files
COPY --chown=diffml:diffml README.md ./
COPY --chown=diffml:diffml notebooks ./notebooks
COPY --chown=diffml:diffml tests ./tests
# Switch to non-root user
USER diffml
# Set volumes for data and results
VOLUME ["/data", "/results"]
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import diffml; print('OK')" || exit 1
# Default command
CMD ["python", "-c", "import diffml; print('DiffML container ready!')"]
# GPU runtime stage - CUDA version
FROM nvidia/cuda:12.1.0-cudnn8-runtime-ubuntu22.04 as gpu-runtime
# Install Python 3.11
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3.11-venv \
python3-pip \
libgomp1 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /usr/bin/python3.11 /usr/bin/python
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/app/.venv/bin:$PATH" \
CUDA_VISIBLE_DEVICES=0
# Create non-root user
RUN useradd -m -u 1000 diffml && \
mkdir -p /app /data /results && \
chown -R diffml:diffml /app /data /results
# Set working directory
WORKDIR /app
# Copy from builder
COPY --from=builder --chown=diffml:diffml /app/.venv /app/.venv
COPY --from=builder --chown=diffml:diffml /app/src ./src
COPY --from=builder --chown=diffml:diffml /app/scripts ./scripts
COPY --from=builder --chown=diffml:diffml /app/configs ./configs
# Copy additional files
COPY --chown=diffml:diffml README.md ./
COPY --chown=diffml:diffml notebooks ./notebooks
COPY --chown=diffml:diffml tests ./tests
# Switch to non-root user
USER diffml
# Set volumes
VOLUME ["/data", "/results"]
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import torch; print(f'CUDA available: {torch.cuda.is_available()}')" || exit 1
# Default command
CMD ["python", "-c", "import torch; import diffml; print(f'DiffML GPU container ready! CUDA: {torch.cuda.is_available()}')"]
# Development stage with Jupyter
FROM cpu-runtime as development
USER root
# Install development dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
vim \
less \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Jupyter and additional packages
RUN /app/.venv/bin/pip install --no-cache-dir \
jupyter \
jupyterlab \
notebook \
ipywidgets \
matplotlib \
seaborn \
plotly \
streamlit
# Create Jupyter configuration
RUN mkdir -p /home/diffml/.jupyter && \
chown -R diffml:diffml /home/diffml/.jupyter
USER diffml
# Expose ports
EXPOSE 8888 8501 6006
# Jupyter command
CMD ["jupyter", "lab", "--ip=0.0.0.0", "--port=8888", "--no-browser", "--allow-root"]