Skip to content

Commit ce61f1f

Browse files
committed
Working version using docker cp rather than mounts
Base on MS devcontainer Jammy image to match OpenSAFELY base image. Install R/Python and their dependencies. Use `docker cp` to copy the R/Python library files to the host filesystem which avoids any of the previously seen issues with mounting a running container. These library directories don't contain any symlinks (verified with `find . -type l`).
1 parent fc4b32d commit ce61f1f

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
// README at: https://github.com/devcontainers/templates/tree/main/src/python
33
{
44
"name": "OpenSAFELY",
5-
"image": "ghcr.io/opensafely-core/research-template:v0",
5+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04",
66
// Features to add to the dev container. More info: https://containers.dev/features.
77
"features": {
88
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
99
},
10-
"postCreateCommand": "/bin/bash /opt/devcontainer/postCreate.sh ${containerWorkspaceFolder}",
11-
"postAttachCommand": "/bin/bash /opt/devcontainer/postAttach.sh",
10+
"postCreateCommand": "/bin/bash .devcontainer/postCreate.sh",
11+
"postAttachCommand": "/bin/bash .devcontainer/postAttach.sh",
1212
"forwardPorts": [
1313
8787
1414
],
@@ -41,7 +41,7 @@
4141
"files.autoSaveDelay": 1000,
4242
"git.autofetch": true,
4343
"python.analysis.extraPaths": [".devcontainer/ehrql-main/"],
44-
"python.defaultInterpreterPath": "/opt/venv/bin/python",
44+
"python.defaultInterpreterPath": "./venv/bin/python",
4545
"python.terminal.activateEnvInCurrentTerminal": true,
4646
"python.terminal.activateEnvironment": true,
4747
"window.autoDetectColorScheme": true

.devcontainer/postAttach.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
opensafely launch rstudio -p 8787 &

.devcontainer/postCreate.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#download and extract latest ehrql source
2+
wget https://github.com/opensafely-core/ehrql/archive/main.zip -P .devcontainer
3+
unzip -o .devcontainer/main.zip -d .devcontainer/
4+
rm .devcontainer/main.zip
5+
6+
# install python and dependencies, set up virtualenv
7+
sudo apt update
8+
wget https://github.com/opensafely-core/python-docker/raw/refs/heads/main/v2/dependencies.txt -q -O - | sed 's/^#.*//' | sudo xargs apt-get install --yes --no-install-recommends
9+
pip install virtualenv opensafely
10+
python3 -m virtualenv .venv
11+
rm -rf .venv/lib
12+
docker container create --name python-v2 ghcr.io/opensafely-core/python:v2
13+
docker cp python-v2:/opt/venv/lib .venv/
14+
docker rm python-v2
15+
16+
# install R and dependencies
17+
echo "deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/" | sudo tee /etc/apt/sources.list.d/cran.list >/dev/null
18+
sudo /usr/lib/apt/apt-helper download-file 'https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc' /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc
19+
sudo apt update
20+
wget https://raw.githubusercontent.com/opensafely-core/r-docker/refs/heads/main/v2/dependencies.txt -q -O - | sed 's/^#.*//' | sudo xargs apt-get install --yes --no-install-recommends
21+
wget https://raw.githubusercontent.com/opensafely-core/r-docker/refs/heads/main/scripts/rprofile-site-append-1.R -q -O - | sudo tee -a /usr/lib/R/etc/Rprofile.site >/dev/null
22+
wget https://raw.githubusercontent.com/opensafely-core/r-docker/refs/heads/main/scripts/rprofile-site-append-2.R -q -O - | sudo tee -a /usr/lib/R/etc/Rprofile.site >/dev/null
23+
docker create --name r-v2 --rm ghcr.io/opensafely-core/r:v2
24+
sudo docker cp r-v2:/usr/local/lib/R/site-library /usr/local/lib/R/
25+
sudo chown -R vscode:vscode /usr/local/lib/R/site-library/

0 commit comments

Comments
 (0)