From 608f608ce14a624746c6f70fd385af67018628cf Mon Sep 17 00:00:00 2001 From: Lucy Bridges Date: Tue, 16 Apr 2024 17:05:43 +0100 Subject: [PATCH 1/8] Use a custom docker image Use the image from opensafely-core/research-template-docker rather than the Microsoft devcontainer image as a base. For this initial version, I build the image locally and uploaded it using these [instructions](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry). --- .devcontainer/devcontainer.json | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e9856a7..47dc9ad 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,8 @@ // 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": "Python 3", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - // 2023-06-29: Use bullseye image instead of bookworm. - // At time of writing, bookworm is new and may have issues with dev containers: - // https://github.com/devcontainers/features/issues/576 - "image": "mcr.microsoft.com/devcontainers/python:3.11-bullseye", + "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": { From 625914accc4e546aab51514abd584e695204e6b6 Mon Sep 17 00:00:00 2001 From: Lucy Bridges Date: Mon, 15 Apr 2024 10:57:40 +0100 Subject: [PATCH 2/8] Start RStudio server automatically Co-authored-by: Jon Massey --- .devcontainer/devcontainer.json | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 47dc9ad..cc1f688 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,10 +13,18 @@ "dockerDashComposeVersion": "v2" } }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - // Use 'postCreateCommand' to run commands after the container is created. "postCreateCommand": "pip3 install --user -r .devcontainer/requirements.in", + "postAttachCommand": { + "rstudio-start": "sudo rstudio-server start" + }, + "forwardPorts": [ + 8787 + ], + "portsAttributes": { + "8787": { + "label": "RStudio IDE" + } + }, // Configure tool-specific properties. "customizations": { "vscode": { From 2cf4905b978d330f0989e412fb6a5382b21f4e44 Mon Sep 17 00:00:00 2001 From: Lucy Bridges Date: Mon, 15 Apr 2024 13:58:48 +0100 Subject: [PATCH 3/8] Move Python and R initialisation to bash script --- .devcontainer/devcontainer.json | 2 +- .devcontainer/postCreate.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/postCreate.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cc1f688..8baae2b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -13,7 +13,7 @@ "dockerDashComposeVersion": "v2" } }, - "postCreateCommand": "pip3 install --user -r .devcontainer/requirements.in", + "postCreateCommand": "/bin/bash .devcontainer/postCreate.sh", "postAttachCommand": { "rstudio-start": "sudo rstudio-server start" }, diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100644 index 0000000..97703cf --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,10 @@ +#!/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 \ No newline at end of file From bb97d44df084eb061c5adb073202ee5a12ec7463 Mon Sep 17 00:00:00 2001 From: Lucy Bridges Date: Mon, 15 Apr 2024 14:23:27 +0100 Subject: [PATCH 4/8] Enable ehrql code highlighting and completion The ehrql extension is downloaded and referenced in vs code separately rather than being installed using pip because it requires a newer version of python (3.11 rather than the 3.10 required for the analysis code). Remove ehrql from requirements.in Co-authored-by: Jon Massey --- .devcontainer/postCreate.sh | 7 ++++++- .devcontainer/requirements.in | 1 - .gitignore | 2 ++ .vscode/settings.json | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index 97703cf..cac58e6 100644 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -7,4 +7,9 @@ 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 \ No newline at end of file +! 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 index cfc3e78..8136f40 100644 --- a/.devcontainer/requirements.in +++ b/.devcontainer/requirements.in @@ -1,2 +1 @@ opensafely -https://github.com/opensafely-core/ehrql/archive/main.zip diff --git a/.gitignore b/.gitignore index 5e16945..5019826 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ venv/ .DS_Store .Rhistory .Rproj.user/ + +.devcontainer/ehrql-main diff --git a/.vscode/settings.json b/.vscode/settings.json index 53e2017..d975b11 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,6 @@ { + "python.analysis.extraPaths": [".devcontainer/ehrql-main/"], + "python.defaultInterpreterPath": "/usr/bin/python3.10", "data.preview.create.json.schema": false, "files.associations": { "*.feather": "arrow", From 315c23ea9d88227795cee9fda0310ff75b69ca74 Mon Sep 17 00:00:00 2001 From: Lucy Bridges Date: Mon, 15 Apr 2024 14:49:22 +0100 Subject: [PATCH 5/8] Setup python virtual env This is so we can use the packages copied over from the python action image. Co-authored-by: Jon Massey --- .vscode/settings.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d975b11..efaab93 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,8 @@ { "python.analysis.extraPaths": [".devcontainer/ehrql-main/"], - "python.defaultInterpreterPath": "/usr/bin/python3.10", + "python.defaultInterpreterPath": "/opt/venv/bin/python", + "python.terminal.activateEnvInCurrentTerminal": true, + "python.terminal.activateEnvironment": true, "data.preview.create.json.schema": false, "files.associations": { "*.feather": "arrow", From 7ea8149a9ca7e247fcfe51e6040f806ff3f356a8 Mon Sep 17 00:00:00 2001 From: Jon Massey Date: Fri, 26 Apr 2024 09:29:04 +0100 Subject: [PATCH 6/8] Move devcontainer-specific vscode settings into devcontainer.json and remove vestigial config added for gitpod --- .devcontainer/devcontainer.json | 13 ++++++++++++- .vscode/settings.json | 15 --------------- 2 files changed, 12 insertions(+), 16 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 8baae2b..a08bee0 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -32,7 +32,18 @@ "ms-python.python", "ms-toolsai.jupyter", "ms-toolsai.jupyter-renderers" - ] + ], + "settings": { + "extensions.ignoreRecommendations": true, + "files.autoSave": "afterDelay", + "files.autoSaveDelay": 1000, + "git.autofetch": true, + "python.analysis.extraPaths": [".devcontainer/ehrql-main/"], + "python.defaultInterpreterPath": "/opt/venv/bin/python", + "python.terminal.activateEnvInCurrentTerminal": true, + "python.terminal.activateEnvironment": true, + "window.autoDetectColorScheme": true + } } }, // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index efaab93..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "python.analysis.extraPaths": [".devcontainer/ehrql-main/"], - "python.defaultInterpreterPath": "/opt/venv/bin/python", - "python.terminal.activateEnvInCurrentTerminal": true, - "python.terminal.activateEnvironment": true, - "data.preview.create.json.schema": false, - "files.associations": { - "*.feather": "arrow", - }, - "files.autoSave": "afterDelay", - "files.autoSaveDelay": 1000, - "window.autoDetectColorScheme": true, - "extensions.ignoreRecommendations": true, - "data.preview.theme": "light" -} From 599de155a96e58b144db6fa32f9aa30fe4382344 Mon Sep 17 00:00:00 2001 From: Jon Massey Date: Fri, 3 May 2024 12:30:36 +0100 Subject: [PATCH 7/8] Move devcontainer-specific gitignore statements --- .devcontainer/.gitignore | 1 + .gitignore | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) create mode 100644 .devcontainer/.gitignore diff --git a/.devcontainer/.gitignore b/.devcontainer/.gitignore new file mode 100644 index 0000000..a9bc9d4 --- /dev/null +++ b/.devcontainer/.gitignore @@ -0,0 +1 @@ +ehrql-main \ No newline at end of file diff --git a/.gitignore b/.gitignore index 5019826..5e16945 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,3 @@ venv/ .DS_Store .Rhistory .Rproj.user/ - -.devcontainer/ehrql-main From ee48aa5acf2230a0140928e5874e70443c5618e7 Mon Sep 17 00:00:00 2001 From: Jon Massey Date: Sun, 5 May 2024 15:22:14 +0100 Subject: [PATCH 8/8] Use new image location and v0 tag --- .devcontainer/devcontainer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a08bee0..da94613 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,7 +2,7 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/python { "name": "OpenSAFELY", - "image": "ghcr.io/opensafely/research-template:latest", + "image": "ghcr.io/opensafely-core/research-template:v0", // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {