Support custom installation paths for R

This commit is contained in:
Greg Lin 2023-01-09 14:31:58 -06:00
commit cca0417d89
12 changed files with 104 additions and 46 deletions

View file

@ -5,6 +5,7 @@ export CRAN=${CRAN-"https://cran.rstudio.com"}
export S3_BUCKET_PREFIX=${S3_BUCKET_PREFIX-""}
export OS_IDENTIFIER=${OS_IDENTIFIER-"unknown"}
export TARBALL_NAME="R-${R_VERSION}-${OS_IDENTIFIER}.tar.gz"
export R_INSTALL_PATH=${R_INSTALL_PATH:-"/opt/R/${R_VERSION}"}
# Some Dockerfiles may copy a `/env.sh` to set up environment variables
# that require command substitution. If this file exists, source it.
@ -33,9 +34,11 @@ upload_r() {
fi
}
# archive_r() - $1 as r version
# archive_r()
archive_r() {
tar czf /tmp/${TARBALL_NAME} --directory=/opt/R ${1} --owner=0 --group=0
dir=$(dirname "$R_INSTALL_PATH")
base=$(basename "$R_INSTALL_PATH")
tar czf "/tmp/${TARBALL_NAME}" --directory="$dir" "$base" --owner=0 --group=0
}
fetch_r_source() {
@ -130,7 +133,7 @@ compile_r() {
R_UNZIPCMD=/usr/bin/unzip \
R_ZIPCMD=/usr/bin/zip \
./configure \
--prefix=/opt/R/${1} \
--prefix="${R_INSTALL_PATH}" \
${CONFIGURE_OPTIONS} \
${build_flag}
make clean
@ -139,7 +142,7 @@ compile_r() {
# Add OS identifier to the default HTTP user agent.
# Set this in the system Rprofile so it works when R is run with --vanilla.
cat <<EOF >> /opt/R/${1}/lib/R/library/base/R/Rprofile
cat <<EOF >> "${R_INSTALL_PATH}"/lib/R/library/base/R/Rprofile
## Set the default HTTP user agent
local({
os_identifier <- if (file.exists("/etc/os-release")) {
@ -167,7 +170,7 @@ package_r() {
}
set_up_environment() {
mkdir -p /opt/R
mkdir -p "$R_INSTALL_PATH"
}
_version_is_greater_than() {
@ -183,5 +186,5 @@ set_up_environment
fetch_r_source $R_VERSION
compile_r $R_VERSION
package_r $R_VERSION
archive_r $R_VERSION
archive_r
upload_r $R_VERSION

View file

@ -3,6 +3,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -14,6 +15,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -25,6 +27,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -36,6 +39,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -47,6 +51,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -58,6 +63,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -69,6 +75,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -80,6 +87,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -91,6 +99,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .
@ -102,6 +111,7 @@ services:
command: ./build.sh
environment:
- R_VERSION=${R_VERSION}
- R_INSTALL_PATH=${R_INSTALL_PATH}
- LOCAL_STORE=/tmp/output
build:
context: .

View file

@ -12,14 +12,14 @@ fi
# create post-install script required for openblas
cat <<EOF >> /post-install.sh
mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblasp.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so
mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblasp.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so
EOF
# create after-remove script to remove internal blas
cat <<EOF >> /after-remove.sh
if [ -d /opt/R/${R_VERSION} ]; then
rm -r /opt/R/${R_VERSION}
if [ -d ${R_INSTALL_PATH} ]; then
rm -r ${R_INSTALL_PATH}
fi
EOF
@ -57,8 +57,8 @@ depends:
- zip
- zlib-devel
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
scripts:
postinstall: /post-install.sh
postremove: /after-remove.sh

View file

@ -12,14 +12,14 @@ fi
# create post-install script required for openblas
cat <<EOF >> /post-install.sh
mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblasp.so.0 /opt/R/${R_VERSION}/lib/R/lib/libRblas.so
mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblasp.so.0 ${R_INSTALL_PATH}/lib/R/lib/libRblas.so
EOF
# create after-remove script to remove internal blas
cat <<EOF >> /after-remove.sh
if [ -d /opt/R/${R_VERSION} ]; then
rm -r /opt/R/${R_VERSION}
if [ -d ${R_INSTALL_PATH} ]; then
rm -r ${R_INSTALL_PATH}
fi
EOF
@ -57,8 +57,8 @@ depends:
- zip
- zlib-devel
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
scripts:
postinstall: /post-install.sh
postremove: /after-remove.sh

View file

@ -56,8 +56,8 @@ depends:
- zip
- zlib1g-dev
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
EOF
nfpm package \

View file

@ -57,8 +57,8 @@ ${pcre_libs}
- zip
- zlib1g-dev
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
EOF
nfpm package \

View file

@ -12,14 +12,14 @@ fi
# create post-install script required for openblas
cat <<EOF >> /post-install.sh
mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so
mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so
EOF
# create after-remove script to remove internal blas
cat <<EOF >> /after-remove.sh
if [ -d /opt/R/${R_VERSION} ]; then
rm -r /opt/R/${R_VERSION}
if [ -d ${R_INSTALL_PATH} ]; then
rm -r ${R_INSTALL_PATH}
fi
EOF
@ -66,8 +66,8 @@ depends:
- zip
- zlib-devel
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
scripts:
postinstall: /post-install.sh
postremove: /after-remove.sh

View file

@ -28,14 +28,14 @@ fi
#
# https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Shared-BLAS
cat <<EOF >> /post-install.sh
mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so
mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so
EOF
# Create after-remove script to remove internal BLAS, which won't be cleaned up automatically.
cat <<EOF >> /after-remove.sh
if [ -d /opt/R/${R_VERSION} ]; then
rm -r /opt/R/${R_VERSION}
if [ -d ${R_INSTALL_PATH} ]; then
rm -r ${R_INSTALL_PATH}
fi
EOF
@ -82,8 +82,8 @@ depends:
- zip
- zlib-devel
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
scripts:
postinstall: /post-install.sh
postremove: /after-remove.sh

View file

@ -29,14 +29,14 @@ fi
#
# https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Shared-BLAS
cat <<EOF >> /post-install.sh
mv /opt/R/${R_VERSION}/lib/R/lib/libRblas.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblasp.so /opt/R/${R_VERSION}/lib/R/lib/libRblas.so
mv ${R_INSTALL_PATH}/lib/R/lib/libRblas.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so.keep
ln -s /usr/lib64/libopenblasp.so ${R_INSTALL_PATH}/lib/R/lib/libRblas.so
EOF
# Create after-remove script to remove internal BLAS, which won't be cleaned up automatically.
cat <<EOF >> /after-remove.sh
if [ -d /opt/R/${R_VERSION} ]; then
rm -r /opt/R/${R_VERSION}
if [ -d ${R_INSTALL_PATH} ]; then
rm -r ${R_INSTALL_PATH}
fi
EOF
@ -74,8 +74,8 @@ ${pcre_libs}
- zip
- zlib-devel
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
scripts:
postinstall: /post-install.sh
postremove: /after-remove.sh

View file

@ -56,8 +56,8 @@ depends:
- zip
- zlib1g-dev
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
EOF
nfpm package \

View file

@ -57,8 +57,8 @@ depends:
- zip
- zlib1g-dev
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
EOF
nfpm package \

View file

@ -57,8 +57,8 @@ ${pcre_libs}
- zip
- zlib1g-dev
contents:
- src: /opt/R/${R_VERSION}
dst: /opt/R/${R_VERSION}
- src: ${R_INSTALL_PATH}
dst: ${R_INSTALL_PATH}
EOF
nfpm package \