-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
83 lines (62 loc) · 2.1 KB
/
Dockerfile
File metadata and controls
83 lines (62 loc) · 2.1 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
FROM python:3.11-slim AS builder
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# Install system dependencies required for building Python packages
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpq-dev \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN pip install poetry==1.7.1
# Set up a working directory
WORKDIR /app
# Copy pyproject.toml and poetry.lock
COPY pyproject.toml poetry.lock* ./
# Configure poetry to not use a virtual environment
RUN poetry config virtualenvs.create false
# Install dependencies
RUN poetry install --no-dev --no-interaction --no-ansi
# Second stage: runtime
FROM python:3.11-slim
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Install system dependencies for runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
gdal-bin \
libgdal-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install psycopg2-binary
RUN pip install psycopg2-binary
# Create a non-root user
RUN useradd -m -s /bin/bash appuser
# Set up a working directory
WORKDIR /app
# Copy installed packages from builder stage
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
# Copy application code
COPY . .
# Create necessary directories with proper permissions
RUN mkdir -p /app/logs && \
chown -R appuser:appuser /app
# Create scripts directory and add startup script
RUN mkdir -p /app/scripts
COPY scripts/start.sh /app/scripts/
RUN chmod +x /app/scripts/start.sh
# Make sure all scripts in the scripts directory are executable
RUN find /app/scripts -type f -name "*.sh" -exec chmod +x {} \;
RUN find /app/scripts -type f -name "*.py" -exec chmod +x {} \;
# Switch to non-root user
USER appuser
# Expose the application port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1