|
1 |
| -# Dockerfile for running titiler application with uvicorn server |
| 1 | +# syntax=docker/dockerfile:1 |
2 | 2 | ARG PYTHON_VERSION=3.11
|
3 | 3 |
|
4 |
| -FROM python:${PYTHON_VERSION}-slim |
| 4 | +# Build stage |
| 5 | +FROM python:${PYTHON_VERSION}-slim AS builder |
5 | 6 |
|
6 |
| -RUN apt update && apt upgrade -y |
| 7 | +# Set build labels |
| 8 | +LABEL stage=builder |
| 9 | +LABEL org.opencontainers.image.source="https://github.com/developmentseed/titiler-openeo" |
| 10 | +LABEL org.opencontainers.image.description="TiTiler OpenEO API" |
| 11 | +LABEL org.opencontainers.image.licenses="MIT" |
7 | 12 |
|
8 |
| -# ref: https://github.com/rasterio/rasterio-wheels/issues/136, https://github.com/docker-library/python/issues/989 |
9 |
| -RUN apt install -y libexpat1 |
| 13 | +# Set environment variables |
| 14 | +ENV PYTHONUNBUFFERED=1 \ |
| 15 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 16 | + PIP_NO_CACHE_DIR=1 \ |
| 17 | + PIP_DISABLE_PIP_VERSION_CHECK=1 |
10 | 18 |
|
11 |
| -RUN python -m pip install uvicorn gunicorn uvicorn worker |
| 19 | +# Install build dependencies |
| 20 | +RUN apt-get update && \ |
| 21 | + apt-get install -y --no-install-recommends \ |
| 22 | + libexpat1 && \ |
| 23 | + rm -rf /var/lib/apt/lists/* |
12 | 24 |
|
13 |
| -# Copy files and install titiler.openeo |
14 |
| -WORKDIR /tmp |
| 25 | +# Create and activate virtual environment |
| 26 | +RUN python -m venv /opt/venv |
| 27 | +ENV PATH="/opt/venv/bin:$PATH" |
15 | 28 |
|
| 29 | +# Install application |
| 30 | +WORKDIR /tmp |
16 | 31 | COPY titiler/ titiler/
|
17 |
| -COPY pyproject.toml pyproject.toml |
18 |
| -COPY README.md README.md |
| 32 | +COPY pyproject.toml . |
| 33 | +COPY README.md . |
| 34 | +RUN pip install --no-cache-dir --upgrade uvicorn PyYAML ".[pystac,oidc,postgres]" |
| 35 | + |
| 36 | +# Runtime stage |
| 37 | +FROM python:${PYTHON_VERSION}-slim |
| 38 | + |
| 39 | +# Set runtime labels |
| 40 | +LABEL org.opencontainers.image.source="https://github.com/developmentseed/titiler-openeo" |
| 41 | +LABEL org.opencontainers.image.description="TiTiler OpenEO API" |
| 42 | +LABEL org.opencontainers.image.licenses="MIT" |
19 | 43 |
|
20 |
| -RUN python -m pip install --no-cache-dir --upgrade ".[pystac,postgres]" |
21 |
| -RUN rm -rf /tmp/titiler pyproject.toml README.md |
| 44 | +# Set environment variables |
| 45 | +ENV PYTHONUNBUFFERED=1 \ |
| 46 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 47 | + PATH="/opt/venv/bin:$PATH" |
22 | 48 |
|
23 |
| -RUN mkdir /data |
| 49 | +# Install runtime dependencies |
| 50 | +RUN apt-get update && \ |
| 51 | + apt-get install -y --no-install-recommends \ |
| 52 | + libexpat1 \ |
| 53 | + curl && \ |
| 54 | + rm -rf /var/lib/apt/lists/* |
| 55 | + |
| 56 | +# Copy virtual environment from builder |
| 57 | +COPY --from=builder /opt/venv /opt/venv |
| 58 | + |
| 59 | +# Create non-root user |
| 60 | +RUN useradd -m -s /bin/bash titiler && \ |
| 61 | + mkdir -p /data /config |
| 62 | +COPY log_config.yaml /config/log_config.yaml |
| 63 | +RUN chown -R titiler:titiler /data /config |
24 | 64 |
|
25 | 65 | WORKDIR /app
|
| 66 | +USER titiler |
| 67 | + |
| 68 | +# Create data directory |
| 69 | +VOLUME /data |
| 70 | +# Create config directory and copy default config |
| 71 | +VOLUME /config |
| 72 | + |
| 73 | +# Add healthcheck |
| 74 | +HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ |
| 75 | + CMD curl --fail http://localhost:8000/api || exit 1 |
| 76 | + |
| 77 | +# Set default command |
| 78 | +CMD ["uvicorn", "titiler.openeo.main:app", "--host", "0.0.0.0", "--port", "80", "--log-config", "/config/log_config.yaml", "--workers", "4"] |
| 79 | + |
| 80 | +# Expose port |
| 81 | +EXPOSE 80 |
0 commit comments