From 53e7f7a4fe40cef21196fb460779e39ca6e38158 Mon Sep 17 00:00:00 2001 From: Steven Maude Date: Wed, 19 Jun 2024 13:13:39 +0100 Subject: [PATCH] Use Docker image files in dev container config See opensafely-core/research-template-docker#32. In opensafely-core/research-template-docker#57, we moved this configuration to the Docker image. We can now update the dev container configuration here to use those Docker image files. Note that `postAttachCommand` now becomes a string, instead of an object; the object format allows for running multiple commands in parallel: https://containers.dev/implementors/json_reference/#formatting-string-vs-array-properties However, for our use case, this is fine for now as we only run one simple script (that only starts R Studio currently). --- .devcontainer/devcontainer.json | 6 ++---- .devcontainer/postCreate.sh | 15 --------------- .devcontainer/requirements.in | 1 - 3 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 .devcontainer/postCreate.sh delete mode 100644 .devcontainer/requirements.in diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f9dd068..978488f 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,10 +7,8 @@ "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": {} }, - "postCreateCommand": "/bin/bash .devcontainer/postCreate.sh ${containerWorkspaceFolder}", - "postAttachCommand": { - "rstudio-start": "sudo rstudio-server start" - }, + "postCreateCommand": "/bin/bash /opt/devcontainer/postCreate.sh ${containerWorkspaceFolder}", + "postAttachCommand": "/bin/bash /opt/devcontainer/postAttach.sh", "forwardPorts": [ 8787 ], diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh deleted file mode 100644 index 6d1e562..0000000 --- a/.devcontainer/postCreate.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euo pipefail - -/usr/local/bin/pip3 install --user -r .devcontainer/requirements.in - -#set R working directory -! grep -q "$1" $R_HOME/etc/Rprofile.site && sudo tee -a $R_HOME/etc/Rprofile.site <<< "setwd(\"$1\")" -#set RStudio working directory -! grep -q "$1" ~/.config/rstudio/rstudio-prefs.json && cat ~/.config/rstudio/rstudio-prefs.json | jq ". + {\"initial_working_directory\":\"$1\"}" > ~/.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 deleted file mode 100644 index 8136f40..0000000 --- a/.devcontainer/requirements.in +++ /dev/null @@ -1 +0,0 @@ -opensafely