-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
69 lines (50 loc) · 1.8 KB
/
Dockerfile
File metadata and controls
69 lines (50 loc) · 1.8 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
# Multi-stage Dockerfile for AI-CoScientist
# Optimized for production deployment with Python 3.11+
ARG PYTHON_VERSION=3.11
# Stage 1: Builder - Install dependencies
FROM python:${PYTHON_VERSION}-slim as builder
# Set working directory
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install --no-cache-dir poetry==1.7.1
# Copy dependency files
COPY pyproject.toml poetry.lock ./
# Configure Poetry to not create virtual environment
RUN poetry config virtualenvs.create false
# Install Python dependencies
RUN poetry install --no-dev --no-interaction --no-ansi
# Stage 2: Runtime
FROM python:${PYTHON_VERSION}-slim
# Set working directory
WORKDIR /app
# Install runtime system dependencies
RUN apt-get update && apt-get install -y \
curl \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user for security
RUN useradd -m -u 1000 coscientist && \
chown -R coscientist:coscientist /app
# Copy Python packages from builder
COPY --from=builder /usr/local/lib/python${PYTHON_VERSION}/site-packages /usr/local/lib/python${PYTHON_VERSION}/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY --chown=coscientist:coscientist . .
# Create necessary directories
RUN mkdir -p /app/papers_collection /app/logs && \
chown -R coscientist:coscientist /app/papers_collection /app/logs
# Switch to non-root user
USER coscientist
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/api/v1/health || exit 1
# Default command (can be overridden in docker-compose)
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]