Skip to content

Commit

Permalink
Merge pull request #120 from opensafely/improve-devcontainers
Browse files Browse the repository at this point in the history
Improve devcontainers/codespaces configuration:
* use custom docker image opensafely-core/research-template-docker
* include R 4.0.5 and RStudio-server via Rocker
* include Python and R packages from opensafely-core/python-docker and r-docker respectively
* improve ehrQL syntax highlighting
* various maintainability improvements
  • Loading branch information
Jongmassey authored May 10, 2024
2 parents a938879 + ee48aa5 commit 7788bb3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
1 change: 1 addition & 0 deletions .devcontainer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ehrql-main
37 changes: 26 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -17,18 +13,37 @@
"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": {
"extensions": [
"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.
Expand Down
15 changes: 15 additions & 0 deletions .devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .devcontainer/requirements.in
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
opensafely
https://github.com/opensafely-core/ehrql/archive/main.zip
11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

0 comments on commit 7788bb3

Please sign in to comment.