Skip to content

Commit 4ac4c33

Browse files
committed
Split dockerfile into multi-stage build to separate pre-req builds, runner, and full layers
1 parent 080cdc6 commit 4ac4c33

File tree

5 files changed

+64
-25
lines changed

5 files changed

+64
-25
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ lightning_logs
77
wandb
88
**/test_data/**/**/*.tif
99
**/project_data
10+
one_off_projects

Dockerfile

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,71 @@
1-
FROM pytorch/pytorch:2.7.0-cuda12.8-cudnn9-runtime@sha256:7db0e1bf4b1ac274ea09cf6358ab516f8a5c7d3d0e02311bed445f7e236a5d80
1+
###
2+
### docker build --ssh default=/path/to/private.key -f Dockerfile .
23

3-
RUN apt update
4-
RUN apt install -y libpq-dev ffmpeg libsm6 libxext6 git wget
4+
ARG BASE=ubuntu:22.04
5+
ARG BASE_PYTORCH=pytorch/pytorch:2.7.0-cuda12.8-cudnn9-runtime@sha256:7db0e1bf4b1ac274ea09cf6358ab516f8a5c7d3d0e02311bed445f7e236a5d80
6+
ARG PLATFORM=linux/amd64
57

6-
# Install Go (used for Satlas smooth_point_labels_viterbi.go).
7-
RUN wget https://go.dev/dl/go1.22.12.linux-amd64.tar.gz
8-
RUN rm -rf /usr/local/go && tar -C /usr/local -xzf go1.22.12.linux-amd64.tar.gz
9-
ENV PATH="${PATH}:/usr/local/go/bin"
8+
FROM --platform=${PLATFORM} ${BASE} AS tippecanoe
109

11-
# Install tippecanoe (used by forest loss driver).
12-
RUN apt install -y build-essential libsqlite3-dev zlib1g-dev
13-
RUN git clone https://github.com/mapbox/tippecanoe /opt/tippecanoe
14-
WORKDIR /opt/tippecanoe
10+
RUN apt-get update && apt-get install -y --no-install-recommends build-essential ca-certificates curl libsqlite3-dev zlib1g-dev
11+
12+
RUN mkdir -p /tmp/tippecanoe && curl -L https://github.com/mapbox/tippecanoe/archive/refs/tags/1.36.0.tar.gz | tar -xvz --strip 1 -C /tmp/tippecanoe
13+
WORKDIR /tmp/tippecanoe
1514
RUN make -j
16-
RUN make install
15+
RUN PREFIX=/opt/tippecanoe make install
16+
17+
# To use this:
18+
# COPY --from=tippecanoe /opt/tippecanoe /opt/tippecanoe
19+
# ENV PATH="/opt/tippecanoe/bin:${PATH}"
20+
21+
FROM --platform=${PLATFORM} ${BASE} AS golang
22+
23+
## Build Satlas smooth_point_labels_viterbi.go (Requires golang)
24+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl
25+
RUN curl -L https://go.dev/dl/go1.22.12.linux-amd64.tar.gz | tar -xvz -C /usr/local
26+
ENV PATH="/usr/local/go/bin:${PATH}"
27+
28+
COPY rslp/satlas/scripts /tmp/smooth_point_labels_viterbi/
29+
WORKDIR /tmp/smooth_point_labels_viterbi/
30+
RUN go build smooth_point_labels_viterbi.go
31+
32+
# To use this:
33+
# COPY --from=golang /tmp/smooth_point_labels_viterbi/smooth_point_labels_viterbi /usr/local/bin/smooth_point_labels_viterbi
34+
35+
FROM --platform=${PLATFORM} pytorch/pytorch:2.7.0-cuda12.8-cudnn9-runtime@sha256:7db0e1bf4b1ac274ea09cf6358ab516f8a5c7d3d0e02311bed445f7e236a5d80 AS base
36+
37+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git``
38+
39+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
40+
41+
COPY . /opt/rslearn_projects/
42+
# We assume that the caller has already cloned olmoearth_run and olmoearth_pretrain to /opt/rslearn_projects/docker_build/
43+
RUN echo 'olmoearth_run[runner] @ /opt/rslearn_projects/docker_build/olmoearth_run/' > /opt/rslearn_projects/requirements-olmoearth_run.txt
44+
RUN echo 'olmoearth_pretrain @ /opt/rslearn_projects/docker_build/olmoearth_pretrain/' > /opt/rslearn_projects/requirements-olmoearth_pretrain.txt
45+
RUN uv pip install --system /opt/rslearn_projects[olmoearth_run,olmoearth_pretrain]
46+
47+
FROM base AS full
48+
49+
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git openssh-client
1750

