Skip to content

Commit

Permalink
Render notebook via CLI (#48)
Browse files Browse the repository at this point in the history
* Patch README after title duplication

* Use native RStudio env vars in .env

* Fix conda env sage-bionetworks and add docker-entrypoint.sh

* Update README

* Fix typo in docker-compose.yml
  • Loading branch information
tschaffter authored May 19, 2021
1 parent de9bff3 commit babf579
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
10 changes: 5 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# RStudio
RSTUDIO_USER=rstudio
RSTUDIO_PASSWORD=yourpassword
RSTUDIO_USERID=1000
RSTUDIO_GROUPID=1000
RSTUDIO_ROOT=FALSE
USER=rstudio
PASSWORD=yourpassword
USERID=1000
GROUPID=1000
ROOT=FALSE

# Synapse
SYNAPSE_TOKEN=yourtoken
Expand Down
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ RUN apt-get update -qq -y \
&& apt-get install --no-install-recommends -qq -y \
bash-completion \
curl \
gosu \
libxml2-dev \
zlib1g-dev \
# Fix https://github.com/tschaffter/rstudio/issues/11 (1/2)
Expand All @@ -41,11 +42,11 @@ RUN apt-get update -qq -y \
# Create conda environments
COPY conda /tmp/conda
RUN conda init bash \
&& conda env create -f /tmp/conda/sage-bionetworks/environment.yaml \
&& conda env create -f /tmp/conda/sage-bionetworks/environment.yml \
&& rm -fr /tmp/conda \
# Fix libssl issue that affects conda env used with reticulate
&& cp /usr/lib/x86_64-linux-gnu/libssl.so.1.1 \
/opt/miniconda/envs/sage/lib/libssl.so.1.1 \
/opt/miniconda/envs/sage-bionetworks/lib/libssl.so.1.1 \
&& conda activate base || true \
&& echo "conda activate sage-bionetworks" >> ~/.bashrc

Expand All @@ -59,4 +60,11 @@ RUN install2.r --error renv \

# Configure S6 init system
RUN mv /etc/cont-init.d/userconf /etc/cont-init.d/10-rstudio-userconf
COPY root /
COPY root /

WORKDIR /
COPY docker-entrypoint.sh .
RUN chmod +x docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["rstudio"]
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,20 @@ $ id
uid=1000(kelsey) gid=1000(kelsey) groups=1000(kelsey)
```

In this example, we would set `RSTUDIO_USERID=1000` and `RSTUDIO_GROUPID=1000`.
In this example, we would set `USERID=1000` and `GROUPID=1000`.

## Giving the user root permissions

Set the environment variable `ROOT=TRUE` (default is `FALSE`).

## Accessing logs

## Setting Synapse credentials

```console
docker logs --follow rstudio
```

## Generating an HTML notebook

## Generating an HTML notebook

This Docker image provides the command `render` that generates an HTML or PDF
notebook from an R notebook (*.Rmd*). Run the command below from the host to
mount the directory `$(pwd)/notebooks` where the R notebook is and generate the
Expand All @@ -154,8 +150,9 @@ HTML notebook that will be saved to the same directory with the extension

```console
docker run --rm \
--env-file .env \
-v $(pwd)/notebooks:/data \
-e RENDER_INPUT="/data/example.Rmd" \
-e RENDER_INPUT="/data/examples/notebook.Rmd" \
tschaffter/rstudio \
render
```
Expand Down
14 changes: 5 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ version: "3.8"

services:
rstudio:
image: tschaffter/rstudio:latest
image: tschaffter/rstudio:4.0.5
build:
context: .
dockerfile: Dockerfile
container_name: rstudio
environment:
- USER=${RSTUDIO_USER}
- PASSWORD=${RSTUDIO_PASSWORD}
- USERID=${RSTUDIO_USERID}
- GROUPID=${RSTUDIO_GROUPID}
- ROOT=${RSTUDIO_ROOT}
- SYNAPSE_TOKEN
env_file:
- .env
volumes:
- .:/home/rstudio/awesome-project:rw
ports:
- "${HOST_PORT}:8787"
- "${HOST_PORT}:8787"
command: rstudio
10 changes: 10 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

set -e

if [ "$1" = 'rstudio' ]; then
# RStudio userconf.sh script runs RStudio as $USER
exec /init
fi

exec /init gosu $USER "$@"
2 changes: 2 additions & 0 deletions root/etc/cont-init.d/20-create-rstudio-logfolder
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/bin/sh
#
# Enable logging for RStudio.

mkdir -p /var/log/rstudio
chown nobody:nogroup /var/log/rstudio
27 changes: 10 additions & 17 deletions root/etc/cont-init.d/30-configure-user
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/with-contenv bash
#
# Prepare the user's environment.

set -euo pipefail

Expand All @@ -11,6 +13,14 @@ BASHRC_FILENAME="/home/${USER}/.bashrc"
# Change the shell of the user to bash
usermod --shell /bin/bash ${USER}

# Create ~/.bashrc
if [[ ! -f ${BASHRC_FILENAME} ]]; then
echo "export PATH=${PATH}" > ${BASHRC_FILENAME}

chown "${USER}:${USER}" ${BASHRC_FILENAME}
chmod 644 ${BASHRC_FILENAME}
fi

# Create Synapse Python client configuration file
if [[ ! -z ${SYNAPSE_TOKEN} ]]; then
if [ ! -f ${SYNAPSE_CONFIG_FILENAME} ]; then
Expand All @@ -23,23 +33,6 @@ if [[ ! -z ${SYNAPSE_TOKEN} ]]; then
fi
fi

# Create ~/.bashrc
if [[ ! -f ${BASHRC_FILENAME} ]]; then
echo "export PATH=${PATH}" > ${BASHRC_FILENAME}

chown "${USER}:${USER}" ${BASHRC_FILENAME}
chmod 644 ${BASHRC_FILENAME}
fi

# Fix sudo: setrlimit(RLIMIT_CORE): Operation not permitted
# https://github.com/sudo-project/sudo/issues/42#issuecomment-659253293
echo "Set disable_coredump false" >> /etc/sudo.conf

# Configure shell to use `conda activate`
# TODO

# sudo -u rstudio bash <<EOF
# conda --version
# conda config --set auto_activate_base false
# conda init bash
# EOF

0 comments on commit babf579

Please sign in to comment.