diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..61ddb853 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,5 @@ +FROM ghcr.io/carpentries/workbench-docker:latest + +## this could be used to run userland scripts e.g. +## users could add specific dependencies or configurations +## RUN scripts/userland.sh diff --git a/.devcontainer/build.sh b/.devcontainer/build.sh new file mode 100644 index 00000000..6a597438 --- /dev/null +++ b/.devcontainer/build.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -euo pipefail +set -x + +GRO=$(git remote get-url origin) +ORG=$(dirname ${GRO} | awk -F':' '{ print $2 }') +REPO=$(basename -s .git ${GRO}) +DEPS_IMG="ghcr.io/${ORG}/${REPO,,}-deps:latest" + +if [[ ! -d "renv" ]]; then + echo "No renv directory found, using minimal image..." + DEPS_IMG="ghcr.io/carpentries/workbench-docker:latest-minimal" + sed -i "s|^FROM .*|FROM $DEPS_IMG|" .devcontainer/Dockerfile +elif docker pull "$DEPS_IMG"; then + echo "Using: ${DEPS_IMG}" + # update the Dockerfile FROM + sed -i "s|^FROM .*|FROM $DEPS_IMG|" .devcontainer/Dockerfile +fi + +devcontainer up diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..07fcc041 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,45 @@ +{ + "forwardPorts": [ + 8787, + 4321 + ], + "portsAttributes": { + "8787": { + "label": "RStudio Server", + "onAutoForward": "notify" + }, + "4321": { + "label": "Sandpaper Serve", + "onAutoForward": "notify" + } + }, + "remoteUser":"rstudio", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/rstudio/lesson,type=bind", + "workspaceFolder": "/home/rstudio/lesson", + "mounts": [ + "source=${localEnv:HOME}${localEnv:USERPROFILE}/.ssh,target=/home/rstudio/.ssh,type=bind,consistency=cached", + "source=${localEnv:HOME}${localEnv:USERPROFILE}/.gnupg,target=/home/rstudio/.gnupg,type=bind,consistency=cached" + ], + "build": { + "dockerfile": "Dockerfile", + "context": ".." + }, + "runArgs": [ + "-p=8787:8787", + "-p=4321:4321" + ], + "postCreateCommand": { + "pre_echo": "echo 'Installing lesson prerequisites - please wait...'", + "gpg_reset": "gpgconf --kill all", + "renv_rstudio_setup": "Rscript /home/rstudio/.workbench/fortify_renv_cache.R && bash /home/rstudio/start.sh" + }, + "containerEnv": { + "DISABLE_AUTH": "true", + "GPG_TTY": "/dev/pts/0", + "USER": "rstudio", + "PASSWORD": "rstudio", + "RENV_PATHS_ROOT": "/home/rstudio/.local/share/renv", + "RENV_PROFILE": "lesson-requirements", + "RENV_CONFIG_EXTERNAL_LIBRARIES": "/usr/local/lib/R/site-library" + } +}