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.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
fix(agent): vendor the installers from the agent repo, and fail CI on drift
Juan Denis35ddc7494b02
diff --git a/.github/workflows/scripts-nightly.yml b/.github/workflows/scripts-nightly.ymlindex 393ed65c..f9e5e807 100644--- a/.github/workflows/scripts-nightly.yml+++ b/.github/workflows/scripts-nightly.yml@@ -48,6 +48,15 @@ jobs:- name: Verify the agent release chainrun: bash scripts/test/verify-agent-release-chain.sh+ # scripts/install.sh is a VENDORED copy of the agent repo's canonical one+ # (the panel has to serve it off its own disk). Two copies of one file is+ # what caused the second half of #101: one was fixed, the other was not,+ # and nothing compared them. Unit tests cannot see this -- they only ever+ # exercise the copy in their own repo -- so the comparison has to be a+ # cross-repo job. Re-vendor with scripts/sync-agent-installers.sh.+ - name: Vendored installers match the agent repo+ run: bash scripts/test/check-installer-drift.sh+tarball-install:name: Install from a freshly built release tarballruns-on: ubuntu-latestdiff --git a/scripts/install.ps1 b/scripts/install.ps1index 15624043..37e3fee4 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -1,4 +1,16 @@#Requires -RunAsAdministrator+#+# ---------------------------------------------------------------------------+# CANONICAL SOURCE: jhd3197/serverkit-agent -> install.ps1+#+# This file is VENDORED into the panel repo at ServerKit/scripts/install.ps1,+# which is the copy the panel serves at GET /api/v1/servers/install.ps1 (it has+# to exist on the panel's own disk, so the panel cannot simply link to it).+#+# Edit it in the agent repo, then re-vendor with ServerKit's+# scripts/sync-agent-installers.sh. Do not patch one copy only -- see the note+# in install.sh; ServerKit's nightly CI fails on any drift.+# ---------------------------------------------------------------------------<#.SYNOPSISServerKit Agent Installation Script for Windows@@ -48,7 +60,7 @@ $ConfigDir = "$env:ProgramData\ServerKit\Agent"$LogDir = "$env:ProgramData\ServerKit\Agent\logs"$ServiceName = "ServerKitAgent"# The agent has its own repo and its own vX.Y.Z releases; it no longer ships-# from the panel monorepo. Keep in step with scripts/install.sh.+# from the panel monorepo.$GitHubRepo = "jhd3197/serverkit-agent"$AgentBinary = "serverkit-agent.exe"diff --git a/scripts/install.sh b/scripts/install.shindex 0df4d719..4d804a58 100644--- a/scripts/install.sh+++ b/scripts/install.sh@@ -2,6 +2,20 @@## ServerKit Agent Installation Script#+# ---------------------------------------------------------------------------+# CANONICAL SOURCE: jhd3197/serverkit-agent -> install.sh+#+# This file is VENDORED into the panel repo at ServerKit/scripts/install.sh,+# which is the copy the panel serves at GET /api/v1/servers/install.sh (it has+# to exist on the panel's own disk, so the panel cannot simply link to it).+#+# Edit it in the agent repo, then re-vendor with ServerKit's+# scripts/sync-agent-installers.sh. Do not patch one copy only: they silently+# drifted once already, and the panel spent that entire time serving an+# installer that downloaded from a tag scheme that no longer existed+# (ServerKit issue #101). ServerKit's nightly CI now fails on any drift.+# ---------------------------------------------------------------------------+## Usage:# curl -fsSL https://your-serverkit.com/install.sh -o /tmp/serverkit-agent-install.sh \# && sudo bash /tmp/serverkit-agent-install.sh --token "TOKEN" --server "URL"@@ -39,11 +53,10 @@ INSTALL_DIR="/usr/local/bin"CONFIG_DIR="/etc/serverkit-agent"LOG_DIR="/var/log/serverkit-agent"SERVICE_USER="serverkit-agent"-# The agent lives in its own repo and publishes its own releases, tagged plain-# `vX.Y.Z`. It used to live in the panel monorepo under `agent-v*` tags, and this-# script was never updated when it moved -- so every download 404'd against a tag-# scheme that no longer exists anywhere. Keep this in step with-# serverkit-agent/install.sh; the panel serves THIS copy.+# The agent publishes its own releases from its own repo, tagged plain `vX.Y.Z`.+# It used to live in the panel monorepo under `agent-v*` tags, and this script+# was never updated when it moved -- so every download 404'd against a tag scheme+# that no longer exists anywhere (ServerKit issue #101).GITHUB_REPO="jhd3197/serverkit-agent"AGENT_BINARY="serverkit-agent"diff --git a/scripts/sync-agent-installers.sh b/scripts/sync-agent-installers.shnew file mode 100644index 00000000..64369342--- /dev/null+++ b/scripts/sync-agent-installers.sh@@ -0,0 +1,86 @@+#!/usr/bin/env bash+#+# Re-vendor the agent installers from their canonical home.+#+# The agent has its own repository, and its installers are canonical there. The+# panel still needs them on its own disk -- it serves them at+# GET /api/v1/servers/install.sh|.ps1 -- so this repo carries a vendored copy+# under scripts/. That is two copies of one file, which is exactly the shape+# that rots: they drifted silently once, and the panel spent that whole period+# serving an installer whose download URL pointed at a tag scheme that no longer+# existed anywhere (issue #101).+#+# So: edit the agent repo, run this, commit the result. Never patch+# scripts/install.sh directly. scripts/test/check-installer-drift.sh fails if+# anyone does, and ServerKit's nightly CI runs it.+#+# Usage:+# bash scripts/sync-agent-installers.sh # sibling checkout, else GitHub+# bash scripts/sync-agent-installers.sh <path|url> # explicit source+#+# AGENT_REF=v1.2.0 bash scripts/sync-agent-installers.sh # pin a ref when fetching++set -uo pipefail++REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"+AGENT_REPO="${SERVERKIT_AGENT_REPO:-jhd3197/serverkit-agent}"+AGENT_REF="${AGENT_REF:-main}"+SOURCE="${1:-}"++INSTALLERS=(install.sh install.ps1)++# Default source: a sibling checkout if there is one (so this works offline and+# before the agent change is pushed), otherwise the published branch.+if [ -z "$SOURCE" ]; then+ if [ -d "${REPO_ROOT}/../serverkit-agent" ]; then+ SOURCE="$(cd "${REPO_ROOT}/../serverkit-agent" && pwd)"+ else+ SOURCE="https://raw.githubusercontent.com/${AGENT_REPO}/${AGENT_REF}"+ fi+fi++printf '\nvendoring agent installers from: %s\n\n' "$SOURCE"++changed=0+for f in "${INSTALLERS[@]}"; do+ dest="${REPO_ROOT}/scripts/${f}"+ tmp="$(mktemp)"++ if [ -d "$SOURCE" ]; then+ if [ ! -f "${SOURCE}/${f}" ]; then+ printf ' \033[31m✘\033[0m %s not found in %s\n' "$f" "$SOURCE"+ rm -f "$tmp"; exit 1+ fi+ cp "${SOURCE}/${f}" "$tmp"+ else+ if ! curl -fsSL "${SOURCE}/${f}" -o "$tmp"; then+ printf ' \033[31m✘\033[0m could not fetch %s/%s\n' "$SOURCE" "$f"+ rm -f "$tmp"; exit 1+ fi+ fi++ # Normalise to LF and let .gitattributes apply this repo's EOL policy on+ # checkout (*.ps1 is eol=crlf here, LF in the agent repo). The drift check+ # compares EOL-insensitively for the same reason.+ tr -d '\r' < "$tmp" > "${tmp}.lf" && mv "${tmp}.lf" "$tmp"++ if [ -f "$dest" ] && diff -q <(tr -d '\r' < "$dest") "$tmp" >/dev/null 2>&1; then+ printf ' \033[32m=\033[0m %s already up to date\n' "$f"+ rm -f "$tmp"+ continue+ fi++ cp "$tmp" "$dest"+ rm -f "$tmp"+ [ "${f##*.}" = "sh" ] && chmod +x "$dest"+ printf ' \033[33m↓\033[0m %s updated\n' "$f"+ changed=$((changed + 1))+done++printf '\n%d file(s) updated\n' "$changed"+if [ "$changed" -gt 0 ]; then+ printf 'Review and commit scripts/install.sh / scripts/install.ps1.\n'+ printf 'The panel serves these; run scripts/test/smoke-docker-image.sh before releasing.\n\n'+else+ printf '\n'+fidiff --git a/scripts/test/check-installer-drift.sh b/scripts/test/check-installer-drift.shnew file mode 100644index 00000000..eba08e1f--- /dev/null+++ b/scripts/test/check-installer-drift.sh@@ -0,0 +1,87 @@+#!/usr/bin/env bash+#+# Fail if the vendored agent installers have drifted from their canonical copies+# in the agent repository.+#+# This is the guard for the second half of issue #101. The agent moved to its own+# repo and kept its own install.sh; the panel kept serving the copy under+# scripts/. Nothing compared them, so when one was fixed and the other was not,+# the panel went on handing every new server an installer that downloaded from+# `agent-v*` tags which exist in no repository. Both copies looked fine on their+# own -- that is the whole problem with two copies of one file.+#+# Unit tests cannot catch this: they exercise whichever copy is in their repo and+# have no idea the other exists. Only a cross-repo comparison can.+#+# Usage:+# bash scripts/test/check-installer-drift.sh # sibling checkout, else GitHub+# bash scripts/test/check-installer-drift.sh <path|url> # explicit canonical source+#+# Exits non-zero on drift, printing the diff.++set -uo pipefail++REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"+AGENT_REPO="${SERVERKIT_AGENT_REPO:-jhd3197/serverkit-agent}"+AGENT_REF="${AGENT_REF:-main}"+SOURCE="${1:-}"++INSTALLERS=(install.sh install.ps1)++PASS=0+FAIL=0+ok() { PASS=$((PASS + 1)); printf ' \033[32m✔\033[0m %s\n' "$1"; }+bad() { FAIL=$((FAIL + 1)); printf ' \033[31m✘\033[0m %s\n' "$1"; }++WORK="$(mktemp -d)"+trap 'rm -rf "$WORK"' EXIT++if [ -z "$SOURCE" ]; then+ if [ -d "${REPO_ROOT}/../serverkit-agent" ]; then+ SOURCE="$(cd "${REPO_ROOT}/../serverkit-agent" && pwd)"+ else+ SOURCE="https://raw.githubusercontent.com/${AGENT_REPO}/${AGENT_REF}"+ fi+fi++printf '\nagent installer drift check\n canonical: %s\n vendored: %s/scripts\n\n' \+ "$SOURCE" "$REPO_ROOT"++for f in "${INSTALLERS[@]}"; do+ vendored="${REPO_ROOT}/scripts/${f}"+ canonical="${WORK}/${f}"++ if [ ! -f "$vendored" ]; then+ bad "${f} is missing from scripts/ — the panel serves this file"+ continue+ fi++ if [ -d "$SOURCE" ]; then+ if [ ! -f "${SOURCE}/${f}" ]; then+ bad "${f} not found in canonical source ${SOURCE}"+ continue+ fi+ cp "${SOURCE}/${f}" "$canonical"+ else+ if ! curl -fsSL "${SOURCE}/${f}" -o "$canonical"; then+ bad "could not fetch canonical ${f} from ${SOURCE}"+ continue+ fi+ fi++ # EOL-insensitive: this repo's .gitattributes checks *.ps1 out as CRLF while+ # the agent repo has no such rule, so a byte comparison would always fail on+ # install.ps1 for a reason that has nothing to do with drift.+ if diff -u <(tr -d '\r' < "$canonical") <(tr -d '\r' < "$vendored") \+ --label "canonical/${f}" --label "vendored/scripts/${f}" > "${WORK}/${f}.diff"; then+ ok "${f} matches the canonical copy"+ else+ bad "${f} has DRIFTED from the canonical copy in ${AGENT_REPO}"+ printf '\n'+ sed 's/^/ /' "${WORK}/${f}.diff" | head -60+ printf '\n Fix: edit the agent repo, then run scripts/sync-agent-installers.sh\n\n'+ fi+done++printf '\n%d passed, %d failed\n\n' "$PASS" "$FAIL"+[ "$FAIL" -eq 0 ]