Skip to content

Commit

Permalink
Merge pull request #10 from opensafely-core/Jongmassey/port-R-fixes
Browse files Browse the repository at this point in the history
Port R and Python fixes from research template "improve devcontainers" branch
  • Loading branch information
Jongmassey authored May 3, 2024
2 parents 4ba3b45 + 2655799 commit e743fce
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ LABEL org.opencontainers.image.source https://github.com/opensafely/research-tem
# docker clean up that deletes that cache on every apt install
RUN rm -f /etc/apt/apt.conf.d/docker-clean

# Install python 3.10. This is the version used by the python-docker
# image, used for analyses using the OpenSAFELY pipeline.
#
# DL3042: we always want latest package versions when we rebuild
# DL3013: using an apt cache on the host instead
# hadolint ignore=DL3042,DL3013
Expand All @@ -17,33 +14,38 @@ RUN --mount=type=cache,target=/var/cache/apt \
echo "deb http://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu focal main" > /etc/apt/sources.list.d/deadsnakes-ppa.list &&\
/usr/lib/apt/apt-helper download-file 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xf23c5a6cf475977595c89f51ba6932366a755776' /etc/apt/trusted.gpg.d/deadsnakes.asc &&\
apt-get update &&\
# Install python 3.10. This is the version used by the python-docker
# image, used for analyses using the OpenSAFELY pipeline.
apt-get install -y --no-install-recommends curl python3.10 python3.10-distutils python3.10-venv &&\
# Pip for Python 3.10 isn't included in deadsnakes, so install separately
curl https://bootstrap.pypa.io/get-pip.py | python3.10 &&\
# Set default python, so that the Python virtualenv works as expected
rm /usr/bin/python3 &&\
ln -s /usr/bin/python3.10 /usr/bin/python3

# install renv
RUN --mount=type=cache,target=/cache,id=/cache-2004 R -e 'install.packages("renv", destdir="/cache"); renv::init(bare = TRUE)'
ln -s /usr/bin/python3.10 /usr/bin/python3 &&\
# Create a fake system Python pointing at venv python
echo 'exec /opt/venv/bin/python3.10 "$@"' > /usr/bin/python &&\
# Configure RStudio Server to run without auth
echo "auth-none=1" >> /etc/rstudio/rserver.conf &&\
echo "USER=rstudio" >> /etc/environment &&\
# Remove the packages shipped with the rocker image
rm -rf /usr/library/lib/R/site-library/* &&\
# Give the local user sudo (aka root) permissions
usermod -aG sudo rstudio &&\
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

# copy the renv directory from the OpenSAFELY R action image
# Copy the Python virtualenv from OpenSAFELY Python action image
#
# DL3022: hadolint can't access a network and doesn't behave
# as expected when a reference is made to an external image.
# hadolint ignore=DL3022
COPY --from=ghcr.io/opensafely-core/r /renv/ /renv/
COPY --chown=rstudio:rstudio --from=ghcr.io/opensafely-core/python:v2 /opt/venv /opt/venv

# Copy the Python virtualenv from OpenSAFELY Python action image
# copy the renv directory into the local site library from the OpenSAFELY R action image
#
# DL3022: hadolint can't access a network and doesn't behave
# as expected when a reference is made to an external image.
# hadolint ignore=DL3022
COPY --from=ghcr.io/opensafely-core/python:v2 /opt/venv /opt/venv

# Create a local user and give it sudo (aka root) permissions
RUN usermod -aG sudo rstudio &&\
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
COPY --chown=rstudio:rstudio --from=ghcr.io/opensafely-core/r:latest /renv/lib/R-4.0/x86_64-pc-linux-gnu/ /usr/local/lib/R/site-library

# Required for installing opensafely cli
ENV PATH="/home/rstudio/.local/bin:${PATH}"
Expand Down

0 comments on commit e743fce

Please sign in to comment.