Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve devcontainers #120

Merged
merged 8 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.