diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6e52b56..9a56901 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -2,13 +2,13 @@ // README at: https://github.com/devcontainers/templates/tree/main/src/python { "name": "OpenSAFELY", - "image": "ghcr.io/opensafely-core/research-template:v0", + "image": "mcr.microsoft.com/devcontainers/base:ubuntu-22.04", // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {} }, - "postCreateCommand": "/bin/bash /opt/devcontainer/postCreate.sh ${containerWorkspaceFolder}", - "postAttachCommand": "/bin/bash /opt/devcontainer/postAttach.sh", + "postCreateCommand": "/bin/bash .devcontainer/postCreate.sh", + "postAttachCommand": "/bin/bash .devcontainer/postAttach.sh", "forwardPorts": [ 8787 ], @@ -40,8 +40,8 @@ "files.autoSave": "afterDelay", "files.autoSaveDelay": 1000, "git.autofetch": true, - "python.analysis.extraPaths": [".devcontainer/ehrql-main/"], - "python.defaultInterpreterPath": "/opt/venv/bin/python", + "python.analysis.extraPaths": [".ehrql/"], + "python.defaultInterpreterPath": "./venv/bin/python", "python.terminal.activateEnvInCurrentTerminal": true, "python.terminal.activateEnvironment": true, "window.autoDetectColorScheme": true diff --git a/.devcontainer/postAttach.sh b/.devcontainer/postAttach.sh new file mode 100644 index 0000000..36ef0ff --- /dev/null +++ b/.devcontainer/postAttach.sh @@ -0,0 +1 @@ +opensafely launch rstudio -p 8787 & \ No newline at end of file diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh new file mode 100644 index 0000000..0e9ee0f --- /dev/null +++ b/.devcontainer/postCreate.sh @@ -0,0 +1,26 @@ +# install python and dependencies, set up virtualenv +sudo apt update +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 +pip install virtualenv opensafely +python3 -m virtualenv .venv +rm -rf .venv/lib +docker container create --name python-v2 ghcr.io/opensafely-core/python:v2 +docker cp python-v2:/opt/venv/lib .venv/ +docker rm python-v2 + +# install R and dependencies +echo "deb https://cloud.r-project.org/bin/linux/ubuntu jammy-cran40/" | sudo tee /etc/apt/sources.list.d/cran.list >/dev/null +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 +sudo apt update +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 +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 +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 +docker create --name r-v2 --rm ghcr.io/opensafely-core/r:v2 +sudo docker cp r-v2:/usr/local/lib/R/site-library /usr/local/lib/R/ +sudo chown -R vscode:vscode /usr/local/lib/R/site-library/ + + +#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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 1c206cf..8577286 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ venv/ .Rhistory .Rproj.user/ .devcontainer/ehrql-main/ +.ehrql \ No newline at end of file