Skip to content

Commit

Permalink
Initial .devcontainer config for codespaces (#6)
Browse files Browse the repository at this point in the history
* Initial .devcontainer config for codespaces

* Change features install order

* Add installAfter setting renv cache.

* Remove version from installAfter.

* Use overrideFeatureInstallOrder as installsAfter is for feature.json

* Handling CA certificates for devcontainer

* Fix for arm64 devcontainer build.

* Update 4.2 and 4.1

* Add codespaces config for multi repository access.

* Clean postAttachCommand command.

* Fix typo
  • Loading branch information
galachad authored Oct 4, 2023
1 parent 7377187 commit dbd3c76
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 11 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.github$
^\.devcontainer$
^\.lycheeignore$
^README\.Rmd$
^_pkgdown\.yml$
Expand Down
24 changes: 13 additions & 11 deletions .Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@ if (Sys.getenv("GITHUB_ACTIONS") != "") {
Sys.setenv("RENV_CONFIG_SANDBOX_ENABLED" = FALSE)
Sys.setenv("RENV_CONFIG_AUTO_SNAPSHOT" = FALSE)

.renv_profile <- paste(R.version$major, substr(R.version$minor, 1, 1), sep = ".")
if (!file.exists("./renv/profile")) {
if (.renv_profile %in% c("4.1", "4.2", "4.3")) {
message("Set renv profile to `", .renv_profile, "`")
Sys.setenv("RENV_PROFILE" = .renv_profile)
if (!Sys.getenv("RENV_AUTOLOADER_ENABLED") %in% c("false", "FALSE")) {
.renv_profile <- paste(R.version$major, substr(R.version$minor, 1, 1), sep = ".")
if (!file.exists("./renv/profile")) {
if (.renv_profile %in% c("4.1", "4.2", "4.3")) {
message("Set renv profile to `", .renv_profile, "`")
Sys.setenv("RENV_PROFILE" = .renv_profile)
} else {
message("This repository do not contains the renv profile for your R version.")
}
} else {
message("This repository do not contains the renv profile for your R version.")
message(
"Using renv profile from `renv/profile` file.\n",
"The `", readLines("./renv/profile"), "` profile will be used."
)
}
} else {
message(
"Using renv profile from `renv/profile` file.\n",
"The `", readLines("./renv/profile"), "` profile will be used."
)
}

source("renv/activate.R")
95 changes: 95 additions & 0 deletions .devcontainer/4.1/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
// https://containers.dev/implementors/json_reference/
"name": "sdtm.oak (RStudio) container",
"image": "ghcr.io/pharmaverse/sdtm.oak-4.1:latest",
// Install Dev Container Features. More info: https://containers.dev/features
"containerEnv": {
"ROOT": "true",
"PASSWORD": "rstudio",
"DISABLE_AUTH": "true",
"RENV_AUTOLOADER_ENABLED": "false"
},
"features": {
"./ca-cert": {},
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
"version": "none",
"vscodeRSupport": "full",
"installRadian": true,
"installVscDebugger": true
},
"ghcr.io/rocker-org/devcontainer-features/renv-cache:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": false,
"installOhMyZsh": true,
"username": "rstudio",
"upgradePackages": false
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"overrideFeatureInstallOrder": [
"./ca-cert",
"./arm64-repos",
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/rocker-org/devcontainer-features/renv-cache",
"ghcr.io/rocker-org/devcontainer-features/r-rig",
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils"
],
"init": true,
"overrideCommand": false,

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "rstudio || true",

"customizations": {
"codespaces": {
"repositories": {
"pharmaverse/mint": {
"permissions": "write-all"
},
"pharmaverse/raw.synthetic.data": {
"permissions": "write-all"
}
}
},
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
},
"extensions": [
"vsls-contrib.codetour",
"GitHub.copilot",
"GitHub.copilot-chat",
// R extensions
"ikuyadeu.r",
"REditorSupport.r-lsp",
// Extra extension
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"cweijan.vscode-office",
"donjayamanne.githistory",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"GitHub.remotehub",
"alefragnani.Bookmarks",
"vscode-icons-team.vscode-icons"
]
}
},

// RStudio ports
"forwardPorts": [8787],
"portsAttributes": {
"8787": {
"label": "Rstudio",
"requireLocalPort": true,
"onAutoForward": "openBrowser"
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root
"remoteUser": "rstudio"
}
95 changes: 95 additions & 0 deletions .devcontainer/4.2/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
// https://containers.dev/implementors/json_reference/
"name": "sdtm.oak R-4.2 (RStudio) container",
"image": "ghcr.io/pharmaverse/sdtm.oak-4.2:latest",
// Install Dev Container Features. More info: https://containers.dev/features
"containerEnv": {
"ROOT": "true",
"PASSWORD": "rstudio",
"DISABLE_AUTH": "true",
"RENV_AUTOLOADER_ENABLED": "false"
},
"features": {
"./ca-cert": {},
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
"version": "none",
"vscodeRSupport": "full",
"installRadian": true,
"installVscDebugger": true
},
"ghcr.io/rocker-org/devcontainer-features/renv-cache:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": false,
"installOhMyZsh": true,
"username": "rstudio",
"upgradePackages": false
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"overrideFeatureInstallOrder": [
"./ca-cert",
"./arm64-repos",
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/rocker-org/devcontainer-features/renv-cache",
"ghcr.io/rocker-org/devcontainer-features/r-rig",
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils"
],
"init": true,
"overrideCommand": false,

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "rstudio || true",

"customizations": {
"codespaces": {
"repositories": {
"pharmaverse/mint": {
"permissions": "write-all"
},
"pharmaverse/raw.synthetic.data": {
"permissions": "write-all"
}
}
},
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
},
"extensions": [
"vsls-contrib.codetour",
"GitHub.copilot",
"GitHub.copilot-chat",
// R extensions
"ikuyadeu.r",
"REditorSupport.r-lsp",
// Extra extension
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"cweijan.vscode-office",
"donjayamanne.githistory",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"GitHub.remotehub",
"alefragnani.Bookmarks",
"vscode-icons-team.vscode-icons"
]
}
},

// RStudio ports
"forwardPorts": [8787],
"portsAttributes": {
"8787": {
"label": "Rstudio",
"requireLocalPort": true,
"onAutoForward": "openBrowser"
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root
"remoteUser": "rstudio"
}
7 changes: 7 additions & 0 deletions .devcontainer/arm64-repos/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "arm64 repos",
"id": "arm64-repos",
"version": "0.1.0",
"description": "Fix repos for arm64.",
"options": {}
}
22 changes: 22 additions & 0 deletions .devcontainer/arm64-repos/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

ARCH=$(uname -m)

## source install if using RSPM and arm64 image
if [ "$ARCH" = "aarch64" ]; then

CRAN="https://cloud.r-project.org"

## Add a default CRAN mirror
echo "options(repos = c(CRAN = '${CRAN}'), download.file.method = 'libcurl')" >"${R_HOME}/etc/Rprofile.site"

## Set HTTPUserAgent for RSPM (https://github.com/rocker-org/rocker/issues/400)
cat <<EOF >>"${R_HOME}/etc/Rprofile.site"
# https://docs.rstudio.com/rspm/admin/serving-binaries/#binaries-r-configuration-linux
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))
EOF

