Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/.devcontainer/cleanup/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "cleanup",
"version": "1.0.0",
"name": "Cleanup",
"description": "Remove user caches and temporary files (for example ~/.cache/R). Intended to run last.",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"./quarto-computing-dependencies",
"./uv",
"./chrome",
"./decktape",
"./tinytex",
"ghcr.io/rocker-org/devcontainer-features/quarto-cli",
"ghcr.io/devcontainers/features/github-cli"
]
}
68 changes: 68 additions & 0 deletions .github/.devcontainer/cleanup/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

set -euo pipefail

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

# Resolve username
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
if id -u "${CURRENT_USER}" >/dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif ! id -u "${USERNAME}" >/dev/null 2>&1; then
USERNAME=root
fi

echo "[cleanup] Running cleanup feature as user: ${USERNAME}"

# Determine home directory for the target user
if [ "${USERNAME}" = "root" ]; then
USER_HOME="/root"
else
USER_HOME=$(eval echo "~${USERNAME}")
fi

echo "[cleanup] Target home: ${USER_HOME}"

cleanup_paths=(
"${USER_HOME}/.cache"
"${USER_HOME}/.local/share/Trash"
"${USER_HOME}/tmp"
"${USER_HOME}/.npm/_cacache"
)

for path in "${cleanup_paths[@]}"; do
if [ -e "${path}" ]; then
echo "[cleanup] Removing: ${path}"
rm -rf "${path}" || true
else
echo "[cleanup] Not found: ${path}"
fi
done

echo "[cleanup] Cleaning system temporary files"
if [ -d "/tmp" ]; then
echo "[cleanup] Removing: /tmp/*"
rm -rf /tmp/* || true
fi

echo "[cleanup] Cleaning package manager caches"
if command -v apt-get >/dev/null 2>&1; then
echo "[cleanup] Running: apt-get clean"
apt-get clean || true

if [ -d "/var/lib/apt/lists" ]; then
echo "[cleanup] Removing: /var/lib/apt/lists/*"
rm -rf /var/lib/apt/lists/* || true
fi
fi

echo "[cleanup] Done."
45 changes: 30 additions & 15 deletions .github/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,34 @@
"IMAGE": "${localEnv:IMAGE}"
},
"options": [
"--label", "org.opencontainers.image.title=${localEnv:ANNOTATION_TITLE}",
"--annotation", "org.opencontainers.image.title=${localEnv:ANNOTATION_TITLE}",
"--label", "org.opencontainers.image.description=${localEnv:ANNOTATION_DESCRIPTION}",
"--annotation", "org.opencontainers.image.description=${localEnv:ANNOTATION_DESCRIPTION}",
"--label", "org.opencontainers.image.authors=${localEnv:ANNOTATION_AUTHORS}",
"--annotation", "org.opencontainers.image.authors=${localEnv:ANNOTATION_AUTHORS}",
"--label", "org.opencontainers.image.url=${localEnv:ANNOTATION_URL}",
"--annotation", "org.opencontainers.image.url=${localEnv:ANNOTATION_URL}",
"--label", "org.opencontainers.image.source=${localEnv:ANNOTATION_URL}",
"--annotation", "org.opencontainers.image.source=${localEnv:ANNOTATION_URL}",
"--label", "org.opencontainers.image.version=${localEnv:ANNOTATION_VERSION}",
"--annotation", "org.opencontainers.image.version=${localEnv:ANNOTATION_VERSION}",
"--label", "org.opencontainers.image.licenses=${localEnv:ANNOTATION_LICENSE}",
"--annotation", "org.opencontainers.image.licenses=${localEnv:ANNOTATION_LICENSE}"
"--label",
"org.opencontainers.image.title=${localEnv:ANNOTATION_TITLE}",
"--annotation",
"org.opencontainers.image.title=${localEnv:ANNOTATION_TITLE}",
"--label",
"org.opencontainers.image.description=${localEnv:ANNOTATION_DESCRIPTION}",
"--annotation",
"org.opencontainers.image.description=${localEnv:ANNOTATION_DESCRIPTION}",
"--label",
"org.opencontainers.image.authors=${localEnv:ANNOTATION_AUTHORS}",
"--annotation",
"org.opencontainers.image.authors=${localEnv:ANNOTATION_AUTHORS}",
"--label",
"org.opencontainers.image.url=${localEnv:ANNOTATION_URL}",
"--annotation",
"org.opencontainers.image.url=${localEnv:ANNOTATION_URL}",
"--label",
"org.opencontainers.image.source=${localEnv:ANNOTATION_URL}",
"--annotation",
"org.opencontainers.image.source=${localEnv:ANNOTATION_URL}",
"--label",
"org.opencontainers.image.version=${localEnv:ANNOTATION_VERSION}",
"--annotation",
"org.opencontainers.image.version=${localEnv:ANNOTATION_VERSION}",
"--label",
"org.opencontainers.image.licenses=${localEnv:ANNOTATION_LICENSE}",
"--annotation",
"org.opencontainers.image.licenses=${localEnv:ANNOTATION_LICENSE}"
]
},
"remoteUser": "${localEnv:USER}",
Expand Down Expand Up @@ -55,6 +69,7 @@
"installTinyTex": "false",
"installChromium": "false"
},
"ghcr.io/devcontainers/features/github-cli:1": {}
"ghcr.io/devcontainers/features/github-cli:1": {},
"./cleanup": {}
}
}