- rewrite docker.sh with gpu default and --no-gpu override - inject host uid/gid via ASTRAI_UID/GID in train.sh compose() - filter readonly UID/GID lines when sourcing .env.train - build image user via USER_UID/USER_GID args matching host uid/gid - pass all GPUs (count: all) and filter by CUDA_VISIBLE_DEVICES inside the container - forward NCCL vars through compose environment
70 lines
1.8 KiB
Docker
70 lines
1.8 KiB
Docker
# AstrAI Dockerfile - Multi-stage Build (Optimized)
|
|
#
|
|
# CUDA version selection:
|
|
# docker build -t astrai .
|
|
# docker build -t astrai --build-arg CUDA_TAG=cu128 .
|
|
# docker build -t astrai --build-arg CUDA_TAG=cu130 .
|
|
# Default: cu128
|
|
|
|
# Build stage - use base image with minimal build tools
|
|
FROM ubuntu:24.04 AS builder
|
|
|
|
ARG CUDA_TAG=cu128
|
|
|
|
WORKDIR /app
|
|
|
|
# Install Python 3.12 and minimal build dependencies
|
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
python3.12 \
|
|
python3.12-dev \
|
|
python3.12-venv \
|
|
gcc \
|
|
g++ \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create isolated virtual environment
|
|
RUN python3.12 -m venv --copies /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Copy source code and install (deps read from pyproject.toml)
|
|
COPY astrai/ ./astrai/
|
|
COPY csrc/ ./csrc/
|
|
COPY setup.py .
|
|
COPY pyproject.toml .
|
|
RUN pip install --no-cache-dir --upgrade pip \
|
|
&& pip install --no-cache-dir . \
|
|
--extra-index-url "https://download.pytorch.org/whl/${CUDA_TAG}"
|
|
|
|
# Production stage
|
|
FROM ubuntu:24.04 AS production
|
|
|
|
WORKDIR /app
|
|
|
|
# Install Python 3.12 runtime and healthcheck dependency
|
|
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
|
python3.12 \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy virtual environment from builder
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Copy application code
|
|
COPY astrai/ ./astrai/
|
|
COPY scripts/ ./scripts/
|
|
COPY docs/ ./docs/
|
|
COPY pyproject.toml .
|
|
COPY README.md .
|
|
|
|
# Create non-root user matching the host uid/gid (passed via build args)
|
|
ARG USER_UID=1000
|
|
ARG USER_GID=1000
|
|
RUN groupadd -g "${USER_GID}" astrai \
|
|
&& useradd -m -u "${USER_UID}" -g astrai astrai \
|
|
&& chown -R astrai:astrai /app
|
|
ENV HOME=/home/astrai
|
|
USER astrai
|
|
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 |