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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
| [rclone](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/rclone.org) | `rclone` — sync files to/from cloud storage | gh release | 1.0.1 |
| [restic.net](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/restic.net) | `restic` — fast, encrypted, deduplicated backups | gh release | 1.0.1 |
| [ripgrep](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/ripgrep) | `rg` — fast grep alternative (ripgrep) | gh release | 1.0.1 |
| [run-script](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/run-script) | Run a script from a URL or inline text during devcontainer build | custom | 1.0.0 |
| [schpet/linear-cli](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/schpet-linear-cli) | `linear` — CLI to access linear.com issue tracker | gh release | 1.0.2 |
| [smallstep.com](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/smallstep.com) | `step` — zero-trust security toolkit and CA | gh release | 1.0.2 |
| [socket.dev/sfw-free](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/socket.dev-sfw-free) | `sfw` — network security proxy that blocks malicious dependencies | gh release | 1.0.0 |
Expand Down
19 changes: 19 additions & 0 deletions src/run-script/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# run-script

## Project

_No upstream project — this is a utility feature._

## Description

A utility feature that runs a custom script during devcontainer build. Accepts either a URL pointing to a script to download and execute, or an inline script supplied directly as text. Exactly one of `url` or `script` must be provided.

## Installation Method

No binary is installed. The feature downloads (via `wget` or `curl`) or writes the provided script to a temporary file, then executes it with `bash`. If neither `wget` nor `curl` is available, `curl` is installed automatically via `apt`.

## Other Notes

- If both `url` and `script` are provided the feature fails with an error.
- If neither option is provided the feature exits successfully without doing anything.
- The temporary script file is removed after execution.
19 changes: 19 additions & 0 deletions src/run-script/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "run-script",
"id": "run-script",
"version": "1.0.0",
"description": "Run a script from a URL or inline text during devcontainer build",
"documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/run-script",
"options": {
"url": {
"type": "string",
"default": "",
"description": "URL of a script to download and execute."
},
"script": {
"type": "string",
"default": "",
"description": "Inline script text to execute."
}
}
}
71 changes: 71 additions & 0 deletions src/run-script/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/bin/bash
set -o errexit
set -o pipefail
set -o noclobber
set -o nounset
set -o allexport
readonly name="run-script"

apt_get_update() {
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update -y
fi
}

apt_get_checkinstall() {
if ! dpkg -s "$@" >/dev/null 2>&1; then
apt_get_update
DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@"
fi
}

apt_get_cleanup() {
apt-get clean
rm -rf /var/lib/apt/lists/*
}

echo_banner() {
local text="$1"
echo -e "\e[1m\e[97m\e[41m$text\e[0m"
}

install() {
if [ -n "${URL}" ] && [ -n "${SCRIPT}" ]; then
printf >&2 '=== [ERROR] Both "url" and "script" options are provided. Please provide only one.\n'
exit 1
fi

if [ -z "${URL}" ] && [ -z "${SCRIPT}" ]; then
echo "No script URL or inline script provided. Nothing to do."
return 0
fi

local tmpScript
tmpScript="$(mktemp)"
trap 'rm -f "${tmpScript}"' EXIT

if [ -n "${URL}" ]; then
echo "Downloading script from: ${URL}"
if command -v wget >/dev/null 2>&1; then
wget -qO "${tmpScript}" "${URL}"
elif command -v curl >/dev/null 2>&1; then
curl -fsSL -o "${tmpScript}" "${URL}"
else
apt_get_checkinstall curl ca-certificates
apt_get_cleanup
curl -fsSL -o "${tmpScript}" "${URL}"
fi
else
echo "Writing inline script to temporary file..."
printf '%s' "${SCRIPT}" | tee "${tmpScript}" >/dev/null
fi

echo "Executing script..."
bash "${tmpScript}"
}

echo_banner "devcontainer.community"
echo "Running $name..."
install "$@"
echo "(*) Done!"
18 changes: 18 additions & 0 deletions test/run-script/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash


set -e

# Optional: Import test library bundled with the devcontainer CLI
# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib
# Provides the 'check' and 'reportResults' commands.
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib. Syntax is...
# check <LABEL> <cmd> [args...]
check "bash is available" bash -c "bash --version"

# Report results
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
Loading