-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
60 lines (48 loc) · 1.76 KB
/
Copy pathDockerfile
File metadata and controls
60 lines (48 loc) · 1.76 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
# ============================================
# FastAPI Panama Papers Application Dockerfile
# ============================================
# Base image: Python 3.11 slim for smaller size
FROM python:3.11-slim
# Set metadata labels
LABEL maintainer="Panama Papers Project"
LABEL description="FastAPI application for Panama Papers Neo4j analysis"
# Set environment variables
# Prevents Python from writing pyc files to disc
ENV PYTHONDONTWRITEBYTECODE=1
# Prevents Python from buffering stdout and stderr
ENV PYTHONUNBUFFERED=1
# Set Python path
ENV PYTHONPATH=/app
# Install system dependencies
# curl is required for health checks
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy requirements file first (for better layer caching)
COPY requirements.txt .
# Install Python dependencies
# --no-cache-dir reduces image size
# --upgrade ensures latest compatible versions
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Copy application code
# This is done after pip install for better Docker layer caching
COPY app/ ./app/
# Create non-root user for security
RUN useradd -m -u 1000 appuser && \
chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose the application port
EXPOSE 8000
# Health check configuration
# Checks if the application is responding every 30 seconds
HEALTHCHECK --interval=30s --timeout=5s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Start the FastAPI application with Uvicorn
# --host 0.0.0.0 allows external connections
# --port 8000 matches the exposed port
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]