51+
# Pin GitHub’s host keys so SSH won’t prompt
52+
RUN mkdir -p -m 700 /root/.ssh && \
53+
ssh-keyscan -t rsa,ecdsa,ed25519 github.com >> /root/.ssh/known_hosts \
54+
55+
COPY --from=tippecanoe /opt/tippecanoe /opt/tippecanoe
56+
COPY --from=golang /tmp/smooth_point_labels_viterbi/smooth_point_labels_viterbi /usr/local/bin/smooth_point_labels_viterbi
1857
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
1958

20-
# Install rslearn.
21-
# We use git clone and then git checkout instead of git clone -b so that the user could
22-
# specify a commit name or branch instead of only accepting a branch.
59+
ENV PATH="/opt/tippecanoe/bin:${PATH}"
60+
61+
## Install rslearn.
62+
## We use git clone and then git checkout instead of git clone -b so that the user could
63+
## specify a commit name or branch instead of only accepting a branch.
2364
ARG RSLEARN_BRANCH=master
24-
RUN git clone https://github.com/allenai/rslearn.git /opt/rslearn
65+
RUN --mount=type=ssh git clone git@github.com:allenai/rslearn.git /opt/rslearn
2566
WORKDIR /opt/rslearn
2667
RUN git checkout $RSLEARN_BRANCH
2768
RUN uv pip install --system /opt/rslearn[extra]
2869

29-
# Install rslearn_projects.
3070
COPY . /opt/rslearn_projects/
3171
RUN uv pip install --system /opt/rslearn_projects[dev,extra]
32-
33-
# Build Satlas smooth_point_labels_viterbi.go program.
34-
WORKDIR /opt/rslearn_projects/rslp/satlas/scripts
35-
RUN go build smooth_point_labels_viterbi.go
36-
37-
WORKDIR /opt/rslearn_projects

pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ file = ["requirements.txt"]
2323
[tool.setuptools.dynamic.optional-dependencies]
2424
dev = { file = ["requirements-dev.txt"] }
2525
extra = { file = ["requirements-extra.txt"] }
26-
helios = { file = ["requirements-helios.txt"] }
26+
olmoearth_pretrain = { file = ["requirements-olmoearth_pretrain.txt"] }
2727
olmoearth_run = { file = ["requirements-olmoearth_run.txt"] }
2828

29+
# Kept for backward compatibility
30+
helios = { file = ["requirements-olmoearth_pretrain.txt"] }
31+
2932
[tool.ruff]
3033
fix = true
3134

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
olmoearth_pretrain @ git+https://github.com/allenai/olmoearth_pretrain.git@0cd82b4784bc2f246a23f6da98a9bab27761c1ba
1+
olmoearth_pretrain @ git+https://github.com/allenai/olmoearth_pretrain.git@f0a63f190b0f99d9c503249daf7e3e47bbd4792a

requirements-olmoearth_run.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
olmoearth_run @ git+https://github.com/allenai/olmoearth_run.git@develop
2+
# olmoearth_runner >= 0.1.0 # Once we have packages publishing.

0 commit comments

Comments
 (0)