Skip to content

Commit 5611129

Browse files
committed
For the docker image
1 parent aa91d54 commit 5611129

File tree

4 files changed

+340
-0
lines changed

4 files changed

+340
-0
lines changed

.Rbuildignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
^pkgdown$
99
^\.github$
1010
^\.covrignore$
11+
Dockerfile
12+
*.sh

Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM rocker/tidyverse:latest
2+
3+
ENV PROJ_VERSION="9.4.1"
4+
ENV GDAL_VERSION="3.9.2"
5+
ENV GEOS_VERSION="3.12.2"
6+
7+
COPY ./install_dev_osgeo.sh /rocker_scripts/install_dev_osgeo.sh
8+
COPY ./install_geospatial.sh /rocker_scripts/install_geospatial.sh
9+
RUN /rocker_scripts/install_dev_osgeo.sh
10+
#COPY ./install_geospatial_unstable.sh /rocker_scripts/install_geospatial_unstable.sh
11+
#RUN /rocker_scripts/install_geospatial_unstable.sh
12+
13+
# Bioc sysreqs
14+
RUN apt-get update && apt-get install -y --no-install-recommends libfftw3-dev libmagick++-dev
15+
16+
RUN Rscript -e "BiocManager::install(version = 'devel', ask = FALSE)"
17+
RUN Rscript -e "options(repos = c(CRAN='https://cloud.r-project.org')); BiocManager::install('Voyager', dependencies = TRUE)"
18+
RUN Rscript -e "remotes::install_github('pachterlab/SpatialFeatureExperiment', ref='devel')"
19+
RUN Rscript -e "remotes::install_github('pachterlab/voyager', ref='devel')"

