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/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index e9856a7..da94613 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-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": { @@ -17,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", + "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": { @@ -28,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/.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 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/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 53e2017..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "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" -}