forked from opensafely/comparative-booster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will provide a development environment for researchers containing: * Python 3.10 * The equivalent Python packages based on the Python Action image, including ehrql * R 4.0.5 * RStudio * The equivalent R packages based on the R Action image This can be used in Codespaces or locally via devcontainers in VS Code. It's based on the work being done for opensafely-core/codespaces-initiative#43.
- Loading branch information
Showing
5 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
opensafely |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters