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
37 changes: 29 additions & 8 deletions common/install-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,35 @@ il_arch() {
esac
}

# _il_retry <description> <command>...: runs the command, up to 4 times with
# a pause of 5s, 10s and 15s between tries; returns the last status. For
# the network steps of apt (update, a package download): a host that resets
# some TLS handshakes (repo.mosquitto.org does, about one in three) fails
# even apt's own Acquire::Retries, which retry within seconds.
_il_retry() {
local what="$1" attempt=1 attempts=4 status=0
shift
while :; do
status=0
"$@" || status=$?
if [ "$status" -eq 0 ] || [ "$attempt" -ge "$attempts" ]; then
return "$status"
fi
echo "install-lib: ${what} failed (attempt ${attempt}/${attempts}); retrying in $((attempt * 5))s" >&2
sleep $((attempt * 5))
attempt=$((attempt + 1))
done
}

# il_apt_install <pkg>...: installs packages without recommends, then
# removes the apt lists so they don't stay in the image layer.
il_apt_install() {
if [ "$#" -eq 0 ]; then
_il_die "il_apt_install: no packages given"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
apt-get install -y --no-install-recommends "$@" \
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "$@" \
|| _il_die "apt-get install failed: $*"
rm -rf /var/lib/apt/lists/*
}
Expand Down Expand Up @@ -335,8 +355,9 @@ _il_ensure_curl() {
# including the connect timeout) and HTTP 408/429/5xx; with
# --retry-connrefused also ECONNREFUSED, but not other connect errors
# such as EHOSTUNREACH or ENETUNREACH. This loop retries what curl
# gives up on: DNS and connect failures (exit 6/7), resets and truncated
# transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# gives up on: DNS and connect failures (exit 6/7), TLS handshake
# failures such as repo.mosquitto.org's "unexpected eof" (35), resets and
# truncated transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# Worst case: 4 curl calls of up to 4 attempts each, 16 attempts in
# all. --connect-timeout 10 bounds each attempt's connection phase (DNS,
# TCP and TLS) to 10s, so failing to connect costs at most about 200s
Expand All @@ -354,7 +375,7 @@ _il_curl() {
--retry-connrefused -o "$dest" "$url" || status=$?
case "$status" in
0) return 0 ;;
6 | 7 | 18 | 52 | 55 | 56)
6 | 7 | 18 | 35 | 52 | 55 | 56)
if [ "$call" -lt "$calls" ]; then
echo "install-lib: curl exit ${status} (call ${call}/${calls}); retrying in $((call * 2))s: ${url}" >&2
sleep $((call * 2))
Expand Down Expand Up @@ -452,7 +473,7 @@ il_apt_add_repo() {
rm -rf "$tmp"
echo "install-lib: added apt repository ${name} (key ${fpr})"
export DEBIAN_FRONTEND=noninteractive
if ! apt-get update --error-on=any \
if ! _il_retry "apt-get update for ${name}" apt-get update --error-on=any -o Acquire::Retries=3 \
-o Dir::Etc::SourceList="$list" -o Dir::Etc::SourceParts=- \
-o APT::Get::List-Cleanup=0; then
rm -f "$keyring" "$list"
Expand Down Expand Up @@ -528,7 +549,7 @@ il_apt_install_pinned() {
"(digits and dots, e.g. 18.6; no leading v, no distro revision)"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
# madison prints "pkg | version | source Packages" per version and
# source; Sources lines (deb-src) are skipped.
available="$(apt-cache madison "$pkg" \
Expand Down Expand Up @@ -581,7 +602,7 @@ il_apt_install_pinned() {
fi
done
echo "install-lib: installing ${pkg}=${chosen} ${deps[*]}"
apt-get install -y --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
|| _il_die "apt-get install failed: ${pkg}=${chosen} ${deps[*]}"
if [ "${#auto[@]}" -gt 0 ]; then
apt-mark auto "${auto[@]}" >/dev/null \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ runs `curl -fsSL --connect-timeout 10 --retry 3 --retry-max-time 60
--retry-connrefused`. curl itself retries timeouts, `ECONNREFUSED` and
HTTP 408/429/5xx. It doesn't retry other connect errors such as
`EHOSTUNREACH` or `ENETUNREACH`, so the library retries DNS and connect
failures (curl exit 6/7), resets and truncated transfers (18/52/55/56) up
failures (curl exit 6/7), TLS handshake failures (35), resets and truncated transfers (18/52/55/56) up
to 4 calls, as base's `scripts/develop.sh` does. That makes at most 16
attempts, each with a connection phase (DNS, TCP and TLS) of at most 10s,
so failing to connect costs at most about 200s with the backoff sleeps.
Expand Down
2 changes: 1 addition & 1 deletion src/cli-claude-code/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "cli-claude-code",
"version": "1.0.0",
"version": "1.0.1",
"name": "Claude Code",
"description": "Installs Anthropic's native Claude Code binary (claude) at an exact version, checked against a sha256 you supply, with its auto-updater and manual updates turned off. No Node.js needed. There are no default pins.",
"documentationURL": "https://github.com/craftainer/devcontainer-features/tree/main/src/cli-claude-code",
Expand Down
37 changes: 29 additions & 8 deletions src/cli-claude-code/install-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,35 @@ il_arch() {
esac
}

# _il_retry <description> <command>...: runs the command, up to 4 times with
# a pause of 5s, 10s and 15s between tries; returns the last status. For
# the network steps of apt (update, a package download): a host that resets
# some TLS handshakes (repo.mosquitto.org does, about one in three) fails
# even apt's own Acquire::Retries, which retry within seconds.
_il_retry() {
local what="$1" attempt=1 attempts=4 status=0
shift
while :; do
status=0
"$@" || status=$?
if [ "$status" -eq 0 ] || [ "$attempt" -ge "$attempts" ]; then
return "$status"
fi
echo "install-lib: ${what} failed (attempt ${attempt}/${attempts}); retrying in $((attempt * 5))s" >&2
sleep $((attempt * 5))
attempt=$((attempt + 1))
done
}

# il_apt_install <pkg>...: installs packages without recommends, then
# removes the apt lists so they don't stay in the image layer.
il_apt_install() {
if [ "$#" -eq 0 ]; then
_il_die "il_apt_install: no packages given"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
apt-get install -y --no-install-recommends "$@" \
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "$@" \
|| _il_die "apt-get install failed: $*"
rm -rf /var/lib/apt/lists/*
}
Expand Down Expand Up @@ -335,8 +355,9 @@ _il_ensure_curl() {
# including the connect timeout) and HTTP 408/429/5xx; with
# --retry-connrefused also ECONNREFUSED, but not other connect errors
# such as EHOSTUNREACH or ENETUNREACH. This loop retries what curl
# gives up on: DNS and connect failures (exit 6/7), resets and truncated
# transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# gives up on: DNS and connect failures (exit 6/7), TLS handshake
# failures such as repo.mosquitto.org's "unexpected eof" (35), resets and
# truncated transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# Worst case: 4 curl calls of up to 4 attempts each, 16 attempts in
# all. --connect-timeout 10 bounds each attempt's connection phase (DNS,
# TCP and TLS) to 10s, so failing to connect costs at most about 200s
Expand All @@ -354,7 +375,7 @@ _il_curl() {
--retry-connrefused -o "$dest" "$url" || status=$?
case "$status" in
0) return 0 ;;
6 | 7 | 18 | 52 | 55 | 56)
6 | 7 | 18 | 35 | 52 | 55 | 56)
if [ "$call" -lt "$calls" ]; then
echo "install-lib: curl exit ${status} (call ${call}/${calls}); retrying in $((call * 2))s: ${url}" >&2
sleep $((call * 2))
Expand Down Expand Up @@ -452,7 +473,7 @@ il_apt_add_repo() {
rm -rf "$tmp"
echo "install-lib: added apt repository ${name} (key ${fpr})"
export DEBIAN_FRONTEND=noninteractive
if ! apt-get update --error-on=any \
if ! _il_retry "apt-get update for ${name}" apt-get update --error-on=any -o Acquire::Retries=3 \
-o Dir::Etc::SourceList="$list" -o Dir::Etc::SourceParts=- \
-o APT::Get::List-Cleanup=0; then
rm -f "$keyring" "$list"
Expand Down Expand Up @@ -528,7 +549,7 @@ il_apt_install_pinned() {
"(digits and dots, e.g. 18.6; no leading v, no distro revision)"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
# madison prints "pkg | version | source Packages" per version and
# source; Sources lines (deb-src) are skipped.
available="$(apt-cache madison "$pkg" \
Expand Down Expand Up @@ -581,7 +602,7 @@ il_apt_install_pinned() {
fi
done
echo "install-lib: installing ${pkg}=${chosen} ${deps[*]}"
apt-get install -y --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
|| _il_die "apt-get install failed: ${pkg}=${chosen} ${deps[*]}"
if [ "${#auto[@]}" -gt 0 ]; then
apt-mark auto "${auto[@]}" >/dev/null \
Expand Down
2 changes: 1 addition & 1 deletion src/cli-keycloak/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "cli-keycloak",
"version": "1.0.0",
"version": "1.0.1",
"name": "Keycloak admin CLI (kcadm)",
"description": "Installs a Keycloak admin CLI as kcadm: the official kcadm.sh (with a headless JRE) at an exact version, checked against a sha256 you supply, or a small curl wrapper around the Admin REST API. The two flavors share the name, not the syntax. There are no default pins.",
"documentationURL": "https://github.com/craftainer/devcontainer-features/tree/main/src/cli-keycloak",
Expand Down
37 changes: 29 additions & 8 deletions src/cli-keycloak/install-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,35 @@ il_arch() {
esac
}

# _il_retry <description> <command>...: runs the command, up to 4 times with
# a pause of 5s, 10s and 15s between tries; returns the last status. For
# the network steps of apt (update, a package download): a host that resets
# some TLS handshakes (repo.mosquitto.org does, about one in three) fails
# even apt's own Acquire::Retries, which retry within seconds.
_il_retry() {
local what="$1" attempt=1 attempts=4 status=0
shift
while :; do
status=0
"$@" || status=$?
if [ "$status" -eq 0 ] || [ "$attempt" -ge "$attempts" ]; then
return "$status"
fi
echo "install-lib: ${what} failed (attempt ${attempt}/${attempts}); retrying in $((attempt * 5))s" >&2
sleep $((attempt * 5))
attempt=$((attempt + 1))
done
}

# il_apt_install <pkg>...: installs packages without recommends, then
# removes the apt lists so they don't stay in the image layer.
il_apt_install() {
if [ "$#" -eq 0 ]; then
_il_die "il_apt_install: no packages given"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
apt-get install -y --no-install-recommends "$@" \
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "$@" \
|| _il_die "apt-get install failed: $*"
rm -rf /var/lib/apt/lists/*
}
Expand Down Expand Up @@ -335,8 +355,9 @@ _il_ensure_curl() {
# including the connect timeout) and HTTP 408/429/5xx; with
# --retry-connrefused also ECONNREFUSED, but not other connect errors
# such as EHOSTUNREACH or ENETUNREACH. This loop retries what curl
# gives up on: DNS and connect failures (exit 6/7), resets and truncated
# transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# gives up on: DNS and connect failures (exit 6/7), TLS handshake
# failures such as repo.mosquitto.org's "unexpected eof" (35), resets and
# truncated transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# Worst case: 4 curl calls of up to 4 attempts each, 16 attempts in
# all. --connect-timeout 10 bounds each attempt's connection phase (DNS,
# TCP and TLS) to 10s, so failing to connect costs at most about 200s
Expand All @@ -354,7 +375,7 @@ _il_curl() {
--retry-connrefused -o "$dest" "$url" || status=$?
case "$status" in
0) return 0 ;;
6 | 7 | 18 | 52 | 55 | 56)
6 | 7 | 18 | 35 | 52 | 55 | 56)
if [ "$call" -lt "$calls" ]; then
echo "install-lib: curl exit ${status} (call ${call}/${calls}); retrying in $((call * 2))s: ${url}" >&2
sleep $((call * 2))
Expand Down Expand Up @@ -452,7 +473,7 @@ il_apt_add_repo() {
rm -rf "$tmp"
echo "install-lib: added apt repository ${name} (key ${fpr})"
export DEBIAN_FRONTEND=noninteractive
if ! apt-get update --error-on=any \
if ! _il_retry "apt-get update for ${name}" apt-get update --error-on=any -o Acquire::Retries=3 \
-o Dir::Etc::SourceList="$list" -o Dir::Etc::SourceParts=- \
-o APT::Get::List-Cleanup=0; then
rm -f "$keyring" "$list"
Expand Down Expand Up @@ -528,7 +549,7 @@ il_apt_install_pinned() {
"(digits and dots, e.g. 18.6; no leading v, no distro revision)"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
# madison prints "pkg | version | source Packages" per version and
# source; Sources lines (deb-src) are skipped.
available="$(apt-cache madison "$pkg" \
Expand Down Expand Up @@ -581,7 +602,7 @@ il_apt_install_pinned() {
fi
done
echo "install-lib: installing ${pkg}=${chosen} ${deps[*]}"
apt-get install -y --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
|| _il_die "apt-get install failed: ${pkg}=${chosen} ${deps[*]}"
if [ "${#auto[@]}" -gt 0 ]; then
apt-mark auto "${auto[@]}" >/dev/null \
Expand Down
2 changes: 1 addition & 1 deletion src/cli-mosquitto/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "cli-mosquitto",
"version": "1.0.0",
"version": "1.0.1",
"name": "Mosquitto MQTT clients",
"description": "Installs the Eclipse Mosquitto MQTT clients (mosquitto_pub, mosquitto_sub, mosquitto_rr) at an exact upstream version you choose, e.g. 2.0.22: on Debian from repo.mosquitto.org, whose signing key the feature pins by fingerprint, on Ubuntu from the distro's own archive. The versions available differ by distro. There are no default pins.",
"documentationURL": "https://github.com/craftainer/devcontainer-features/tree/main/src/cli-mosquitto",
Expand Down
37 changes: 29 additions & 8 deletions src/cli-mosquitto/install-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,35 @@ il_arch() {
esac
}

# _il_retry <description> <command>...: runs the command, up to 4 times with
# a pause of 5s, 10s and 15s between tries; returns the last status. For
# the network steps of apt (update, a package download): a host that resets
# some TLS handshakes (repo.mosquitto.org does, about one in three) fails
# even apt's own Acquire::Retries, which retry within seconds.
_il_retry() {
local what="$1" attempt=1 attempts=4 status=0
shift
while :; do
status=0
"$@" || status=$?
if [ "$status" -eq 0 ] || [ "$attempt" -ge "$attempts" ]; then
return "$status"
fi
echo "install-lib: ${what} failed (attempt ${attempt}/${attempts}); retrying in $((attempt * 5))s" >&2
sleep $((attempt * 5))
attempt=$((attempt + 1))
done
}

# il_apt_install <pkg>...: installs packages without recommends, then
# removes the apt lists so they don't stay in the image layer.
il_apt_install() {
if [ "$#" -eq 0 ]; then
_il_die "il_apt_install: no packages given"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
apt-get install -y --no-install-recommends "$@" \
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "$@" \
|| _il_die "apt-get install failed: $*"
rm -rf /var/lib/apt/lists/*
}
Expand Down Expand Up @@ -335,8 +355,9 @@ _il_ensure_curl() {
# including the connect timeout) and HTTP 408/429/5xx; with
# --retry-connrefused also ECONNREFUSED, but not other connect errors
# such as EHOSTUNREACH or ENETUNREACH. This loop retries what curl
# gives up on: DNS and connect failures (exit 6/7), resets and truncated
# transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# gives up on: DNS and connect failures (exit 6/7), TLS handshake
# failures such as repo.mosquitto.org's "unexpected eof" (35), resets and
# truncated transfers (18/52/55/56), as scripts/develop.sh's fetch does.
# Worst case: 4 curl calls of up to 4 attempts each, 16 attempts in
# all. --connect-timeout 10 bounds each attempt's connection phase (DNS,
# TCP and TLS) to 10s, so failing to connect costs at most about 200s
Expand All @@ -354,7 +375,7 @@ _il_curl() {
--retry-connrefused -o "$dest" "$url" || status=$?
case "$status" in
0) return 0 ;;
6 | 7 | 18 | 52 | 55 | 56)
6 | 7 | 18 | 35 | 52 | 55 | 56)
if [ "$call" -lt "$calls" ]; then
echo "install-lib: curl exit ${status} (call ${call}/${calls}); retrying in $((call * 2))s: ${url}" >&2
sleep $((call * 2))
Expand Down Expand Up @@ -452,7 +473,7 @@ il_apt_add_repo() {
rm -rf "$tmp"
echo "install-lib: added apt repository ${name} (key ${fpr})"
export DEBIAN_FRONTEND=noninteractive
if ! apt-get update --error-on=any \
if ! _il_retry "apt-get update for ${name}" apt-get update --error-on=any -o Acquire::Retries=3 \
-o Dir::Etc::SourceList="$list" -o Dir::Etc::SourceParts=- \
-o APT::Get::List-Cleanup=0; then
rm -f "$keyring" "$list"
Expand Down Expand Up @@ -528,7 +549,7 @@ il_apt_install_pinned() {
"(digits and dots, e.g. 18.6; no leading v, no distro revision)"
fi
export DEBIAN_FRONTEND=noninteractive
apt-get update || _il_die "apt-get update failed"
_il_retry "apt-get update" apt-get update -o Acquire::Retries=3 || _il_die "apt-get update failed"
# madison prints "pkg | version | source Packages" per version and
# source; Sources lines (deb-src) are skipped.
available="$(apt-cache madison "$pkg" \
Expand Down Expand Up @@ -581,7 +602,7 @@ il_apt_install_pinned() {
fi
done
echo "install-lib: installing ${pkg}=${chosen} ${deps[*]}"
apt-get install -y --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
_il_retry "apt-get install" apt-get install -y -o Acquire::Retries=3 --no-install-recommends "${pkg}=${chosen}" "${deps[@]}" \
|| _il_die "apt-get install failed: ${pkg}=${chosen} ${deps[*]}"
if [ "${#auto[@]}" -gt 0 ]; then
apt-mark auto "${auto[@]}" >/dev/null \
Expand Down
2 changes: 1 addition & 1 deletion src/cli-opencode/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "cli-opencode",
"version": "1.0.0",
"version": "1.0.1",
"name": "opencode",
"description": "Installs the opencode AI coding agent (anomalyco/opencode) at an exact version, checked against a sha256 you supply, with its update checks turned off. There are no default pins.",
"documentationURL": "https://github.com/craftainer/devcontainer-features/tree/main/src/cli-opencode",
Expand Down
Loading
Loading