Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port R and Python fixes from research template "improve devcontainers" branch #10

Merged
merged 5 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,46 @@
# 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
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN --mount=type=cache,target=/var/cache/apt \

Check failure on line 13 in Dockerfile

View workflow job for this annotation

GitHub Actions / build-and-test

DL3008 warning: Pin versions in apt get install. Instead of `apt-get install <package>` use `apt-get install <package>=<version>`
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