-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (48 loc) · 1.42 KB
/
Dockerfile
File metadata and controls
64 lines (48 loc) · 1.42 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
# --- Stage 1: Builder ---
FROM python:3.10-slim AS builder
WORKDIR /build
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libpq-dev \
libffi-dev \
libfreetype6-dev \
&& rm -rf /var/lib/apt/lists/*
# Create and use a virtualenv
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# --- Stage 2: Runtime ---
FROM python:3.10-slim
WORKDIR /app
# Set production environment variables
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=5000 \
FLASK_ENV=production \
PATH="/opt/venv/bin:$PATH"
# Install minimal runtime libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
libfreetype6 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy virtualenv from builder
COPY --from=builder /opt/venv /opt/venv
# Copy application code
COPY . .
# Create persistent data volumes with correct permissions
RUN mkdir -p data logs static/uploads \
&& useradd -m -u 1000 appuser \
&& chown -R appuser:appuser /app
# Ensure appuser can write to the data directories
RUN chmod -R 755 data logs static/uploads
USER appuser
# Health check using curl
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:5000/ || exit 1
EXPOSE 5000
# Entry point
CMD ["python", "main.py"]