-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathDockerfile
More file actions
201 lines (152 loc) · 5.98 KB
/
Dockerfile
File metadata and controls
201 lines (152 loc) · 5.98 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
# Multi-stage Dockerfile for AstroML
# This Dockerfile creates optimized images for both ingestion and training environments
# ============================================================================
# BASE STAGE - Common dependencies and Python environment
# ============================================================================
FROM python:3.11-slim as base
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
postgresql-client \
&& 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
# ============================================================================
FROM base as ingestion
# Install additional dependencies for ingestion
RUN apt-get update && apt-get install -y \
jq \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*
# Copy application code
COPY --chown=astroml:astroml astroml/ ./astroml/
COPY --chown=astroml:astroml migrations/ ./migrations/
# Create necessary directories
RUN mkdir -p /app/logs /app/data && \
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" || 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 \
python3.11 \
python3.11-pip \
python3.11-dev \
build-essential \
curl \
git \
postgresql-client \
&& 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/
# Create necessary directories
RUN mkdir -p /app/models /app/data /app/logs && \
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" || 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/
# Create necessary directories
RUN mkdir -p /app/models /app/data /app/logs && \
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" || 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/
# Create necessary directories
RUN mkdir -p /app/logs /app/data /app/notebooks && \
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"]
# ============================================================================
# PRODUCTION STAGE - Minimal production image
# ============================================================================
FROM base as production
# Copy only necessary files for production
COPY --chown=astroml:astroml astroml/ ./astroml/
# Create necessary directories
RUN mkdir -p /app/logs /app/data && \
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" || exit 1
# Default production command (can be overridden)
CMD ["python", "-m", "astroml.ingestion"]