forked from Traqora/astroml
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
252 lines (196 loc) · 8.38 KB
/
Dockerfile
File metadata and controls
252 lines (196 loc) · 8.38 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# Multi-stage Dockerfile for AstroML with Feature Store
# This Dockerfile creates optimized images for development, testing, and production
# Includes comprehensive Feature Store implementation with caching and versioning
# ============================================================================
# BASE STAGE - Common dependencies and Python environment
# ============================================================================
# Pin the Python base image to an exact patch + distro (#196) so a rebuild
# six months from now produces the same intermediate layers. The slim
# bookworm tag is roughly 60% smaller than the default `python:3.11` image.
FROM python:3.11.9-slim-bookworm AS base
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
ASTROML_ENV=container \
FEATURE_STORE_PATH=/app/feature_store
# Install system dependencies. `--no-install-recommends` skips the long tail
# of suggested packages (man-db, locales, etc.) that ship with apt's default
# recommend resolution and add ~80MB to the image (#196).
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
git \
postgresql-client \
redis-tools \
netcat-openbsd \
jq \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create app user
RUN groupadd -r astroml && useradd -r -g astroml astroml
# Set working directory
WORKDIR /app
# Copy and install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# ============================================================================
# INGESTION STAGE - Optimized for data ingestion and streaming with Feature Store
# ============================================================================
FROM base AS ingestion
# Install additional dependencies for ingestion.
RUN apt-get update && apt-get install -y --no-install-recommends \
jq \
netcat-openbsd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Copy application code
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml migrations/ ./migrations/
COPY --chown=astroml:astroml docs/ ./docs/
COPY --chown=astroml:astroml examples/ ./examples/
# Create necessary directories
RUN mkdir -p /app/logs /app/data /app/feature_store && \
chown -R astroml:astroml /app
# Switch to non-root user
USER astroml
# Expose ports for health checks and monitoring
EXPOSE 8000 8080
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import astroml.ingestion; import astroml.features" || exit 1
# Default command for ingestion
CMD ["python", "-m", "astroml.ingestion"]
# ============================================================================
# TRAINING STAGE - Optimized for ML training with GPU support
# ============================================================================
FROM nvidia/cuda:12.1-runtime-base-ubuntu22.04 AS training-base
# Install Python and system dependencies.
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3.11-pip \
python3.11-dev \
build-essential \
curl \
git \
postgresql-client \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Create symbolic links for python
RUN ln -s /usr/bin/python3.11 /usr/bin/python && \
ln -s /usr/bin/pip3 /usr/bin/pip
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
CUDA_VISIBLE_DEVICES=0
# Create app user
RUN groupadd -r astroml && useradd -r -g astroml astroml
# Set working directory
WORKDIR /app
# Copy and install Python dependencies
COPY requirements.txt .
RUN pip install --upgrade pip && \
pip install -r requirements.txt
# Install PyTorch with CUDA support
RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# Install PyTorch Geometric with CUDA support
RUN pip install torch-geometric torch-scatter torch-sparse torch-cluster torch-spline-conv -f https://data.pyg.org/whl/torch-2.1.0+cu121.html
# Copy application code
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml docs/ ./docs/
COPY --chown=astroml:astroml examples/ ./examples/
# Create necessary directories
RUN mkdir -p /app/models /app/data /app/logs /app/feature_store && \
chown -R astroml:astroml /app
# Switch to non-root user
USER astroml
# Expose port for monitoring (TensorBoard, etc.)
EXPOSE 6006
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import torch; import torch_geometric; import astroml.features" || exit 1
# Default command for training
CMD ["python", "-m", "astroml.training.train_gcn"]
# ============================================================================
# CPU-ONLY TRAINING STAGE - For environments without GPU
# ============================================================================
FROM base as training-cpu
# Copy application code
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml docs/ ./docs/
COPY --chown=astroml:astroml examples/ ./examples/
# Create necessary directories
RUN mkdir -p /app/models /app/data /app/logs /app/feature_store && \
chown -R astroml:astroml /app
# Switch to non-root user
USER astroml
# Expose port for monitoring
EXPOSE 6006
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import torch; import torch_geometric; import astroml.features" || exit 1
# Default command for training
CMD ["python", "-m", "astroml.training.train_gcn"]
# ============================================================================
# DEVELOPMENT STAGE - Includes development tools and testing
# ============================================================================
FROM base as development
# Install development dependencies
RUN pip install pytest pytest-asyncio pytest-cov black flake8 mypy jupyter
# Copy application code
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml tests/ ./tests/
COPY --chown=astroml:astroml migrations/ ./migrations/
COPY --chown=astroml:astroml docs/ ./docs/
COPY --chown=astroml:astroml examples/ ./examples/
# Create necessary directories
RUN mkdir -p /app/logs /app/data /app/notebooks /app/feature_store && \
chown -R astroml:astroml /app
# Switch to non-root user
USER astroml
# Expose ports for development
EXPOSE 8000 8080 8888 6006
# Default command for development
CMD ["python", "-m", "pytest", "tests/", "-v"]
# ============================================================================
# FEATURE STORE STAGE - Dedicated Feature Store service
# ============================================================================
FROM base as feature-store
# Copy application code
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml docs/ ./docs/
COPY --chown=astroml:astroml examples/ ./examples/
# Create necessary directories
RUN mkdir -p /app/logs /app/data /app/feature_store && \
chown -R astroml:astroml /app
# Switch to non-root user
USER astroml
# Expose ports for Feature Store API
EXPOSE 8000 8080
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import astroml.features; from astroml.features import create_feature_store" || exit 1
# Default command for Feature Store service
CMD ["python", "-c", "from astroml.features import create_feature_store; store = create_feature_store('/app/feature_store'); print('Feature Store service ready')"]
# ============================================================================
# PRODUCTION STAGE - Minimal production image
# ============================================================================
FROM base as production
# Copy only necessary files for production
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml docs/ ./docs/
# Create necessary directories
RUN mkdir -p /app/logs /app/data /app/feature_store && \
chown -R astroml:astroml /app
# Switch to non-root user
USER astroml
# Add health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import astroml; import astroml.features" || exit 1
# Default production command (can be overridden)
CMD ["python", "-m", "astroml.ingestion"]