|
4 | 4 |
|
5 | 5 | ARG PY_VER=3.10 |
6 | 6 | ARG TF_VER=2.9.2 |
7 | | -ARG BUILD_TYPE=cpu |
| 7 | +ARG BUILD_TYPE=gpu |
8 | 8 | ARG CUDA_TAG=11.8.0-cudnn8-runtime-ubuntu22.04 |
9 | 9 | ARG CUDA_DEVEL_TAG=11.8.0-cudnn8-devel-ubuntu22.04 |
10 | 10 |
|
| 11 | +# ============================================================================== |
| 12 | +# === CPU base image (minimal) ================================================= |
| 13 | + |
11 | 14 | FROM python:${PY_VER}-slim-bookworm AS cpu-base |
12 | 15 | ENV DEBIAN_FRONTEND=noninteractive |
13 | 16 | RUN apt-get update && \ |
14 | 17 | apt-get install -y --no-install-recommends \ |
15 | 18 | build-essential gcc g++ python3-dev python3-rtree \ |
16 | 19 | gdal-bin libgdal-dev python3-gdal python3-opencv libspatialindex-dev \ |
17 | 20 | && rm -rf /var/lib/apt/lists/* |
18 | | - |
19 | | -FROM nvidia/cuda:${CUDA_DEVEL_TAG} AS cuda-dev |
20 | | - |
| 21 | +# ============================================================================== |
| 22 | +# === GPU base image (CUDA + runtime-only Python & GDAL) ======================= |
21 | 23 | FROM nvidia/cuda:${CUDA_TAG} AS gpu-base |
22 | 24 | ENV DEBIAN_FRONTEND=noninteractive |
23 | 25 | RUN apt-get update && \ |
24 | 26 | apt-get install -y --no-install-recommends \ |
25 | | - python3 python3-pip python3-rtree python-is-python3 \ |
26 | | - gdal-bin libgdal-dev python3-gdal python3-opencv \ |
27 | | - libspatialindex-dev libpq-dev \ |
28 | | - && rm -rf /var/lib/apt/lists/* \ |
29 | | - && python3 -m pip install --upgrade pip |
30 | | -COPY --from=cuda-dev /usr/local/cuda/nvvm/libdevice /usr/local/cuda/nvvm/libdevice |
| 27 | + python3 python3-pip build-essential gcc g++ python3-dev python3-rtree python-is-python3 \ |
| 28 | + gdal-bin libgdal-dev python3-gdal python3-opencv libspatialindex-dev \ |
| 29 | + && rm -rf /var/lib/apt/lists/* && \ |
| 30 | + python3 -m pip install --upgrade pip |
| 31 | + |
| 32 | +FROM nvidia/cuda:${CUDA_DEVEL_TAG} AS cuda-dev |
| 33 | + |
31 | 34 |
|
| 35 | +# ============================================================================== |
| 36 | +# === Builder stage (installs everything) ====================================== |
32 | 37 | FROM ${BUILD_TYPE}-base AS builder |
33 | 38 | ENV DEBIAN_FRONTEND=noninteractive |
34 | 39 | ARG TF_VER |
| 40 | +ARG BUILD_TYPE |
| 41 | + |
35 | 42 | COPY docker/pipped-requirements.txt /tmp/pipped-requirements.txt |
| 43 | + |
| 44 | + |
| 45 | +# Use pip cache and install Python packages (including building GDAL) |
36 | 46 | RUN --mount=type=cache,target=/root/.cache/pip \ |
37 | 47 | pip install --no-cache-dir --upgrade pip more-itertools && \ |
38 | 48 | pip install --no-cache-dir tensorflow==${TF_VER} && \ |
39 | | - pip install --no-cache-dir "GDAL==$(gdal-config --version)" && \ |
| 49 | + pip install "GDAL==$(gdal-config --version)" && \ |
40 | 50 | pip install --no-cache-dir -r /tmp/pipped-requirements.txt |
| 51 | + |
| 52 | +# Install solaris (local) |
41 | 53 | COPY solaris /tmp/solaris |
42 | 54 | RUN --mount=type=cache,target=/root/.cache/pip \ |
43 | 55 | pip install --no-cache-dir /tmp/solaris |
| 56 | + |
| 57 | +# Install scikit-fmm |
44 | 58 | RUN --mount=type=cache,target=/root/.cache/pip \ |
45 | 59 | pip install --no-cache-dir scikit-fmm |
| 60 | + |
| 61 | +# Install ramp (local) |
46 | 62 | COPY setup.py README.md /tmp/ramp-code/ |
47 | 63 | COPY ramp /tmp/ramp-code/ramp |
48 | 64 | RUN --mount=type=cache,target=/root/.cache/pip \ |
49 | 65 | pip install --no-cache-dir /tmp/ramp-code |
50 | 66 |
|
| 67 | +# ============================================================================== |
| 68 | +# === Final minimal runtime image ============================================== |
51 | 69 | FROM ${BUILD_TYPE}-base AS final |
52 | 70 | ENV DEBIAN_FRONTEND=noninteractive |
| 71 | + |
53 | 72 | ENV CPLUS_INCLUDE_PATH=/usr/include/gdal \ |
54 | 73 | C_INCLUDE_PATH=/usr/include/gdal \ |
55 | 74 | RAMP_HOME=/app |
| 75 | + |
56 | 76 | COPY --from=builder /usr/local /usr/local |
57 | 77 | COPY --from=builder /usr/lib/python*/ /usr/lib/python*/ |
58 | 78 | COPY --from=builder /usr/include/gdal /usr/include/gdal |
59 | 79 | COPY --from=cuda-dev /usr/local/cuda/nvvm/libdevice /usr/local/cuda/nvvm/libdevice |
| 80 | + |
60 | 81 | WORKDIR /app |
61 | 82 | CMD ["bash"] |
0 commit comments