install_dev_osgeo.sh

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#!/bin/bash
2+
set -e
3+
4+
## Install PROJ, GDAL, GEOS from source.
5+
##
6+
## 'latest' means installing the latest release version.
7+
8+
## build ARGs
9+
NCPUS=${NCPUS:-"-1"}
10+
11+
PROJ_VERSION=${PROJ_VERSION:-"latest"}
12+
GDAL_VERSION=${GDAL_VERSION:-"latest"}
13+
GEOS_VERSION=${GEOS_VERSION:-"latest"}
14+
15+
CRAN_SOURCE=${CRAN_SOURCE:-"https://cloud.r-project.org"}
16+
echo "options(repos = c(CRAN = '${CRAN}'))" >>"${R_HOME}/etc/Rprofile.site"
17+
18+
# cmake does not understand "-1" as "all cpus"
19+
CMAKE_CORES=${NCPUS}
20+
if [ "${CMAKE_CORES}" = "-1" ]; then
21+
CMAKE_CORES=$(nproc --all)
22+
fi
23+
24+
# a function to install apt packages only if they are not installed
25+
function apt_install() {
26+
if ! dpkg -s "$@" >/dev/null 2>&1; then
27+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
28+
apt-get update
29+
fi
30+
apt-get install -y --no-install-recommends "$@"
31+
fi
32+
}
33+
34+
# a function to remove apt packages only if they are installed
35+
function apt_remove() {
36+
if dpkg -s "$@" >/dev/null 2>&1; then
37+
apt-get remove -y "$@"
38+
fi
39+
}
40+
41+
function url_latest_gh_released_asset() {
42+
wget -qO- "https://api.github.com/repos/$1/releases/latest" | grep -oP "(?<=\"browser_download_url\":\s\")https.*\.tar.gz(?=\")" | head -n 1
43+
}
44+
45+
export DEBIAN_FRONTEND=noninteractive
46+
47+
apt_remove gdal-bin libgdal-dev libgeos-dev libproj-dev &&
48+
apt-get autoremove -y
49+
50+
## Derived from osgeo/gdal
51+
apt-get update
52+
apt-get install -y --fix-missing --no-install-recommends \
53+
ant \
54+
autoconf \
55+
automake \
56+
bash-completion \
57+
build-essential \
58+
ca-certificates \
59+
cmake \
60+
curl \
61+
git \
62+
libarchive-dev \
63+
libarmadillo-dev \
64+
libblosc-dev \
65+
libboost-dev \
66+
libbz2-dev \
67+
libcairo2-dev \
68+
libclc-15-dev \
69+
libcfitsio-dev \
70+
libcrypto++-dev \
71+
libcurl4-openssl-dev \
72+
libdeflate-dev \
73+
libexpat-dev \
74+
libfreexl-dev \
75+
libfyba-dev \
76+
libgif-dev \
77+
libheif-dev \
78+
libhdf4-alt-dev \
79+
libhdf5-serial-dev \
80+
libjpeg-dev \
81+
libkml-dev \
82+
liblcms2-2 \
83+
liblerc-dev \
84+
liblz4-dev \
85+
liblzma-dev \
86+
libmysqlclient-dev \
87+
libnetcdf-dev \
88+
libogdi-dev \
89+
libopenexr-dev \
90+
libopenjp2-7-dev \
91+
libpcre3-dev \
92+
libpng-dev \
93+
libpq-dev \
94+
libpoppler-dev \
95+
libpoppler-private-dev \
96+
libqhull-dev \
97+
libsqlite3-dev \
98+
libssl-dev \
99+
libtiff5-dev \
100+
libudunits2-dev \
101+
libwebp-dev \
102+
libxerces-c-dev \
103+
libxml2-dev \
104+
lsb-release \
105+
make \
106+
mdbtools-dev \
107+
pkg-config \
108+
python3-dev \
109+
python3-numpy \
110+
python3-setuptools \
111+
sqlite3 \
112+
swig \
113+
unixodbc-dev \
114+
wget \
115+
zlib1g-dev
116+
## geoparquet support
117+
wget https://apache.jfrog.io/artifactory/arrow/"$(lsb_release --id --short | tr '[:upper:]' '[:lower:]')"/apache-arrow-apt-source-latest-"$(lsb_release --codename --short)".deb
118+
apt_install -y -V ./apache-arrow-apt-source-latest-"$(lsb_release --codename --short)".deb
119+
apt-get update && apt-get install -y -V libarrow-dev libparquet-dev libarrow-dataset-dev
120+
121+
rm -rf /build_local
122+
mkdir /build_local && cd /build_local
123+
124+
## tiledb
125+
GCC_ARCH="$(uname -m)"
126+
export TILEDB_VERSION=2.16.3
127+
apt-get update -y &&
128+
DEBIAN_FRONTEND=noninteractive apt-get install -y \
129+
libspdlog-dev &&
130+
mkdir tiledb &&
131+
wget -q https://github.com/TileDB-Inc/TileDB/archive/${TILEDB_VERSION}.tar.gz -O - |
132+
tar xz -C tiledb --strip-components=1 &&
133+
cd tiledb &&
134+
mkdir build_cmake &&
135+
cd build_cmake &&
136+
../bootstrap --prefix=/usr --disable-werror &&
137+
make "-j$(nproc)" &&
138+
make install-tiledb DESTDIR="/build_thirdparty" &&
139+
make install-tiledb &&
140+
cd ../.. &&
141+
rm -rf tiledb &&
142+
for i in /build_thirdparty/usr/lib/"${GCC_ARCH}"-linux-gnu/*; do strip -s "$i" 2>/dev/null || /bin/true; done &&
143+
for i in /build_thirdparty/usr/bin/*; do strip -s "$i" 2>/dev/null || /bin/true; done
144+
145+
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
146+
147+
# install geos
148+
# https://libgeos.org/usage/download/
149+
if [ "$GEOS_VERSION" = "latest" ]; then
150+
GEOS_VERSION=$(wget -qO- "https://api.github.com/repos/libgeos/geos/git/refs/tags" | grep -oP "(?<=\"ref\":\s\"refs/tags/)\d+\.\d+\.\d+" | tail -n -1)
151+
fi
152+
153+
## purge existing directories to permit re-run of script with updated versions
154+
rm -rf geos* proj* gdal*
155+
156+
wget https://download.osgeo.org/geos/geos-"${GEOS_VERSION}".tar.bz2
157+
bzip2 -d geos-*bz2
158+
tar xf geos*tar
159+
rm geos*tar
160+
cd geos*
161+
mkdir build
162+
cd build
163+
cmake ..
164+
cmake --build . --parallel "$CMAKE_CORES" --target install
165+
ldconfig
166+
cd /build_local
167+
168+
# install proj
169+
# https://download.osgeo.org/proj/
170+
if [ "$PROJ_VERSION" = "latest" ]; then
171+
PROJ_DL_URL=$(url_latest_gh_released_asset "OSGeo/PROJ")
172+
else
173+
PROJ_DL_URL="https://download.osgeo.org/proj/proj-${PROJ_VERSION}.tar.gz"
174+
fi
175+
176+
wget "$PROJ_DL_URL" -O proj.tar.gz
177+
tar zxvf proj.tar.gz
178+
rm proj.tar.gz
179+
cd proj-*
180+
mkdir build
181+
cd build
182+
cmake ..
183+
cmake --build . --parallel "$CMAKE_CORES" --target install
184+
ldconfig
185+
cd /build_local
186+
187+
# install gdal
188+
# https://download.osgeo.org/gdal/
189+
if [ "$GDAL_VERSION" = "latest" ]; then
190+
GDAL_DL_URL=$(url_latest_gh_released_asset "OSGeo/gdal")
191+
else
192+
GDAL_DL_URL="https://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz"
193+
fi
194+
195+
wget "$GDAL_DL_URL" -O gdal.tar.gz
196+
tar -xf gdal.tar.gz
197+
rm gdal*tar.gz
198+
cd gdal*
199+
mkdir build
200+
cd ./build
201+
# cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_JAVA_BINDINGS:BOOL=OFF -DBUILD_CSHARP_BINDINGS:BOOL=OFF
202+
cmake -DCMAKE_BUILD_TYPE=Release ..
203+
cmake --build . --parallel "$CMAKE_CORES" --target install
204+
ldconfig
205+
cd /build_local
206+
207+
apt-get update && apt-get -y install cargo
208+
209+
install2.r --error --skipmissing -n "$NCPUS" -r "${CRAN_SOURCE}" \
210+
sf \
211+
terra \
212+
lwgeom \
213+
stars \
214+
gdalcubes
215+
216+
# Clean up
217+
rm -rf /var/lib/apt/lists/*
218+
rm -rf /tmp/downloaded_packages
219+
220+
# Check the geospatial packages
221+
222+
echo -e "Check the stars package...\n"
223+
R -q -e "library(stars)"
224+
echo -e "\nInstall stars package, done!"

install_geospatial.sh

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# always set this for scripts but don't declare as ENV..
5+
export DEBIAN_FRONTEND=noninteractive
6+
7+
## build ARGs
8+
NCPUS=${NCPUS:--1}
9+
10+
# a function to install apt packages only if they are not installed
11+
function apt_install() {
12+
if ! dpkg -s "$@" >/dev/null 2>&1; then
13+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
14+
apt-get update
15+
fi
16+
apt-get install -y --no-install-recommends "$@"
17+
fi
18+
}
19+
20+
apt_install \
21+
gdal-bin \
22+
lbzip2 \
23+
libfftw3-dev \
24+
libgdal-dev \
25+
libgeos-dev \
26+
libgsl0-dev \
27+
libgl1-mesa-dev \
28+
libglu1-mesa-dev \
29+
libhdf4-alt-dev \
30+
libhdf5-dev \
31+
libjq-dev \
32+
libpq-dev \
33+
libproj-dev \
34+
libprotobuf-dev \
35+
libnetcdf-dev \
36+
libsqlite3-dev \
37+
libssl-dev \
38+
libudunits2-dev \
39+
netcdf-bin \
40+
postgis \
41+
protobuf-compiler \
42+
sqlite3 \
43+
tk-dev \
44+
unixodbc-dev
45+
46+
install2.r --error --skipmissing --skipinstalled -n "$NCPUS" \
47+
RColorBrewer \
48+
RandomFields \
49+
RNetCDF \
50+
classInt \
51+
deldir \
52+
gstat \
53+
hdf5r \
54+
lidR \
55+
mapdata \
56+
maptools \
57+
mapview \
58+
ncdf4 \
59+
proj4 \
60+
raster \
61+
rgdal \
62+
rgeos \
63+
rlas \
64+
sf \
65+
sfarrow \
66+
sp \
67+
spacetime \
68+
spatstat \
69+
spatialreg \
70+
spdep \
71+
stars \
72+
terra \
73+
tidync \
74+
tmap \
75+
geoR \
76+
geosphere \
77+
BiocManager
78+
79+
R -e "BiocManager::install('rhdf5')"
80+
81+
## install wgrib2 for NOAA's NOMADS / rNOMADS forecast files
82+
## This is no longer needed, but we include it for reproducibility
83+
## reasons on earlier base images.
84+
source /etc/os-release
85+
if [ "${UBUNTU_CODENAME}" == "focal" ]; then
86+
/rocker_scripts/install_wgrib2.sh
87+
fi
88+
89+
# Clean up
90+
rm -rf /var/lib/apt/lists/*
91+
rm -r /tmp/downloaded_packages
92+
93+
## Strip binary installed lybraries from RSPM
94+
## https://github.com/rocker-org/rocker-versioned2/issues/340
95+
strip /usr/local/lib/R/site-library/*/libs/*.so

0 commit comments

Comments
 (0)