Skip to content

Commit 6e7911f

Browse files
committed
and so it begins... 🌱
1 parent 9ec1c19 commit 6e7911f

File tree

6 files changed

+188
-0
lines changed

6 files changed

+188
-0
lines changed

.github/workflows/docker-rstudio.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: RStudio
2+
on:
3+
workflow_dispatch: null
4+
push:
5+
paths: ['Dockerfile']
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
permissions: write-all
10+
steps:
11+
# For biggish images, github actions runs out of disk space.
12+
# So we cleanup some unwanted things in the disk image, and reclaim that space for our docker use
13+
# https://github.com/actions/virtual-environments/issues/2606#issuecomment-772683150
14+
# and https://github.com/easimon/maximize-build-space/blob/b4d02c14493a9653fe7af06cc89ca5298071c66e/action.yml#L104
15+
# This gives us a total of about 52G of free space, which should be enough for now
16+
- name: cleanup disk space
17+
run: |
18+
sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc
19+
df -h
20+
- uses: actions/checkout@v3
21+
- name: Login to GitHub Container Registry
22+
if: github.repository == 'boettiger-lab/k8s'
23+
uses: docker/login-action@v1
24+
with:
25+
registry: ghcr.io
26+
username: ${{github.actor}}
27+
password: ${{secrets.GITHUB_TOKEN}}
28+
- name: Build the Docker image
29+
if: github.repository == 'boettiger-lab/repo2docker-r'
30+
run: docker build . --tag ghcr.io/boettiger-lab/repo2docker-r/r2u:latest
31+
- name: Publish
32+
if: github.repository == 'boettiger-lab/repo2docker-r'
33+
run: docker push ghcr.io/boettiger-lab/repo2docker-r/r2u:latest
34+

Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM quay.io/jupyter/minimal-notebook
2+
3+
USER root
4+
5+
# Install R
6+
COPY install_r.sh install_r.sh
7+
RUN bash install_r.sh
8+
9+
## RStudio
10+
RUN conda install jupyter-rsession-proxy
11+
COPY install_rstudio.sh install_rstudio.sh
12+
RUN bash install_rstudio.sh
13+
14+
COPY environment.yml environment.yml
15+
RUN conda env update -f environment.yml
16+
17+
COPY install.r install.r
18+
RUN Rscript install.R
19+
20+
USER ${NB_USER}
21+

environment.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: base
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- seaborn
6+
- ibis-duckdb
7+

install.r

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
install.packages(c("sf", "terra", "stars", "rstan", "ROracle"))
3+

install_r.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
## First: update apt and get keys
4+
apt update -qq && apt install --yes --no-install-recommends wget ca-certificates gnupg
5+
wget -q -O- https://eddelbuettel.github.io/r2u/assets/dirk_eddelbuettel_key.asc \
6+
| tee -a /etc/apt/trusted.gpg.d/cranapt_key.asc
7+
8+
## Second: add the repo -- here we use the well-connected mirror
9+
echo "deb [arch=amd64] https://r2u.stat.illinois.edu/ubuntu noble main" > /etc/apt/sources.list.d/cranapt.list
10+
apt update
11+
12+
## Third: ensure current R is used
13+
wget -q -O- https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc \
14+
| tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
15+
echo "deb [arch=amd64] https://cloud.r-project.org/bin/linux/ubuntu noble-cran40/" > /etc/apt/sources.list.d/cran_r.list
16+
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 67C2D66C4B1D4339 51716619E084DAB9
17+
apt update -qq
18+
DEBIAN_FRONTEND=noninteractive apt install --yes --no-install-recommends r-base r-base-dev r-recommended
19+
20+
## Fourth: add pinning to ensure package sorting
21+
echo "Package: *" > /etc/apt/preferences.d/99cranapt
22+
echo "Pin: release o=CRAN-Apt Project" >> /etc/apt/preferences.d/99cranapt
23+
echo "Pin: release l=CRAN-Apt Packages" >> /etc/apt/preferences.d/99cranapt
24+
echo "Pin-Priority: 700" >> /etc/apt/preferences.d/99cranapt
25+
26+
## Fifth: install bspm (and its Python requirements) and enable it
27+
## If needed (in bare container, say) install python tools for bspm and R itself
28+
apt install --yes --no-install-recommends python3-{dbus,gi,apt} \
29+
make sudo r-cran-{docopt,littler,remotes}
30+
## Then install bspm (as root) and enable it, and enable a speed optimization
31+
Rscript -e 'install.packages("bspm")'
32+
RHOME=$(R RHOME)
33+
echo "suppressMessages(bspm::enable())" >> ${RHOME}/etc/Rprofile.site
34+
echo "options(bspm.version.check=FALSE)" >> ${RHOME}/etc/Rprofile.site
35+
36+
chown root:staff ${RHOME}/site-library
37+
chmod g+ws ${RHOME}/site-library
38+
echo "options('bspm.sudo' = TRUE)" >> ${RHOME}/etc/Rprofile.site
39+
40+
41+
ln -s /usr/lib/R/site-library/littler/examples/install2.r /usr/local/bin/install2.r
42+
43+
44+
## add user to sudoers
45+
usermod -a -G staff ${NB_USER}
46+
echo "${NB_USER} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
47+
48+

install_rstudio.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
set -e
3+
4+
RSTUDIO_VERSION=${1:-${RSTUDIO_VERSION:-"stable"}}
5+
DEFAULT_USER=${DEFAULT_USER:-"rstudio"}
6+
7+
apt-get update && apt-get -y install \
8+
ca-certificates \
9+
gdebi-core \
10+
git \
11+
libclang-dev \
12+
libssl-dev \
13+
lsb-release \
14+
psmisc \
15+
pwgen \
16+
sudo \
17+
wget
18+
19+
ARCH=$(dpkg --print-architecture)
20+
UBUNTU_CODENAME="noble"
21+
22+
## Download RStudio Server for Ubuntu 18+
23+
DOWNLOAD_FILE=rstudio-server.deb
24+
25+
if [ "$RSTUDIO_VERSION" = "latest" ]; then
26+
RSTUDIO_VERSION="stable"
27+
fi
28+
29+
if [ "$UBUNTU_CODENAME" = "focal" ]; then
30+
UBUNTU_CODENAME="bionic"
31+
fi
32+
33+
# TODO: remove this workaround for Ubuntu 24.04
34+
if [ "$UBUNTU_CODENAME" = "noble" ]; then
35+
UBUNTU_CODENAME="jammy"
36+
fi
37+
38+
if [ "$RSTUDIO_VERSION" = "stable" ] || [ "$RSTUDIO_VERSION" = "preview" ] || [ "$RSTUDIO_VERSION" = "daily" ]; then
39+
if [ "$UBUNTU_CODENAME" = "bionic" ]; then
40+
UBUNTU_CODENAME="focal"
41+
fi
42+
wget "https://rstudio.org/download/latest/${RSTUDIO_VERSION}/server/${UBUNTU_CODENAME}/rstudio-server-latest-${ARCH}.deb" -O "$DOWNLOAD_FILE"
43+
else
44+
wget "https://download2.rstudio.org/server/${UBUNTU_CODENAME}/${ARCH}/rstudio-server-${RSTUDIO_VERSION/"+"/"-"}-${ARCH}.deb" -O "$DOWNLOAD_FILE" ||
45+
wget "https://s3.amazonaws.com/rstudio-ide-build/server/${UBUNTU_CODENAME}/${ARCH}/rstudio-server-${RSTUDIO_VERSION/"+"/"-"}-${ARCH}.deb" -O "$DOWNLOAD_FILE"
46+
fi
47+
48+
gdebi --non-interactive "$DOWNLOAD_FILE"
49+
rm "$DOWNLOAD_FILE"
50+
51+
ln -fs /usr/lib/rstudio-server/bin/rstudio-server /usr/local/bin
52+
ln -fs /usr/lib/rstudio-server/bin/rserver /usr/local/bin
53+
54+
# https://github.com/rocker-org/rocker-versioned2/issues/137
55+
rm -f /var/lib/rstudio-server/secure-cookie-key
56+
57+
## RStudio wants an /etc/R, will populate from $R_HOME/etc
58+
mkdir -p /etc/R
59+
60+
## Make RStudio compatible with case when R is built from source
61+
## (and thus is at /usr/local/bin/R), because RStudio doesn't obey
62+
## path if a user apt-get installs a package
63+
R_BIN="$(which R)"
64+
echo "rsession-which-r=${R_BIN}" >/etc/rstudio/rserver.conf
65+
## use more robust file locking to avoid errors when using shared volumes:
66+
echo "lock-type=advisory" >/etc/rstudio/file-locks
67+
68+
## Prepare optional configuration file to disable authentication
69+
## To de-activate authentication, `disable_auth_rserver.conf` script
70+
## will just need to be overwrite /etc/rstudio/rserver.conf.
71+
## This is triggered by an env var in the user config
72+
cp /etc/rstudio/rserver.conf /etc/rstudio/disable_auth_rserver.conf
73+
echo "auth-none=1" >>/etc/rstudio/disable_auth_rserver.conf
74+
75+

0 commit comments

Comments
 (0)