build: 修改docker 配置

This commit is contained in:
ViperEkura 2026-04-10 12:53:08 +08:00
parent cb0e7f2a80
commit 0f9e5c5049
1 changed files with 27 additions and 14 deletions

View File

@ -1,40 +1,53 @@
# AstrAI Dockerfile - Minimal # AstrAI Dockerfile - Multi-stage Build (Optimized)
# Build stage # Build stage - use base image with minimal build tools
FROM python:3.12-slim AS builder FROM nvidia/cuda:12.6.0-base-ubuntu24.04 AS builder
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \ # Install Python 3.12 and minimal build dependencies
build-essential \ 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/* && 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 dependencies
COPY astrai/ ./astrai/ COPY astrai/ ./astrai/
COPY pyproject.toml . COPY pyproject.toml .
RUN pip install --no-cache-dir --upgrade pip \ RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir . && pip install --no-cache-dir . \
--extra-index-url https://download.pytorch.org/whl/cu126
# Production stage # Production stage
FROM nvidia/cuda:12.6.0-runtime-ubuntu22.04 AS production FROM nvidia/cuda:12.6.0-base-ubuntu24.04 AS production
WORKDIR /app WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \ # Install Python 3.12 runtime
python3 \ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
libpython3.12 \ python3.12 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages # Copy virtual environment from builder
COPY --from=builder /usr/local/bin /usr/local/bin COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy application code
COPY astrai/ ./astrai/ COPY astrai/ ./astrai/
COPY scripts/ ./scripts/ COPY scripts/ ./scripts/
COPY assets/ ./assets/ COPY assets/ ./assets/
COPY pyproject.toml . COPY pyproject.toml .
COPY README.md . COPY README.md .
RUN useradd -m -u 1000 astrai && chown -R astrai:astrai /app # Create non-root user
RUN useradd -m astrai && chown -R astrai:astrai /app
USER astrai USER astrai
ENV PYTHONUNBUFFERED=1 \ ENV PYTHONUNBUFFERED=1 \