Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(installer): require build tools only for local venv builds

Juan Denis5ffc7257a330
diff --git a/install.sh b/install.sh
index bab571c2..75f7859a 100644
--- a/install.sh
+++ b/install.sh
@@ -850,10 +850,10 @@ ensure_python_build_deps() {
provision_python() {
phase "Installing Python"
- # Existing interpreters may have venv support but no development headers.
+ # Native build prerequisites are checked by build_virtualenv only when a
+ # local build is needed; a working release venv does not need a compiler.
if locate_python; then
- ensure_python_build_deps
- return $?
+ return
fi
warn "No supported Python ($PYTHON_MIN–$PYTHON_MAX) found — installing one."
@@ -869,8 +869,7 @@ provision_python() {
refresh_pkg_index
pkg_add python3 python3-venv python3-dev
if locate_python; then
- ensure_python_build_deps
- return $?
+ return
fi
pkg_add python3.12 python3.12-venv python3.12-dev
if ! command -v python3.12 &>/dev/null; then
@@ -924,8 +923,7 @@ provision_python() {
# Did a distro package give us something usable?
if locate_python; then
good "Python ready: $PYTHON_BIN"
- ensure_python_build_deps
- return $?
+ return
fi
# Last resort: compile from source.
@@ -965,7 +963,6 @@ provision_python() {
command -v "$PYTHON_BIN" &>/dev/null || \
halt "Could not install a supported Python — install Python $PYTHON_MIN-$PYTHON_MAX by hand."
good "Python installed ($PYTHON_BIN)."
- ensure_python_build_deps
}
# ---------------------------------------------------------------------------
@@ -1439,6 +1436,9 @@ build_virtualenv() {
fi
fi
+ # Existing interpreters may have venv support without the headers needed
+ # by pip. Check after the release fast path, including its local fallback.
+ ensure_python_build_deps || return $?
step "Creating the virtual environment..."
$PYTHON_BIN -m venv "$VENV_DIR"
if [ ! -f "$VENV_DIR/bin/activate" ]; then
diff --git a/scripts/test/test_install.sh b/scripts/test/test_install.sh
index 11e14d63..c99dcd11 100644
--- a/scripts/test/test_install.sh
+++ b/scripts/test/test_install.sh
@@ -593,6 +593,9 @@ printf '#!/bin/sh\n' > "$t/slot/venv/bin/python"; chmod +x "$t/slot/venv/bin/pyt
if (
set -Eeuo pipefail
INSTALL_FROM_RELEASE=1; FIRST_SLOT="$t/slot"; VENV_DIR="$t/slot/venv"
+ locate_python() { PYTHON_BIN=python3.14; return 0; }
+ ensure_python_build_deps() { exit 1; }
+ provision_python
build_virtualenv \
&& [ -f "$t/slot/venv/bin/activate" ]
) >/dev/null 2>&1; then
@@ -2252,6 +2255,7 @@ if ( set -Eeuo pipefail
ready=1
}
provision_python >/dev/null
+ ensure_python_build_deps >/dev/null
[ "$ready" = 1 ]
); then
ok "existing Python 3.14 gets matching headers and build tools"
@@ -2274,17 +2278,17 @@ else
fi
if ( set -Eeuo pipefail
- OS_FAMILY=debian; ID=ubuntu; installed=0; checked=0
+ OS_FAMILY=debian; ID=ubuntu; installed=0
locate_python() { [ "$installed" = 1 ] && { PYTHON_BIN=python3.14; return 0; }; return 1; }
refresh_pkg_index() { :; }
pkg_add() {
[ "$*" = 'python3 python3-venv python3-dev' ] || exit 1
installed=1
}
- ensure_python_build_deps() { checked=1; }
+ ensure_python_build_deps() { exit 1; }
add-apt-repository() { exit 1; }
provision_python >/dev/null
- [ "$installed" = 1 ] && [ "$checked" = 1 ]
+ [ "$installed" = 1 ]
); then
ok "Ubuntu uses its supported default Python without a PPA"
else
@@ -2302,6 +2306,53 @@ else
bad "working native build environment tried to install packages"
fi
+# A source install, absent release venv, or incompatible release interpreter
+# must all check native prerequisites before creating a venv or invoking pip.
+for build_case in source missing-release broken-release; do
+ if ( set -Eeuo pipefail
+ build_dir="$WORK/native-$build_case"
+ mkdir -p "$build_dir/slot"
+ FIRST_SLOT="$build_dir/slot"; VENV_DIR="$FIRST_SLOT/venv"
+ INSTALL_FROM_RELEASE=1
+ [ "$build_case" != source ] || INSTALL_FROM_RELEASE=0
+ if [ "$build_case" = broken-release ]; then
+ mkdir -p "$VENV_DIR/bin"
+ : > "$VENV_DIR/bin/activate"
+ printf '#!/bin/sh\nexit 1\n' > "$VENV_DIR/bin/python"
+ chmod +x "$VENV_DIR/bin/python"
+ fi
+ ready=0; pip_called=0
+ ensure_python_build_deps() { ready=1; }
+ PYTHON_BIN=test_build_python
+ test_build_python() {
+ [ "$ready" = 1 ] || exit 1
+ mkdir -p "$VENV_DIR/bin"
+ : > "$VENV_DIR/bin/activate"
+ }
+ pip() { [ "$ready" = 1 ] || exit 1; pip_called=1; }
+ build_virtualenv >/dev/null 2>&1
+ [ "$ready" = 1 ] && [ "$pip_called" = 1 ]
+ ); then
+ ok "$build_case checks build prerequisites before pip"
+ else
+ bad "$build_case skipped build prerequisites"
+ fi
+done
+
+if ( set -Eeuo pipefail
+ INSTALL_FROM_RELEASE=0
+ ensure_python_build_deps() { return 1; }
+ PYTHON_BIN=never_build_python
+ never_build_python() { exit 99; }
+ rc=0
+ build_virtualenv >/dev/null 2>&1 || rc=$?
+ [ "$rc" = 1 ]
+); then
+ ok "failed prerequisites stop the local build before venv creation"
+else
+ bad "local build ignored prerequisite failure"
+fi
+
# -- static guard: the documented insecure site must keep shipping, since both
# the docs and SERVERKIT_EXTERNAL_PROXY point operators straight at it.
if [ -f "$REPO_DIR/nginx/sites-available/serverkit-insecure.conf" ] \
diff --git a/scripts/test/test_provision_python.sh b/scripts/test/test_provision_python.sh
index c85f5d28..e11f67f6 100644
--- a/scripts/test/test_provision_python.sh
+++ b/scripts/test/test_provision_python.sh
@@ -10,8 +10,9 @@
# (nothing in install.sh ever installs a compiler). Seven distro images in CI
# and none of them caught it, because none of them ran this code for real.
#
-# So: run identify_system + choose_pkg_manager + provision_python against the
-# real repos, then prove the result is usable. No systemd, no nginx, no network
+# So: run identify_system + choose_pkg_manager + provision_python and the
+# local-build prerequisites against real repos, then prove the result is
+# usable. No systemd, no nginx, no network
# services — this fits in the plain distro containers the matrix already pulls.
#
# Destructive: installs packages. Intended for a container or a throwaway VM.
@@ -112,7 +113,7 @@ halt() {
return 1
}
-if provision_python >/tmp/pp.log 2>&1; then
+if { provision_python && ensure_python_build_deps; } >/tmp/pp.log 2>&1; then
prov_rc=0
else
prov_rc=$?