-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDockerfile.backend
More file actions
116 lines (90 loc) · 4.23 KB
/
Dockerfile.backend
File metadata and controls
116 lines (90 loc) · 4.23 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
113
114
115
# =============================================================================
# Automatos AI - Backend Dockerfile (Multi-stage)
# =============================================================================
# Stages:
# - base: Common dependencies
# - development: Hot-reload, debugging tools
# - production: Optimized, minimal image
# =============================================================================
# =============================================================================
# Base Stage - Common Dependencies
# =============================================================================
FROM python:3.11-slim as base
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
curl \
postgresql-client \
libmagic1 \
tesseract-ocr \
ghostscript \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Copy requirements (Dockerfile is in orchestrator/, so copy from current dir)
COPY requirements.txt .
# Install Python dependencies (clean cache after)
RUN pip install --no-cache-dir -r requirements.txt && \
pip cache purge && \
rm -rf /root/.cache/pip
# Download NLTK data (punkt tokenizer, stopwords) for memory operations
# Set NLTK_DATA to a system-wide location accessible to all users
ENV NLTK_DATA=/usr/local/nltk_data
RUN python -c "import nltk; nltk.download('punkt', quiet=True, download_dir='/usr/local/nltk_data'); nltk.download('stopwords', quiet=True, download_dir='/usr/local/nltk_data')" && \
chmod -R 755 /usr/local/nltk_data && \
rm -rf /root/.cache/nltk
# =============================================================================
# Development Stage - Hot Reload & Debugging
# =============================================================================
FROM base as development
# Create minimal entrypoint script (Railway doesn't need full entrypoint - database is ready)
# For docker-compose, the full entrypoint.sh will be mounted/overridden
RUN printf '#!/bin/bash\nset -e\nexec "$@"\n' > /usr/local/bin/docker-entrypoint.sh && \
chmod +x /usr/local/bin/docker-entrypoint.sh
# Copy application code (Dockerfile is in orchestrator/, so copy from current dir)
COPY . .
# Create necessary directories
RUN mkdir -p /app/logs /app/vector_stores /app/projects /app/exports
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Set entrypoint
ENTRYPOINT ["docker-entrypoint.sh"]
# Default command - can be overridden in docker-compose
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
# =============================================================================
# Production Stage - Optimized & Minimal
# =============================================================================
FROM base as production
# Copy application code only (no dev tools)
# .dockerignore will exclude unnecessary files
COPY . .
# Create minimal entrypoint script (Railway doesn't need full entrypoint - database is ready)
# For docker-compose, the full entrypoint.sh will be mounted/overridden
RUN printf '#!/bin/bash\nset -e\nexec "$@"\n' > /usr/local/bin/docker-entrypoint.sh && \
chmod +x /usr/local/bin/docker-entrypoint.sh
# Create necessary directories
RUN mkdir -p /app/logs /app/vector_stores /app/projects /app/exports
# Remove dev dependencies and clean up
RUN pip uninstall -y pytest pytest-asyncio black isort 2>/dev/null || true && \
pip cache purge && \
rm -rf /root/.cache/pip /root/.cache/pytest /tmp/* && \
find /app -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true && \
find /app -type f -name "*.pyc" -delete 2>/dev/null || true
# Create non-root user for security
RUN useradd -m -u 1000 automatos && \
chown -R automatos:automatos /app
USER automatos
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Set entrypoint
ENTRYPOINT ["docker-entrypoint.sh"]
# Production command - use PORT env var (Railway provides this)
# Default to 8000 if PORT not set
CMD sh -c "uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000} --workers 4"