-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
127 lines (98 loc) · 2.74 KB
/
Dockerfile
File metadata and controls
127 lines (98 loc) · 2.74 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
116
117
118
119
120
121
122
123
124
125
126
127
# AI Automation Bot - Dockerfile
# Multi-stage build for optimized production image
# Base stage
FROM python:3.9-slim as base
# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PIP_NO_CACHE_DIR=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
curl \
wget \
git \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Development stage
FROM base as development
# Install development dependencies
RUN pip install --no-cache-dir \
pytest \
pytest-cov \
black \
flake8 \
mypy \
ipython \
jupyter
# Copy source code
COPY src/ ./src/
COPY tests/ ./tests/
COPY config/ ./config/
COPY scripts/ ./scripts/
# Create necessary directories
RUN mkdir -p logs data models reports backups
# Set development environment
ENV ENVIRONMENT=development
ENV PYTHONPATH=/app
# Development command
CMD ["python", "-m", "src.main", "--daemon"]
# Production stage
FROM base as production
# Install production dependencies only
RUN pip install --no-cache-dir \
gunicorn \
uvicorn
# Copy source code
COPY src/ ./src/
COPY config/ ./config/
COPY scripts/ ./scripts/
# Create necessary directories
RUN mkdir -p logs data models reports backups
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser
RUN chown -R appuser:appuser /app
USER appuser
# Set production environment
ENV ENVIRONMENT=production
ENV PYTHONPATH=/app
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import requests; requests.get('http://localhost:8000/health')" || exit 1
# Production command
CMD ["python", "-m", "src.main", "--daemon"]
# Testing stage
FROM development as testing
# Install testing dependencies
RUN pip install --no-cache-dir \
pytest-asyncio \
pytest-mock \
factory-boy \
coverage
# Copy test configuration
COPY pytest.ini .
COPY .coveragerc .
# Test command
CMD ["pytest", "tests/", "-v", "--cov=src", "--cov-report=html"]
# Documentation stage
FROM base as documentation
# Install documentation dependencies
RUN pip install --no-cache-dir \
sphinx \
sphinx-rtd-theme \
sphinx-autodoc-typehints
# Copy documentation files
COPY docs/ ./docs/
COPY README.md .
# Build documentation
RUN sphinx-build -b html docs/ docs/_build/html
# Serve documentation
EXPOSE 8080
CMD ["python", "-m", "http.server", "8080", "--directory", "docs/_build/html"]