Skip to content

Commit

Permalink
Update ownership of $RENV_PATHS_CACHE to correct uid on `postStartC…
Browse files Browse the repository at this point in the history
…ommand` (#210)

Closes #209 

Updates the ownership of the `$RENV_PATHS_CACHE` directory such that
when `updateRemoteUserUID` is set, the ownership of the cache is the
same as the workspace. The test cases have also been updated to check
the permissions of the directory.
  • Loading branch information
ahaim5357 authored Jan 24, 2024
1 parent f9e426d commit 7b72c43
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/renv-cache/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "renv cache",
"id": "renv-cache",
"version": "0.1.1",
"version": "0.1.2",
"description": "Install the renv R package and set renv cache to a Docker volume. Cache is shared by all containers.",
"documentationURL": "https://github.com/rocker-org/devcontainer-features/tree/main/src/renv-cache",
"options": {},
Expand All @@ -15,6 +15,9 @@
"type": "volume"
}
],
"postStartCommand": {
"renv-cache-setup": "/usr/local/share/rocker-devcontainer-features/renv-cache/scripts/poststart.sh"
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/rocker-org/devcontainer-features/apt-packages",
Expand Down
10 changes: 10 additions & 0 deletions src/renv-cache/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ RENV_PATHS_CACHE=${RENV_PATHS_CACHE:-"/renv/cache"}

USERNAME=${USERNAME:-${_REMOTE_USER}}

LIFECYCLE_SCRIPTS_DIR="/usr/local/share/rocker-devcontainer-features/renv-cache/scripts"

set -e

create_cache_dir() {
Expand Down Expand Up @@ -47,6 +49,14 @@ install_renv() {
export DEBIAN_FRONTEND=noninteractive

create_cache_dir "${RENV_PATHS_CACHE}" "${USERNAME}"

# Set Lifecycle scripts
## check_r exits installation if R isn't present, so the script needs to be copied first
if [ -f poststart.sh ]; then
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}"
cp poststart.sh "${LIFECYCLE_SCRIPTS_DIR}/poststart.sh"
fi

check_r
install_renv "${USERNAME}"

Expand Down
20 changes: 20 additions & 0 deletions src/renv-cache/poststart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash

RENV_PATHS_CACHE=${RENV_PATHS_CACHE:-"/renv/cache"}

set -e

fix_permissions() {
local dir
dir="${1}"

if [ ! -w "${dir}" ]; then
echo "Fixing permissions of '${dir}'..."
sudo chown -R "$(id -u):$(id -g)" "${dir}"
echo "Done!"
else
echo "Permissions of '${dir}' are OK!"
fi
}

fix_permissions "${RENV_PATHS_CACHE}"
1 change: 1 addition & 0 deletions test/renv-cache/gh-version-renv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /renv/cache/"
check "renv" R -q -e 'packageVersion("renv")'
check "renv::install" R -q -e 'renv::install("jsonlite")'
check "cache dir" find /renv/cache/*
Expand Down
1 change: 1 addition & 0 deletions test/renv-cache/r-apt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /renv/cache/"
check "renv" R -q -e 'packageVersion("renv")'
check "renv::install" R -q -e 'renv::install("jsonlite")'
check "cache dir" find /renv/cache/*
Expand Down
1 change: 1 addition & 0 deletions test/renv-cache/r-rig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /renv/cache/"
check "renv" R -q -e 'packageVersion("renv")'
check "renv::install" R -q -e 'renv::install("jsonlite")'
check "cache dir" find /renv/cache/*
Expand Down
1 change: 1 addition & 0 deletions test/renv-cache/rocker-r-ver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /renv/cache/"
check "renv" R -q -e 'packageVersion("renv")'
check "renv::install" R -q -e 'renv::install("jsonlite")'
check "cache dir" find /renv/cache/*
Expand Down
1 change: 1 addition & 0 deletions test/renv-cache/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
source dev-container-features-test-lib

# Feature-specific tests
check "cache dir permission" bash -c "test -w /renv/cache/"

# Report result
reportResults

0 comments on commit 7b72c43

Please sign in to comment.