-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.gpu
More file actions
99 lines (77 loc) · 2.98 KB
/
Dockerfile.gpu
File metadata and controls
99 lines (77 loc) · 2.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
# =============================================================================
# NGLab GPU Dockerfile
# CUDA-enabled production image for GPU inference and training
# =============================================================================
ARG CUDA_VERSION=12.1.0
ARG CUDNN_VERSION=8
ARG PYTHON_VERSION=3.11
ARG RUST_VERSION=1.83
# =============================================================================
# Stage 1: Rust Builder (same as production)
# =============================================================================
FROM rust:${RUST_VERSION}-slim-bookworm AS rust-builder
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
libssl-dev \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
COPY rust/ ./rust/
WORKDIR /build/rust
ENV CARGO_INCREMENTAL=0
ENV RUSTFLAGS="-C target-cpu=native -C opt-level=3"
# Removed --locked to handle lockfile synchronization in CI
RUN cargo build --release
# =============================================================================
# Stage 2: CUDA Runtime
# =============================================================================
FROM nvidia/cuda:${CUDA_VERSION}-cudnn${CUDNN_VERSION}-runtime-ubuntu22.04 AS runtime
ARG NGLAB_VERSION=0.1.0
LABEL maintainer="NGLab Team"
LABEL version=${NGLAB_VERSION}
LABEL description="NGLab Trading Bot - GPU Image"
# Create non-root user
RUN groupadd --gid 1000 nglab && \
useradd --uid 1000 --gid nglab --shell /bin/bash --create-home nglab
WORKDIR /app
# Install Python and runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.11 \
python3-pip \
libgomp1 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install PyTorch with CUDA support
RUN pip3 install --no-cache-dir torch torchvision torchaudio \
--index-url https://download.pytorch.org/whl/cu121
# Install remaining dependencies
COPY pyproject.toml ./
RUN pip3 install --no-cache-dir -e ".[gpu]" || pip3 install --no-cache-dir -r pyproject.toml
# Copy Rust library
COPY --from=rust-builder /build/rust/target/release/libnglab.so /usr/local/lib/python3.11/dist-packages/
# Copy application code
COPY --chown=nglab:nglab python/src ./src
COPY --chown=nglab:nglab python/conf ./conf
# Create directories
RUN mkdir -p /app/logs /app/models /app/.cache /tmp/prometheus && \
chown -R nglab:nglab /app /tmp/prometheus
# Environment configuration
ENV PYTHONPATH=/app/src
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV NGLAB_ENV=production
# CUDA configuration
ENV CUDA_HOME=/usr/local/cuda
ENV PATH=${CUDA_HOME}/bin:${PATH}
ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
# Mixed precision defaults
ENV TORCH_CUDNN_V8_API_ENABLED=1
ENV CUDA_MODULE_LOADING=LAZY
# Prometheus multiprocess mode
ENV PROMETHEUS_MULTIPROC_DIR=/tmp/prometheus
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
USER nglab
EXPOSE 8000
CMD ["python3", "-m", "api.main"]