fi

1 change: 1 addition & 0 deletions .devcontainer/ca-cert/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.crt
7 changes: 7 additions & 0 deletions .devcontainer/ca-cert/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "CA cert",
"id": "ca-cert",
"version": "0.1.0",
"description": "Copy CA cert into the container.",
"options": {}
}
11 changes: 11 additions & 0 deletions .devcontainer/ca-cert/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

# Copy CA certificate to `/etc/ssl/cert`
if ls *.crt 1> /dev/null 2>&1; then
sudo cp *.crt /usr/local/share/ca-certificates
sudo update-ca-certificates
fi

echo "Done!"
96 changes: 96 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
// https://containers.dev/implementors/json_reference/
"name": "sdtm.oak R-4.3 (RStudio) container",
"image": "ghcr.io/pharmaverse/sdtm.oak-4.3:latest",
// Install Dev Container Features. More info: https://containers.dev/features
"containerEnv": {
"ROOT": "true",
"PASSWORD": "rstudio",
"DISABLE_AUTH": "true",
"RENV_AUTOLOADER_ENABLED": "false"
},
"features": {
"./ca-cert": {},
"./arm64-repos": {},
"ghcr.io/rocker-org/devcontainer-features/r-rig:1": {
"version": "none",
"vscodeRSupport": "full",
"installRadian": true,
"installVscDebugger": true
},
"ghcr.io/rocker-org/devcontainer-features/renv-cache:latest": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": false,
"installOhMyZsh": true,
"username": "rstudio",
"upgradePackages": false
},
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils:1": {}
},
"overrideFeatureInstallOrder": [
"./ca-cert",
"./arm64-repos",
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/rocker-org/devcontainer-features/renv-cache",
"ghcr.io/rocker-org/devcontainer-features/r-rig",
"ghcr.io/mikaello/devcontainer-features/modern-shell-utils"
],
"init": true,
"overrideCommand": false,

"postCreateCommand": "bash ./.devcontainer/postCreateCommand.sh",

"postAttachCommand": "rstudio || true",

"customizations": {
"codespaces": {
"repositories": {
"pharmaverse/mint": {
"permissions": "read-all"
},
"pharmaverse/raw.synthetic.data": {
"permissions": "read-all"
}
}
},
"vscode": {
"settings": {
"r.rterm.linux": "/usr/local/bin/radian",
"r.bracketedPaste": true,
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active"
},
"extensions": [
"vsls-contrib.codetour",
"GitHub.copilot",
"GitHub.copilot-chat",
// R extensions
"ikuyadeu.r",
"REditorSupport.r-lsp",
// Extra extension
"streetsidesoftware.code-spell-checker",
"eamodio.gitlens",
"cweijan.vscode-office",
"donjayamanne.githistory",
"GitHub.vscode-github-actions",
"GitHub.vscode-pull-request-github",
"GitHub.remotehub",
"alefragnani.Bookmarks",
"vscode-icons-team.vscode-icons"
]
}
},

// RStudio ports
"forwardPorts": [8787],
"portsAttributes": {
"8787": {
"label": "Rstudio",
"requireLocalPort": true,
"onAutoForward": "openBrowser"
}
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root
"remoteUser": "rstudio"
}
11 changes: 11 additions & 0 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# move script rstudio into /usr/bin
sudo cp "$(pwd)/.devcontainer/rstudio.sh" /usr/bin/rstudio
sudo chmod +x /usr/bin/rstudio

# Restore renv and install staged dependencies
R -q -e 'renv::restore(lockfile = file.path("renv", "profiles", paste(R.version$major, substr(R.version$minor, 1, 1), sep = "."), "renv.lock")); staged.dependencies::install_deps(staged.dependencies::dependency_table(project = ".", verbose = 1), verbose = 1);'

# Define rstudio default working directory
jq --arg folder "$(pwd)/" '. + { "initial_working_directory": $folder }' .devcontainer/rstudio-prefs.json > ~/.config/rstudio/rstudio-prefs.json
Loading

0 comments on commit dbd3c76

Please sign in to comment.