From be9fe6084f3456b4e8ee39a7919602b5e3a1c577 Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Fri, 13 Nov 2026 12:43:52 +0100 Subject: [PATCH 1/2] Build Ruby on disk and without docs setup_ruby let ruby-build compile in /tmp, which is tmpfs on Debian 13, so the build tree counted against the container's memory on top of the compiler itself. It now builds under /var/tmp, skips the rdoc/ri docs (several minutes that no server uses) and keeps the build log there when the build fails. --- lib/runtime.func | 11 ++++-- tests/ruby-build-env.sh | 75 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 tests/ruby-build-env.sh diff --git a/lib/runtime.func b/lib/runtime.func index f4030dd..9f5a1e6 100644 --- a/lib/runtime.func +++ b/lib/runtime.func @@ -2432,12 +2432,17 @@ EOF } msg_ok "Updated ruby-build definitions" fi - $STD "$RBENV_BIN" install "$RUBY_VERSION" || { - msg_error "Failed to install Ruby $RUBY_VERSION" + # The build tree goes to disk: /tmp is tmpfs on Debian 13, where it counted + # against the container's memory. The docs took minutes and no server reads them. + local build_tmp + build_tmp="$(mktemp -d -p /var/tmp ruby-build.XXXXXX 2>/dev/null)" || build_tmp="" + $STD env TMPDIR="${build_tmp:-/tmp}" RUBY_CONFIGURE_OPTS="--disable-install-doc ${RUBY_CONFIGURE_OPTS:-}" "$RBENV_BIN" install "$RUBY_VERSION" || { + msg_error "Failed to install Ruby $RUBY_VERSION - the build log is in ${build_tmp:-/tmp}" cd "$PREV_DIR" 2>/dev/null || cd / - rm -rf "$TMP_DIR" + rm -rf "$TMP_DIR" return 150 } + [[ -n "$build_tmp" ]] && rm -rf "$build_tmp" fi "$RBENV_BIN" global "$RUBY_VERSION" || { diff --git a/tests/ruby-build-env.sh b/tests/ruby-build-env.sh new file mode 100644 index 0000000..7e5ed84 --- /dev/null +++ b/tests/ruby-build-env.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +set -uo pipefail + +CORE_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)" +eval "$(awk '/^setup_ruby\(\) \{/,/^}/' "$CORE_DIR/lib/runtime.func")" + +TEST_DIR="$(mktemp -d)" +trap 'rm -rf -- "$TEST_DIR"' EXIT +passed=0 failed=0 + +check() { + if [[ "$3" == "$2" ]]; then + echo "PASS $1" + passed=$((passed + 1)) + else + echo "FAIL $1: expected <$2>, got <$3>" >&2 + failed=$((failed + 1)) + fi +} + +# shellcheck disable=SC2034 # read by setup_ruby +STD="" +msg_info() { :; } +msg_ok() { :; } +msg_warn() { :; } +msg_error() { :; } +ensure_apt_working() { :; } +apt-cache() { echo found; } +apt() { :; } +cache_installed_version() { :; } + +# rbenv and ruby-build are already there; the fake rbenv records how install runs. +export HOME="$TEST_DIR/home" +RBENV="$HOME/.rbenv" +mkdir -p "$RBENV/bin" "$RBENV/plugins/ruby-build/share/ruby-build" +: >"$RBENV/plugins/ruby-build/share/ruby-build/3.4.7" +cat >"$RBENV/bin/rbenv" <"$TEST_DIR/install.log" + exit "\${FAKE_INSTALL_RC:-0}" + ;; +global) [[ -n "\${2:-}" ]] && exit 0 ;; +esac +exit 0 +EOF +chmod +x "$RBENV/bin/rbenv" + +run() { + : >"$TEST_DIR/install.log" + (RUBY_VERSION=3.4.7 RUBY_INSTALL_RAILS=false setup_ruby >/dev/null 2>&1) +} +logged() { sed -n "s/^$1=//p" "$TEST_DIR/install.log"; } + +run +check "setup succeeds" 0 "$?" +check "the build tree is on disk, not in tmpfs /tmp" "/var/tmp" "$(dirname "$(logged tmpdir)")" +check "the build directory exists during the build" "yes" "$(logged tmpdir-exists)" +check "the build directory is removed afterwards" "no" "$([[ -e "$(logged tmpdir)" ]] && echo yes || echo no)" +check "docs are not built" "--disable-install-doc " "$(logged opts)" + +RUBY_CONFIGURE_OPTS="--with-jemalloc" run +check "a caller's configure options are kept" "--disable-install-doc --with-jemalloc" "$(logged opts)" + +FAKE_INSTALL_RC=1 run +check "a failed build fails the setup" 150 "$?" +check "a failed build keeps its log for inspection" "yes" "$([[ -d "$(logged tmpdir)" ]] && echo yes || echo no)" + +echo "${passed} passed, ${failed} failed" +((failed == 0)) From ce7bc90195cc0daedf13d941c69681b00fc27180 Mon Sep 17 00:00:00 2001 From: MickLesk <47820557+MickLesk@users.noreply.github.com> Date: Fri, 13 Nov 2026 15:39:58 +0100 Subject: [PATCH 2/2] Trim the comments to what a reader would get wrong --- lib/runtime.func | 3 +-- tests/ruby-build-env.sh | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/runtime.func b/lib/runtime.func index 9f5a1e6..8b232fb 100644 --- a/lib/runtime.func +++ b/lib/runtime.func @@ -2432,8 +2432,7 @@ EOF } msg_ok "Updated ruby-build definitions" fi - # The build tree goes to disk: /tmp is tmpfs on Debian 13, where it counted - # against the container's memory. The docs took minutes and no server reads them. + # /tmp is tmpfs on Debian 13 and counts against the container's memory local build_tmp build_tmp="$(mktemp -d -p /var/tmp ruby-build.XXXXXX 2>/dev/null)" || build_tmp="" $STD env TMPDIR="${build_tmp:-/tmp}" RUBY_CONFIGURE_OPTS="--disable-install-doc ${RUBY_CONFIGURE_OPTS:-}" "$RBENV_BIN" install "$RUBY_VERSION" || { diff --git a/tests/ruby-build-env.sh b/tests/ruby-build-env.sh index 7e5ed84..e5d18ad 100644 --- a/tests/ruby-build-env.sh +++ b/tests/ruby-build-env.sh @@ -29,7 +29,6 @@ apt-cache() { echo found; } apt() { :; } cache_installed_version() { :; } -# rbenv and ruby-build are already there; the fake rbenv records how install runs. export HOME="$TEST_DIR/home" RBENV="$HOME/.rbenv" mkdir -p "$RBENV/bin" "$RBENV/plugins/ruby-build/share/ruby-build"