Skip to content

Commit 5f45ce2

Browse files
committed
Add feature: deno-cache.
1 parent f095a2d commit 5f45ce2

File tree

6 files changed

+93
-0
lines changed

6 files changed

+93
-0
lines changed

src/deno-cache/NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Deno Cache
2+
3+
Setup the [deno cache](https://jsr.io/@deno/cache-dir) as a volume.
4+
5+
Intended for usage with the `denoland/deno:debian` docker image. Otherwise,
6+
will create a `deno` group with read-write permissions on the cache directory.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"id": "deno-cache",
3+
"name": "Deno cache setup",
4+
"version": "0.1.0",
5+
"containerEnv": {
6+
"DENO_DIR": "/deno-dir"
7+
},
8+
"options": {
9+
"username": {
10+
"description": "Add the 'deno' group to the given non-root user. Defaults to the value of `remoteUser`.",
11+
"default": "automatic",
12+
"type": "string"
13+
}
14+
},
15+
"mounts": [
16+
{
17+
"source": "deno-cache-${devcontainerId}",
18+
"target": "/deno-dir",
19+
"type": "volume"
20+
}
21+
],
22+
"installsAfter": [
23+
"ghcr.io/devcontainers/features/common-utils"
24+
]
25+
}

src/deno-cache/install.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
GROUP=deno
6+
7+
echo "Creating cache directory: $DENO_DIR"
8+
mkdir --parents "$DENO_DIR"
9+
10+
echo "Creating user group: $GROUP"
11+
groupadd --force --key GID_MIN=1993 "$GROUP"
12+
13+
echo "Assigning group to cache directory..."
14+
chgrp --changes --recursive "$GROUP" "$DENO_DIR"
15+
16+
echo "Assigning permissions with sticky group..."
17+
chmod --changes --recursive 2775 "$DENO_DIR"
18+
19+
echo "Appending group ${GROUP@Q} to user..."
20+
if [[ "$USERNAME" == "automatic" ]]; then
21+
usermod --append --groups "$GROUP" "$_REMOTE_USER"
22+
elif [[ -n "$USERNAME" && "$USERNAME" != "root" ]]; then
23+
usermod --append --groups "$GROUP" "$USERNAME"
24+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
check "Group exists" getent group deno
8+
check "Directory /deno-dir exists" test -d "$DENO_DIR"
9+
check "Group is set" test "$(stat --printf="%G" "$DENO_DIR")" == "deno"
10+
check "Permissions are set" test "$(stat --printf="%a" "$DENO_DIR")" -eq 2775
11+
check "Remote user is in the deno group" bash -c "getent group deno | grep jsr"
12+
check "Run deno info" deno info "jsr:@deno/cache-dir"
13+
14+
reportResults

test/deno-cache/scenarios.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"denoland_deno__debian__custom_user": {
3+
"image": "denoland/deno:debian",
4+
"remoteUser": "jsr",
5+
"features": {
6+
"deno-cache": {},
7+
"ghcr.io/devcontainers/features/common-utils:2": {
8+
"username": "jsr"
9+
}
10+
}
11+
}
12+
}

test/deno-cache/test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
check "Group exists" getent group deno
8+
check "Directory /deno-dir exists" test -d "$DENO_DIR"
9+
check "Group is set" test "$(stat --printf="%G" "$DENO_DIR")" == "deno"
10+
check "Permissions are set" test "$(stat --printf="%a" "$DENO_DIR")" -eq 2775
11+
12+
reportResults

0 commit comments

Comments
 (0)