Skip to content

Commit

Permalink
Add initial devcontainer Dockerfile
Browse files Browse the repository at this point in the history
This copies the updated dockerfile from the research-template repo (see this
[PR](opensafely/research-template#120)).
  • Loading branch information
lucyb committed Apr 26, 2024
1 parent 2b632f5 commit 9d93903
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
6 changes: 5 additions & 1 deletion DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ source <(just --completions bash)

# Show all available commands
just # shortcut for just --list
```
```

## Build instructions

Run `just build` to build the Docker image.
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM rocker/rstudio:4.0.5

LABEL org.opencontainers.image.source https://github.com/opensafely/research-template

# 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
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.
RUN --mount=type=cache,target=/var/cache/apt \

Check failure on line 11 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfile

DL3027 warning: Do not use apt as it is meant to be a end-user tool, use apt-get or apt-cache instead

Check failure on line 11 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfile

DL4006 warning: Set the SHELL option -o pipefail before RUN with a pipe in it. If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox then consider explicitly setting your SHELL to /bin/ash, or disable this check
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 update &&\
apt install -y 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)'

# copy the renv directory from the OpenSAFELY R action image
COPY --from=ghcr.io/opensafely-core/r /renv/ /renv/

Check failure on line 25 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfile

DL3022 warning: `COPY --from` should reference a previously defined `FROM` alias

# Copy the Python virtualenv from OpenSAFELY Python action image
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
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

Check failure on line 32 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint-dockerfile

DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.

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

USER rstudio
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ set dotenv-load := true
# list available commands
default:
@"{{ just_executable() }}" --list

build:
docker build .

0 comments on commit 9d93903

Please sign in to comment.