-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·142 lines (112 loc) · 3.11 KB
/
Dockerfile
File metadata and controls
executable file
·142 lines (112 loc) · 3.11 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# Second Brain - Docker-First Development Environment
# Multi-stage build for development and production
# Zero host Python dependencies required
# Development stage
FROM python:3.11-slim AS development
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
DEBIAN_FRONTEND=noninteractive
# Create app user
RUN groupadd -r app && useradd -r -g app app
# Install system dependencies for development
RUN apt-get update && apt-get install -y \
build-essential \
curl \
git \
libpq-dev \
postgresql-client \
# Multi-modal support
tesseract-ocr \
tesseract-ocr-eng \
ffmpeg \
libsm6 \
libxext6 \
libglib2.0-0 \
libgomp1 \
# Development tools
vim \
htop \
&& rm -rf /var/lib/apt/lists/*
# Set work directory
WORKDIR /app
# Copy requirements files
COPY requirements.txt ./
# Install Python dependencies
RUN pip install --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create necessary directories
RUN mkdir -p logs session_storage temp data .cache && \
chown -R app:app /app
# Switch to non-root user
USER app
# Expose port
EXPOSE 8000
# Development command (with hot reload)
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
# Build stage for production
FROM python:3.11-slim AS builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpq-dev \
# Additional dependencies for multi-modal support
libxml2-dev \
libxslt1-dev \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy requirements files
COPY requirements.txt ./
# Install Python dependencies
RUN pip install --upgrade pip && \
pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels \
-r requirements.txt
# Runtime stage
FROM python:3.11-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
libpq5 \
curl \
# Multi-modal runtime dependencies
tesseract-ocr \
tesseract-ocr-eng \
ffmpeg \
libsm6 \
libxext6 \
libglib2.0-0 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd -r appuser && useradd -r -g appuser appuser
# Set working directory
WORKDIR /app
# Copy wheels from builder
COPY --from=builder /app/wheels /wheels
# Install Python packages
RUN pip install --upgrade pip && \
pip install --no-cache /wheels/* && \
rm -rf /wheels
# Copy application code
COPY --chown=appuser:appuser . .
# Create necessary directories
RUN mkdir -p /app/data /app/logs /app/temp && \
chown -R appuser:appuser /app/data /app/logs /app/temp
# Set environment variables
ENV TEMP_DIR=/app/temp
ENV PYTHONUNBUFFERED=1
# Switch to non-root user
USER appuser
# 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
# Default command
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]