-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
68 lines (51 loc) · 1.87 KB
/
Dockerfile
File metadata and controls
68 lines (51 loc) · 1.87 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
# syntax=docker/dockerfile:1
# Build stage - install dependencies with build tools
FROM python:3.12-slim-bookworm AS builder
# Install system dependencies for building wheels
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
gdal-bin \
libgdal-dev \
libproj-dev \
proj-bin \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Install Python dependencies to a virtual environment
COPY requirements.txt .
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt
# Production stage - minimal runtime image
FROM python:3.12-slim-bookworm AS production
# Install only runtime dependencies (no build tools)
RUN apt-get update && apt-get install -y --no-install-recommends \
gdal-bin \
libgdal32 \
libproj25 \
proj-bin \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
RUN groupadd --gid 1000 appgroup && \
useradd --uid 1000 --gid appgroup --shell /bin/bash --create-home appuser
WORKDIR /app
# Copy virtual environment from builder
COPY --from=builder /opt/venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# Copy application code
COPY --chown=appuser:appgroup src/ ./src/
# Create temp directory for IFC file generation (writable by appuser)
RUN mkdir -p /app/tmp && chown appuser:appgroup /app/tmp
ENV TMPDIR=/app/tmp
ENV PYTHONPATH=/app
# Switch to non-root user
USER appuser
# Use PORT env variable (Sevalla sets this)
ENV PORT=8080
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD python -c "import os, urllib.request; port=os.getenv('PORT', '8080'); urllib.request.urlopen(f'http://localhost:{port}/health')" || exit 1
# Run with uvicorn
CMD ["sh", "-c", "uvicorn src.rest_api:app --host 0.0.0.0 --port ${PORT}"]