forked from jimmc414/Kosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
112 lines (91 loc) · 3.24 KB
/
Copy pathDockerfile
File metadata and controls
112 lines (91 loc) · 3.24 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
# =============================================================================
# Kosmos AI Scientist - Production Dockerfile
# =============================================================================
#
# Multi-stage build for optimized production deployment
#
# Features:
# - Multi-stage build for minimal image size
# - Non-root user for security
# - Health check endpoint
# - Optimized layer caching
# - Production-ready configuration
#
# Build:
# docker build -t kosmos:latest .
#
# Run:
# docker run -p 8000:8000 kosmos:latest
#
# =============================================================================
# =============================================================================
# Stage 1: Builder
# =============================================================================
FROM python:3.11-slim as builder
LABEL maintainer="Kosmos AI Scientist Team"
LABEL description="Autonomous scientific research system"
LABEL version="0.10.0"
# Set working directory
WORKDIR /build
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gcc \
g++ \
git \
&& rm -rf /var/lib/apt/lists/*
# Copy only requirements first (for layer caching)
COPY pyproject.toml README.md ./
# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
pip install --no-cache-dir .
# =============================================================================
# Stage 2: Runtime
# =============================================================================
FROM python:3.11-slim
# Set working directory
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy Python packages from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY kosmos/ /app/kosmos/
COPY alembic/ /app/alembic/
COPY alembic.ini /app/
COPY README.md /app/
# Create necessary directories
RUN mkdir -p /app/data /app/logs /app/cache && \
chmod 755 /app/data /app/logs /app/cache
# Create non-root user for security
RUN useradd --create-home --uid 1000 --shell /bin/bash kosmos && \
chown -R kosmos:kosmos /app
# Switch to non-root user
USER kosmos
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app \
KOSMOS_DATA_DIR=/app/data \
KOSMOS_LOG_DIR=/app/logs \
KOSMOS_CACHE_DIR=/app/cache
# Expose port (if running web service)
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import kosmos; print('healthy')" || exit 1
# Default command
CMD ["python", "-m", "kosmos.cli.main", "--help"]
# =============================================================================
# Build Info
# =============================================================================
#
# Image size: ~400MB (vs ~1GB without multi-stage build)
# Security: Non-root user, minimal attack surface
# Performance: Optimized layer caching for fast rebuilds
#
# =============================================================================