@@ -4,7 +4,7 @@ ARG UBUNTU_VERSION
4
4
5
5
# #######################################################################
6
6
7
- FROM nvidia/cuda:${CUDA_VERSION}-cudnn8-runtime-ubuntu${UBUNTU_VERSION} as thinbuild
7
+ FROM nvidia/cuda:${CUDA_VERSION}-cudnn8-runtime-ubuntu${UBUNTU_VERSION} AS thinbuild
8
8
9
9
ARG PYTHON_VERSION=3.11
10
10
@@ -22,12 +22,12 @@ RUN --mount=type=cache,target=/var/cache/apt apt update && \
22
22
23
23
# #######################################################################
24
24
25
- FROM nvidia/cuda:${CUDA_VERSION}-cudnn8-runtime-ubuntu${UBUNTU_VERSION} as fullbuild
25
+ FROM nvidia/cuda:${CUDA_VERSION}-cudnn8-runtime-ubuntu${UBUNTU_VERSION} AS fullbuild
26
26
27
27
ARG TARGETPLATFORM
28
28
ARG PYTHON_VERSION=3.11
29
29
30
- # wget: needed below to install conda
30
+ # wget: needed below to install mamba
31
31
# build-essential: installs gcc which is needed to install some deps like rasterio
32
32
# libGL1: needed to avoid following error when using cv2
33
33
# ImportError: libGL.so.1: cannot open shared object file: No such file or directory
@@ -45,27 +45,32 @@ RUN case ${TARGETPLATFORM} in \
45
45
RUN curl -fsSL https://deb.nodesource.com/node_16.x | bash - && \
46
46
apt-get install -y nodejs
47
47
48
- # Install Python and conda/ mamba (mamba installs conda as well)
48
+ # Install Python and mamba
49
49
RUN wget -q -O ~/micromamba.sh https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-$(cat /root/linux_arch).sh && \
50
50
chmod +x ~/micromamba.sh && \
51
51
bash ~/micromamba.sh -b -p /opt/conda && \
52
52
rm ~/micromamba.sh
53
- ENV PATH /opt/conda/bin:$PATH
54
- ENV LD_LIBRARY_PATH /opt/conda/lib/:$LD_LIBRARY_PATH
55
- RUN mamba init
56
- RUN mamba install -y python=${PYTHON_VERSION}
57
- RUN python -m pip install --upgrade pip
53
+ ENV PATH=/opt/conda/bin:/opt/conda/condabin:$PATH
54
+ ENV LD_LIBRARY_PATH=/opt/conda/lib/:$LD_LIBRARY_PATH
55
+
56
+ RUN mamba init bash
57
+ RUN mamba create -n rv python=${PYTHON_VERSION} -y
58
+ RUN echo "mamba activate rv" >> ~/.bashrc
59
+
60
+ # Make RUN commands use the new mamba environment:
61
+ SHELL ["mamba" , "run" , "-n" , "rv" , "bash" , "-l" , "-c" ]
58
62
59
63
# env variable required by uv
60
- ENV CONDA_PREFIX=/opt/conda
64
+ ENV CONDA_PREFIX=/opt/conda/envs/rv/bin/
65
+ RUN python -m pip install --upgrade pip
61
66
RUN pip install uv
62
67
63
68
# We need to install GDAL first to install Rasterio on non-AMD64 architectures.
64
69
# The Rasterio wheels contain GDAL in them, but they are only built for AMD64 now.
65
- RUN mamba update mamba -y && mamba install -y -c conda-forge gdal=3.6.3
70
+ RUN mamba install -y -c conda-forge gdal=3.6.3
66
71
ENV GDAL_DATA=/opt/conda/lib/python${PYTHON_VERSION}/site-packages/rasterio/gdal_data/
67
72
# Needed for GDAL 3.0
68
- ENV PROJ_LIB /opt/conda/share/proj/
73
+ ENV PROJ_LIB= /opt/conda/share/proj/
69
74
70
75
# This is to prevent the following error when starting the container.
71
76
# bash: /opt/conda/lib/libtinfo.so.6: no version information available (required by bash)
@@ -86,99 +91,23 @@ FROM ${BUILD_TYPE:-fullbuild} AS final_stage
86
91
87
92
ARG TARGETARCH
88
93
89
- ENV LC_ALL C.UTF-8
90
- ENV LANG C.UTF-8
94
+ ENV LC_ALL= C.UTF-8
95
+ ENV LANG= C.UTF-8
91
96
92
97
WORKDIR /opt/src/
93
98
94
99
# ------------------------------------------------------------------------
95
100
96
- # Ideally we'd just pip install each package, but if we do that, then
97
- # a lot of the image will have to be re-built each time we make a
98
- # change to the code. So, we split the install into installing all the
99
- # requirements in bunches (filtering out any prefixed with
100
- # rastervision_*), and then copy over the source code. The
101
- # dependencies are installed in bunches rather than package-by-package
102
- # or on a per-RV component basis to reduce the build time, the number
103
- # of layers, and the overall image size, and to reduce churn
104
- # (installing and uninstalling of Python packages during the build).
105
- #
106
- # The bunches are heuristic and are meant to keep the heaviest and/or
107
- # least-frequently-changing dependencies before the more variable
108
- # ones. At time of writing, the amount of image size attributable to
109
- # PyTorch (and the amount of image size overall) is heavily dominated
110
- # by PyTorch, so it is first.
111
-
112
- # Install requirements.
113
- # -E "^\s*$|^#|rastervision_*" means exclude blank lines, comment lines,
114
- # and rastervision plugins.
115
-
116
- COPY ./rastervision_pytorch_learner/requirements.txt /opt/src/pytorch-requirements.txt
117
- RUN --mount=type=cache,target=/root/.cache/pip cat pytorch-requirements.txt | sort | uniq > all-requirements.txt && \
118
- uv pip install $(grep -ivE "^\s *$|^#|rastervision_*" all-requirements.txt) && \
119
- rm all-requirements.txt
120
-
121
- COPY ./rastervision_aws_batch/requirements.txt /opt/src/batch-requirements.txt
122
- COPY ./rastervision_aws_s3/requirements.txt /opt/src/s3-requirements.txt
123
- COPY ./rastervision_core/requirements.txt /opt/src/core-requirements.txt
124
-
125
- # Pip wheels for triangle are missing for ARM64 architectures and building
126
- # from source fails, so we skip it.
127
- RUN if [ "${TARGETARCH}" = "arm64" ]; \
128
- then sed -i '/^triangle.*$/d' /opt/src/core-requirements.txt; fi
129
-
130
- COPY ./rastervision_gdal_vsi/requirements.txt /opt/src/gdal-requirements.txt
131
- COPY ./rastervision_pipeline/requirements.txt /opt/src/pipeline-requirements.txt
132
- COPY ./rastervision_aws_sagemaker/requirements.txt /opt/src/sagemaker-requirements.txt
133
- COPY ./requirements-dev.txt /opt/src/requirements-dev.txt
134
- RUN --mount=type=cache,target=/root/.cache/pip cat \
135
- /opt/src/batch-requirements.txt \
136
- /opt/src/s3-requirements.txt \
137
- /opt/src/core-requirements.txt \
138
- /opt/src/gdal-requirements.txt \
139
- /opt/src/pipeline-requirements.txt \
140
- /opt/src/sagemaker-requirements.txt \
141
- /opt/src/requirements-dev.txt \
142
- | sort | uniq > all-requirements.txt && \
143
- uv pip install $(grep -ivE "^\s *$|^#|rastervision_*" all-requirements.txt) && \
144
- rm all-requirements.txt
145
-
146
- # ########################
147
- # Docs
148
- # ########################
149
- # Install docs/requirements.txt
150
- COPY ./docs/requirements.txt /opt/src/docs/pandoc-requirements.txt
151
-
152
101
# Install pandoc, needed for rendering notebooks
153
102
# Get latest release link from here: https://github.com/jgm/pandoc/releases
154
- RUN --mount=type=cache,target=/root/.cache/pip uv pip install -r docs/pandoc-requirements.txt && \
155
- wget https://github.com/jgm/pandoc/releases/download/3.1.12.2/pandoc-3.1.12.2-1-${TARGETARCH}.deb && \
156
- dpkg -i pandoc-3.1.12.2-1-${TARGETARCH}.deb && rm pandoc-3.1.12.2-1-${TARGETARCH}.deb
103
+ RUN --mount=type=cache,target=/root/.cache/pip wget \
104
+ https://github.com/jgm/pandoc/releases/download/3.1.12.2/pandoc-3.1.12.2-1-${TARGETARCH}.deb && \
105
+ dpkg -i pandoc-3.1.12.2-1-${TARGETARCH}.deb && \
106
+ rm pandoc-3.1.12.2-1-${TARGETARCH}.deb
157
107
158
108
# ------------------------------------------------------------------------
159
109
160
- # needed for this image to be used by the AWS SageMaker PyTorch Estimator
161
- RUN uv pip install sagemaker_pytorch_training==2.8.1
162
- ENV SAGEMAKER_TRAINING_MODULE=sagemaker_pytorch_container.training:main
163
-
164
- # Install a onnxruntime-gpu version compatible with CUDA 12. Specifying
165
- # --extra-index-url in requirements.txt seems to cause problems with the
166
- # RTD build.
167
- RUN if [ "${TARGETARCH}" != "arm64" ]; then \
168
- uv pip install onnxruntime-gpu==1.19; fi
169
-
170
- # ------------------------------------------------------------------------
171
-
172
- ENV PYTHONPATH=/opt/src:$PYTHONPATH
173
- ENV PYTHONPATH=/opt/src/rastervision_aws_batch/:$PYTHONPATH
174
- ENV PYTHONPATH=/opt/src/rastervision_aws_s3/:$PYTHONPATH
175
- ENV PYTHONPATH=/opt/src/rastervision_core/:$PYTHONPATH
176
- ENV PYTHONPATH=/opt/src/rastervision_gdal_vsi/:$PYTHONPATH
177
- ENV PYTHONPATH=/opt/src/rastervision_pipeline/:$PYTHONPATH
178
- ENV PYTHONPATH=/opt/src/rastervision_aws_sagemaker/:$PYTHONPATH
179
- ENV PYTHONPATH=/opt/src/rastervision_pytorch_backend/:$PYTHONPATH
180
- ENV PYTHONPATH=/opt/src/rastervision_pytorch_learner/:$PYTHONPATH
181
-
110
+ COPY ./requirements.txt /opt/src/requirements.txt
182
111
COPY scripts /opt/src/scripts/
183
112
COPY scripts/rastervision /usr/local/bin/rastervision
184
113
COPY tests /opt/src/tests/
@@ -195,4 +124,41 @@ COPY ./rastervision_aws_sagemaker/ /opt/src/rastervision_aws_sagemaker/
195
124
COPY ./rastervision_pytorch_backend/ /opt/src/rastervision_pytorch_backend/
196
125
COPY ./rastervision_pytorch_learner/ /opt/src/rastervision_pytorch_learner/
197
126
127
+ # remove rastervision dependencies
128
+ RUN sed -i '/^rastervision/d' requirements.txt
129
+
130
+ # Pip wheels for triangle are missing for ARM64 architectures and building
131
+ # from source fails, so we skip it.
132
+ RUN if [ "${TARGETARCH}" = "arm64" ]; \
133
+ then sed -i '/^triangle.*$/d' /opt/src/requirements.txt; fi
134
+
135
+ RUN --mount=type=cache,target=/root/.cache/pip uv pip sync /opt/src/requirements.txt
136
+
137
+ RUN uv pip install -e /opt/src/rastervision_pipeline/ --no-deps
138
+ RUN uv pip install -e /opt/src/rastervision_aws_s3/ --no-deps
139
+ RUN uv pip install -e /opt/src/rastervision_aws_batch/ --no-deps
140
+ RUN uv pip install -e /opt/src/rastervision_core/ --no-deps
141
+ RUN uv pip install -e /opt/src/rastervision_pytorch_learner/ --no-deps
142
+ RUN uv pip install -e /opt/src/rastervision_pytorch_backend/ --no-deps
143
+ RUN uv pip install -e /opt/src/rastervision_aws_sagemaker/ --no-deps
144
+ RUN uv pip install -e /opt/src/rastervision_gdal_vsi/ --no-deps
145
+
146
+
147
+ # ------------------------------------------------------------------------
148
+
149
+ # needed for this image to be used by the AWS SageMaker PyTorch Estimator
150
+ RUN uv pip install sagemaker_pytorch_training==2.8.1
151
+ ENV SAGEMAKER_TRAINING_MODULE=sagemaker_pytorch_container.training:main
152
+
153
+ # ------------------------------------------------------------------------
154
+
155
+ # Install a onnxruntime-gpu version compatible with CUDA 12. Specifying
156
+ # --extra-index-url in requirements.txt seems to cause problems with the
157
+ # RTD build.
158
+ RUN if [ "${TARGETARCH}" != "arm64" ]; then \
159
+ uv pip install onnxruntime-gpu==1.19; fi
160
+
161
+ # ------------------------------------------------------------------------
162
+
163
+ ENTRYPOINT ["mamba" , "run" , "--no-capture-output" , "-n" , "rv" , "bash" , "-l" , "-c" ]
198
164
CMD ["bash" ]
0 commit comments