Skip to content

Instantly share code, notes, and snippets.

@Alain-Bearez
Created August 12, 2020 17:35
Show Gist options
  • Save Alain-Bearez/478d61607f9ad275d1f97ac1f179ed16 to your computer and use it in GitHub Desktop.
Save Alain-Bearez/478d61607f9ad275d1f97ac1f179ed16 to your computer and use it in GitHub Desktop.
Dockerfile to build an Oracle Linux 8 image with GraalVM 20.1.0 and FastR installed, as well as some commonly used R packages pre-installed.
# based on https://github.com/graalvm/container/blob/master/community/Dockerfile.ol8-java11
# Pull base image
FROM oraclelinux:8-slim
# Note: If you are behind a web proxy, set the build variables for the build:
# E.g.: docker build --build-arg "https_proxy=..." --build-arg "http_proxy=..." --build-arg "no_proxy=..." ...
# Env variables
ARG GRAALVM_VERSION=20.1.0
ARG JAVA_VERSION=java11
ARG GRAALVM_PKG=https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-${GRAALVM_VERSION}/graalvm-ce-${JAVA_VERSION}-GRAALVM_ARCH-${GRAALVM_VERSION}.tar.gz
ARG TARGET_PLATFORM=amd64
ARG USER_ID=1001
ARG GROUP_ID=1001
ENV LANG=en_US.UTF-8 \
JAVA_HOME=/opt/graalvm-ce-${JAVA_VERSION}-${GRAALVM_VERSION}
# Install necessary libraries and tools for FastR packages compilation
RUN \
mkdir -p /etc/dnf/ \
&& echo "[main]" > /etc/dnf/dnf.conf \
&& echo "obsoletes=false" >> /etc/dnf/dnf.conf \
&& mkdir -p /usr/share/info/ \
&& touch /usr/share/info/history.info \
&& microdnf update -y oraclelinux-release-el8 \
&& microdnf --enablerepo ol8_codeready_builder install bzip2 ed findutils gzip file fontconfig less make openssl shadow-utils tar vi which \
gcc gcc-c++ gcc-gfortran glibc-static libgfortran libstdc++ libstdc++-static zlib-static \
bzip2-devel libcurl-devel libstdc++-devel libxml2-devel openssl-devel readline-devel xz-devel zlib-devel \
&& microdnf clean all
RUN fc-cache -f -v
# Install GraalVM
## Piping curl directly in tar
RUN \
set -eux \
&& if [ "$TARGET_PLATFORM" == "amd64" ]; then GRAALVM_PKG=${GRAALVM_PKG/GRAALVM_ARCH/linux-amd64}; fi \
&& if [ "$TARGET_PLATFORM" == "arm64" ]; then GRAALVM_PKG=${GRAALVM_PKG/GRAALVM_ARCH/linux-aarch64}; fi \
&& curl --fail --silent --location --retry 3 ${GRAALVM_PKG} | gunzip | tar x -C /opt/ \
# Set alternative links
&& mkdir -p /usr/java/ \
&& ln -sfT "${JAVA_HOME}" /usr/java/default \
&& ln -sfT "${JAVA_HOME}" /usr/java/latest \
&& for bin in "${JAVA_HOME}/bin/"*; do \
base="$(basename "$bin")"; \
[ ! -e "/usr/bin/$base" ]; \
alternatives --install "/usr/bin/$base" "$base" "$bin" 20000; \
done
ADD gu-wrapper.sh /usr/local/bin/gu
# Add and use user ufastr
RUN \
mkdir /logs/ \
&& chmod +x /usr/local/bin/gu \
&& groupadd --gid ${GROUP_ID} ufastr \
&& useradd --gid ${GROUP_ID} --uid ${USER_ID} ufastr --shell /bin/bash \
&& chown -R ufastr:ufastr /opt/ \
&& chown -R ufastr:ufastr /logs/
ENV R_HOME=${JAVA_HOME}/languages/R
RUN \
gu install R \
&& ${R_HOME}/bin/configure_fastr \
&& mkdir -p ${R_HOME}/library/ \
&& mkdir -p ${R_HOME}/doc/html/ \
&& chown ufastr.ufastr ${R_HOME}/library/ \
&& chown ufastr.ufastr ${R_HOME}/doc/html/ \
&& touch ${R_HOME}/doc/html/packages.html \
&& chown ufastr.ufastr ${R_HOME}/doc/html/packages.html
# Switch working directory
USER ufastr
WORKDIR /home/ufastr
# Pre-install most commonly used packages
RUN \
Rscript -e "install.fastr.packages('data.table')" \
&& Rscript -e "install.packages('shiny')"
# Switch working directory back to root
## Users wanting to use this container as non-root should combine the two following arguments
## -u ufastr
## -w /home/ufastr
USER root
WORKDIR /root

Error on the last package installed

After some long minutes installing successfully all packages shiny depends on, the test about lazy loading fails with no workable information to fix the error cause:

* installing *source* package ?shiny? ...
** package ?shiny? successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
/bin/sh: line 1: 20317 Killed                  R_TESTS= '/opt/graalvm-ce-java11-20.1.0/languages/R/bin/R' --no-save --slave 2>&1 < '/tmp/Rtmp92BoVy/filei1xa1wtvegi0'
ERROR: lazy loading failed for package ?shiny?
* removing ?/opt/graalvm-ce-java11-20.1.0/languages/R/library/shiny?

The downloaded source packages are in
	?/tmp/Rtmp6veE9G/downloaded_packages?
Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
Warning message:
In install.packages("shiny") :
  installation of package ?shiny? had non-zero exit status
@Alain-Bearez
Copy link
Author

The Docker image can be produced with development releases of GraalVM by specifying the GRAALVM_PKG build argument as in:

⨯ docker build \
                           -f Dockerfile.ol8-java11 \
                           --build-arg GRAALVM_PKG="https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/20.3.0-dev-20200812_0203/graalvm-ce-java11-linux-amd64-20.3.0-dev.tar.gz" \
                           --build-arg GRAALVM_VERSION=20.3.0-dev \
                           --output=type=docker \
                           -t cuali/fastr-dev:20.3.0-dev-java11-amd64 \
                           .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment