diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..506a40d --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,31 @@ +FROM remlapmot/r-docker:2024-04-02-rstudio + +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 \ + echo "deb http://ppa.launchpad.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 + +# 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 + +# Required for installing opensafely cli +ENV PATH="/home/rstudio/.local/bin:${PATH}" + +USER rstudio diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..8baae2b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,43 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/python +{ + "name": "OpenSAFELY", + "image": "ghcr.io/opensafely/research-template:latest", + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "moby": true, + "azureDnsAutoDetection": true, + "installDockerBuildx": true, + "version": "latest", + "dockerDashComposeVersion": "v2" + } + }, + "postCreateCommand": "/bin/bash .devcontainer/postCreate.sh", + "postAttachCommand": { + "rstudio-start": "sudo rstudio-server start" + }, + "forwardPorts": [ + 8787 + ], + "portsAttributes": { + "8787": { + "label": "RStudio IDE" + } + }, + // Configure tool-specific properties. + "customizations": { + "vscode": { + "extensions": [ + "ms-python.python", + "ms-toolsai.jupyter", + "ms-toolsai.jupyter-renderers" + ] + } + }, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" + "remoteEnv": { + "MAX_WORKERS": "2" + } +} diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100644 index 0000000..cac58e6 --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,15 @@ +#!/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 + +#download and extract latest ehrql source +wget https://github.com/opensafely-core/ehrql/archive/main.zip -P .devcontainer +unzip -o .devcontainer/main.zip -d .devcontainer/ +rm .devcontainer/main.zip diff --git a/.devcontainer/requirements.in b/.devcontainer/requirements.in new file mode 100644 index 0000000..8136f40 --- /dev/null +++ b/.devcontainer/requirements.in @@ -0,0 +1 @@ +opensafely diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a01863..22c1591 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,7 +1,7 @@ { - "python.linting.pylintEnabled": false, - "python.linting.flake8Enabled": true, - "python.linting.enabled": true, + "python.analysis.extraPaths": [".devcontainer/ehrql-main/"], + "python.defaultInterpreterPath": "/opt/venv/bin/python3.10", + "python.terminal.activateEnvironment": true, "data.preview.create.json.schema": false, "files.associations": { "*.feather": "arrow",