Skip to content

Commit 1127a88

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 1127a88

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 5 additions & 5 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
],
@@ -40,8 +40,8 @@
4040
"files.autoSave": "afterDelay",
4141
"files.autoSaveDelay": 1000,
4242
"git.autofetch": true,
43-
"python.analysis.extraPaths": [".devcontainer/ehrql-main/"],
44-
"python.defaultInterpreterPath": "/opt/venv/bin/python",
43+
"python.analysis.extraPaths": [".ehrql/"],
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# install python and dependencies, set up virtualenv
2+
sudo apt update
3+
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
4+
pip install virtualenv opensafely
5+
python3 -m virtualenv .venv
6+
rm -rf .venv/lib
7+
docker container create --name python-v2 ghcr.io/opensafely-core/python:v2
8+
docker cp python-v2:/opt/venv/lib .venv/
9+
docker rm python-v2
10+
11+
# install R and dependencies
12+
echo "deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/" | sudo tee /etc/apt/sources.list.d/cran.list >/dev/null
13+
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
14+
sudo apt update
15+
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
16+
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
17+
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
18+
docker create --name r-v2 --rm ghcr.io/opensafely-core/r:v2
19+
sudo docker cp r-v2:/usr/local/lib/R/site-library /usr/local/lib/R/
20+
sudo chown -R vscode:vscode /usr/local/lib/R/site-library/
21+
22+
23+
#download and extract latest ehrql source
24+
wget https://github.com/opensafely-core/ehrql/archive/main.zip -P .devcontainer
25+
unzip -o .devcontainer/main.zip -d .devcontainer/
26+
rm .devcontainer/main.zip

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ venv/
1010
.Rhistory
1111
.Rproj.user/
1212
.devcontainer/ehrql-main/
13+
.ehrql

0 commit comments

Comments
 (0)