Skip to content

Commit

Permalink
Use standard rocker image
Browse files Browse the repository at this point in the history
This uses the standard Rocker image and saves use over 3 gig in space (see [comment](opensafely-core#9 (comment))).

It also moves the renv setup into a separate script, where we also setup the
rstudio environment.
  • Loading branch information
lucyb committed Apr 24, 2024
1 parent ee0f2b0 commit 762eb34
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM remlapmot/r-docker:2024-04-02-rstudio-renv-1-0-7
FROM rocker/rstudio:4.0.5

# we are going to use an apt cache on the host, so disable the default debian
# docker clean up that deletes that cache on every apt install
Expand All @@ -14,11 +14,11 @@ RUN --mount=type=cache,target=/var/cache/apt \
# Pip for Python 3.10 isn't included in deadsnakes, so install separately
curl https://bootstrap.pypa.io/get-pip.py | python3.10

# copy the renv directory from the OpenSAFELY R action image and active it by
# default
RUN R -e 'renv::init(bare = TRUE)'
# install renv
RUN --mount=type=cache,target=/cache,id=/cache-2004 R -e 'install.packages("renv", destdir="/cache"); renv::init(bare = TRUE)'

# copy the renv directory from the OpenSAFELY R action image
COPY --from=ghcr.io/opensafely-core/r /renv/ /renv/
RUN echo 'source("/renv/renv/activate.R")' >> /etc/R/Rprofile.site

# Copy the Python virtualenv from OpenSAFELY Python action image
COPY --from=ghcr.io/opensafely-core/python:v2 /opt/venv /opt/venv
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dockerDashComposeVersion": "v2"
}
},
"postCreateCommand": "pip3 install --user -r .devcontainer/requirements.in",
"postCreateCommand": "/bin/bash .devcontainer/postCreate.sh",
"postAttachCommand": {
"rstudio-start": "sudo rstudio-server start"
},
Expand Down
10 changes: 10 additions & 0 deletions .devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail

pip3 install --user -r .devcontainer/requirements.in

#set R working directory
! grep -q `pwd` $R_HOME/etc/Rprofile.site && sudo tee -a $R_HOME/etc/Rprofile.site <<< "setwd(\"`pwd`\")"
#set RStudio working directory
! grep -q `pwd` ~/.config/rstudio/rstudio-prefs.json && cat ~/.config/rstudio/rstudio-prefs.json | jq ". + {\"initial_working_directory\":\"`pwd`\"}" > ~/.config/rstudio/rstudio-prefs.json

0 comments on commit 762eb34

Please sign in to comment.