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.

ci: boot the built image, and check the agent download URLs resolve

Juan Denis4f12f8164ddf
diff --git a/.github/workflows/release-smoke.yml b/.github/workflows/release-smoke.yml
index b47ef848..d875dcd9 100644
--- a/.github/workflows/release-smoke.yml
+++ b/.github/workflows/release-smoke.yml
@@ -14,7 +14,9 @@ on:
paths:
- 'frontend/**'
- 'backend/**'
- - 'scripts/build-release.sh'
+ - 'scripts/**'
+ - 'Dockerfile'
+ - '.dockerignore'
- '.github/workflows/release-smoke.yml'
- '.github/workflows/release.yml'
- 'VERSION'
@@ -23,7 +25,9 @@ on:
paths:
- 'frontend/**'
- 'backend/**'
- - 'scripts/build-release.sh'
+ - 'scripts/**'
+ - 'Dockerfile'
+ - '.dockerignore'
- '.github/workflows/release-smoke.yml'
- '.github/workflows/release.yml'
- 'VERSION'
@@ -48,3 +52,34 @@ jobs:
- name: Run release build script
run: bash scripts/build-release.sh
+
+ # The tarball job above proves the *source* packaging. This one proves the
+ # *image* packaging, which is a different artifact with a different file list
+ # -- and the one that shipped issue #101 (the panel serves scripts/install.sh
+ # off its own disk; the Dockerfile never copied it, so every containerised
+ # panel 404'd the enrollment URL its own UI prints). Booting the image is the
+ # only check that sees it: pytest runs against the source tree, where the file
+ # is always present.
+ docker-image-smoke:
+ name: Boot the Docker image
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v3
+
+ - name: Build image (amd64)
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ platforms: linux/amd64
+ push: false
+ load: true
+ tags: serverkit:smoke
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+
+ - name: Smoke test the built image
+ run: SKIP_BUILD=1 bash scripts/test/smoke-docker-image.sh serverkit:smoke
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 13a5d4e8..a9c6c184 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -136,12 +136,38 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}
continue-on-error: true
+ # Build amd64 first and boot it before anything is published. Issue #101
+ # shipped because this job went straight from `build` to `push`: the image
+ # was missing scripts/, so /api/v1/servers/install.sh 404'd in every
+ # container while the whole test suite stayed green (pytest runs against
+ # the source tree, where the file always exists). Only booting the artifact
+ # catches that. The layers are cached, so the multi-arch push below reuses
+ # this build rather than repeating it.
+ - name: Build amd64 image for smoke test
+ uses: docker/build-push-action@v5
+ with:
+ context: .
+ platforms: linux/amd64
+ push: false
+ load: true
+ tags: serverkit:smoke
+ cache-from: type=gha
+ cache-to: type=gha,mode=max
+ build-args: |
+ VERSION=${{ needs.version.outputs.version }}
+ BUILD_TIME=${{ github.event.repository.updated_at }}
+ GIT_COMMIT=${{ github.sha }}
+
+ - name: Smoke test the built image
+ run: SKIP_BUILD=1 bash scripts/test/smoke-docker-image.sh serverkit:smoke
+
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ secrets.DOCKERHUB_USERNAME != '' }}
+ cache-from: type=gha
tags: |
${{ env.DOCKER_IMAGE }}:latest
${{ env.DOCKER_IMAGE }}:${{ needs.version.outputs.version }}
diff --git a/.github/workflows/scripts-nightly.yml b/.github/workflows/scripts-nightly.yml
index 9a752bc1..393ed65c 100644
--- a/.github/workflows/scripts-nightly.yml
+++ b/.github/workflows/scripts-nightly.yml
@@ -30,6 +30,24 @@ on:
workflow_dispatch:
jobs:
+ # Asks GitHub whether the URLs the agent installer builds resolve to real
+ # assets. Every unit test stubs curl, so they prove the script is internally
+ # consistent and nothing more -- which is how the installer went on pointing
+ # at jhd3197/ServerKit and `agent-v*` tags for the entire period after the Go
+ # agent moved to its own repo (issue #101). This job is also the tripwire for
+ # the reverse case: a change to the agent's release naming or tag scheme
+ # breaking the panel's installer from the other side of the repo split.
+ agent-release-chain:
+ name: Agent download URLs resolve on GitHub
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ - name: Verify the agent release chain
+ run: bash scripts/test/verify-agent-release-chain.sh
+
tarball-install:
name: Install from a freshly built release tarball
runs-on: ubuntu-latest
diff --git a/scripts/test/smoke-docker-image.sh b/scripts/test/smoke-docker-image.sh
new file mode 100644
index 00000000..be4732bb
--- /dev/null
+++ b/scripts/test/smoke-docker-image.sh
@@ -0,0 +1,145 @@
+#!/usr/bin/env bash
+#
+# Smoke-test a BUILT ServerKit image.
+#
+# This is the check that issue #101 needed and nobody had. Everything the panel
+# reads off its own filesystem at request time -- installers, the SPA bundle,
+# the VERSION file -- exists in the source tree, so the whole pytest suite passes
+# while the shipped image is missing the file. The only way to catch that class
+# of bug is to boot the artifact you are about to publish and ask it for the
+# things it promises to serve.
+#
+# Usage:
+# bash scripts/test/smoke-docker-image.sh # builds serverkit:smoke, then tests
+# bash scripts/test/smoke-docker-image.sh <image[:tag]> # tests an image you already have
+# SKIP_BUILD=1 bash scripts/test/smoke-docker-image.sh # reuse the existing serverkit:smoke
+#
+# Exits non-zero on the first failed assertion, with the response that failed.
+
+set -uo pipefail
+
+IMAGE="${1:-serverkit:smoke}"
+PORT="${SMOKE_PORT:-45990}"
+CONTAINER="serverkit-smoke-$$"
+REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
+
+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"; }
+
+cleanup() {
+ if [ -n "${CONTAINER:-}" ] && docker inspect "$CONTAINER" >/dev/null 2>&1; then
+ printf '\n--- container logs (tail) ---\n'
+ docker logs --tail 40 "$CONTAINER" 2>&1 || true
+ docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
+ fi
+}
+trap cleanup EXIT
+
+# --------------------------------------------------------------------------
+# Build (unless we were handed an image or told to skip)
+# --------------------------------------------------------------------------
+if [ -z "${SKIP_BUILD:-}" ] && [ "$IMAGE" = "serverkit:smoke" ]; then
+ printf '\nBuilding %s (this is the slow part)...\n' "$IMAGE"
+ if ! docker build -t "$IMAGE" "$REPO_ROOT"; then
+ printf '\n\033[31mimage build failed\033[0m\n'
+ exit 1
+ fi
+fi
+
+printf '\nServerKit image smoke test — %s\n\n' "$IMAGE"
+
+# --------------------------------------------------------------------------
+# Filesystem assertions: cheap, and they name the missing path directly rather
+# than making you infer it from an HTTP status.
+# --------------------------------------------------------------------------
+for f in /app/scripts/install.sh /app/scripts/install.ps1 /app/VERSION \
+ /app/frontend/dist/index.html; do
+ if docker run --rm --entrypoint sh "$IMAGE" -c "test -f $f" 2>/dev/null; then
+ ok "image contains $f"
+ else
+ bad "image is MISSING $f — it will be requested at runtime"
+ fi
+done
+
+# --------------------------------------------------------------------------
+# Boot it
+# --------------------------------------------------------------------------
+docker rm -f "$CONTAINER" >/dev/null 2>&1 || true
+if ! docker run -d --name "$CONTAINER" -p "${PORT}:5000" \
+ -e SECRET_KEY=smoke-secret \
+ -e JWT_SECRET_KEY=smoke-jwt \
+ "$IMAGE" >/dev/null; then
+ bad "container failed to start"
+ exit 1
+fi
+
+BASE="http://127.0.0.1:${PORT}"
+printf ' waiting for %s/api/v1/system/health ...\n' "$BASE"
+ready=""
+for _ in $(seq 1 90); do
+ if curl -fsS -o /dev/null "${BASE}/api/v1/system/health" 2>/dev/null; then
+ ready=1
+ break
+ fi
+ # A container that has already exited will never become ready.
+ if [ "$(docker inspect -f '{{.State.Running}}' "$CONTAINER" 2>/dev/null)" != "true" ]; then
+ bad "container exited during boot"
+ exit 1
+ fi
+ sleep 2
+done
+
+if [ -n "$ready" ]; then
+ ok "panel boots and answers /api/v1/system/health"
+else
+ bad "panel never became healthy"
+ exit 1
+fi
+
+# --------------------------------------------------------------------------
+# HTTP assertions: every route that serves a file off the panel's own disk.
+# --------------------------------------------------------------------------
+assert_http() {
+ local path="$1" want="$2" desc="$3"
+ local code
+ code="$(curl -s -o /tmp/smoke-body.$$ -w '%{http_code}' "${BASE}${path}")"
+ if [ "$code" = "$want" ]; then
+ ok "$desc"
+ else
+ bad "$desc — got HTTP $code, want $want: $(head -c 200 /tmp/smoke-body.$$)"
+ fi
+ rm -f /tmp/smoke-body.$$
+}
+
+assert_body() {
+ local path="$1" needle="$2" desc="$3"
+ if curl -fsS "${BASE}${path}" 2>/dev/null | grep -q -- "$needle"; then
+ ok "$desc"
+ else
+ bad "$desc — '$needle' not found in the response body"
+ fi
+}
+
+# The exact request from issue #101.
+assert_http /api/v1/servers/install.sh 200 "GET /api/v1/servers/install.sh serves the agent installer"
+assert_http /api/v1/servers/install.ps1 200 "GET /api/v1/servers/install.ps1 serves the Windows installer"
+assert_http / 200 "GET / serves the SPA"
+
+assert_body /api/v1/servers/install.sh '#!/bin/bash' \
+ "the served install.sh is a real bash script"
+# Placeholder substitution runs against the served copy; if it silently stopped
+# working the box would try to enroll against a nonexistent domain.
+if curl -fsS "${BASE}/api/v1/servers/install.sh" | grep -q 'your-serverkit.com'; then
+ bad "served install.sh still contains the your-serverkit.com placeholder"
+else
+ ok "served install.sh has this panel's URL substituted in"
+fi
+assert_body /api/v1/servers/install.sh 'jhd3197/serverkit-agent' \
+ "the served install.sh downloads from the agent release repo"
+assert_body /api/v1/servers/install.ps1 'Install-ServerKitAgent' \
+ "the served install.ps1 is a real PowerShell installer"
+
+printf '\n%d passed, %d failed\n\n' "$PASS" "$FAIL"
+[ "$FAIL" -eq 0 ]
diff --git a/scripts/test/verify-agent-release-chain.sh b/scripts/test/verify-agent-release-chain.sh
new file mode 100644
index 00000000..4038ff0a
--- /dev/null
+++ b/scripts/test/verify-agent-release-chain.sh
@@ -0,0 +1,145 @@
+#!/usr/bin/env bash
+#
+# Verify the agent enrollment chain against the REAL GitHub releases.
+#
+# Issue #101 had two breaks stacked on top of each other:
+#
+# 1. the panel image never shipped scripts/install.sh, so the enrollment URL
+# 404'd (covered by scripts/test/smoke-docker-image.sh), and
+# 2. the installer it would have served pointed at jhd3197/ServerKit and
+# `agent-v*` tags -- coordinates that stopped existing when the Go agent
+# moved to its own repo. Fixing (1) alone just moves the failure one step
+# later, into the download.
+#
+# Unit tests cannot see (2): they stub curl, so they only ever prove the script
+# is self-consistent, never that the URL it builds resolves to a real file. This
+# script asks GitHub. It needs network but no root, no Docker and no systemd.
+#
+# Usage:
+# bash scripts/test/verify-agent-release-chain.sh
+# bash scripts/test/verify-agent-release-chain.sh <panel-base-url>
+#
+# With a panel URL it checks the chain end to end, starting from the script the
+# panel actually serves. Without one it checks the script in this checkout.
+
+set -uo pipefail
+
+PANEL_URL="${1:-}"
+REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
+WORK="$(mktemp -d)"
+trap 'rm -rf "$WORK"' EXIT
+
+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"; }
+
+printf '\nagent release chain\n\n'
+
+# --------------------------------------------------------------------------
+# 1. Get the installer -- from the panel if we were given one, else from disk.
+# --------------------------------------------------------------------------
+INSTALLER="$WORK/install.sh"
+if [ -n "$PANEL_URL" ]; then
+ url="${PANEL_URL%/}/api/v1/servers/install.sh"
+ if curl -fsSL "$url" -o "$INSTALLER"; then
+ ok "panel serves the installer at $url"
+ else
+ bad "panel did not serve $url (this is the #101 symptom)"
+ printf '\n%d passed, %d failed\n\n' "$PASS" "$FAIL"
+ exit 1
+ fi
+else
+ cp "$REPO_ROOT/scripts/install.sh" "$INSTALLER"
+ ok "using scripts/install.sh from this checkout"
+fi
+
+# --------------------------------------------------------------------------
+# 2. Read the coordinates back out of the script itself, so we test what the
+# installer will really do rather than what we assume it does.
+# --------------------------------------------------------------------------
+REPO="$(grep -m1 '^GITHUB_REPO=' "$INSTALLER" | cut -d'"' -f2)"
+if [ -n "$REPO" ]; then
+ ok "installer targets repo: $REPO"
+else
+ bad "could not read GITHUB_REPO out of the installer"
+ exit 1
+fi
+
+# --------------------------------------------------------------------------
+# 3. Resolve a version the same way the installer does.
+# --------------------------------------------------------------------------
+releases="$WORK/releases.json"
+if ! curl -fsSL "https://api.github.com/repos/${REPO}/releases?per_page=100&page=1" -o "$releases"; then
+ bad "GitHub API unreachable for ${REPO} (rate limited? offline?)"
+ printf '\n%d passed, %d failed\n\n' "$PASS" "$FAIL"
+ exit 1
+fi
+
+VERSION="$(grep -o '"tag_name": *"v[0-9][^"]*"' "$releases" | head -1 | sed -e 's/.*"v//' -e 's/"$//')"
+if [ -n "$VERSION" ]; then
+ ok "resolved latest agent version: v${VERSION}"
+else
+ bad "no vX.Y.Z release found in ${REPO} — enrollment cannot resolve a version"
+ printf '\n%d passed, %d failed\n\n' "$PASS" "$FAIL"
+ exit 1
+fi
+
+# --------------------------------------------------------------------------
+# 4. The URLs the installer builds must resolve to real assets. This is the
+# assertion that was missing: every unit test stubbed curl, so nothing ever
+# asked GitHub whether the download target existed.
+# --------------------------------------------------------------------------
+for arch in amd64 arm64; do
+ asset="serverkit-agent-${VERSION}-linux-${arch}.tar.gz"
+ url="https://github.com/${REPO}/releases/download/v${VERSION}/${asset}"
+ code="$(curl -sSL -o /dev/null -w '%{http_code}' "$url")"
+ if [ "$code" = "200" ]; then
+ ok "linux-${arch} asset exists: ${asset}"
+ else
+ bad "HTTP ${code} for ${url}"
+ fi
+done
+
+checksums_url="https://github.com/${REPO}/releases/download/v${VERSION}/checksums.txt"
+if curl -fsSL "$checksums_url" -o "$WORK/checksums.txt"; then
+ ok "checksums.txt published for v${VERSION}"
+ if grep -q "serverkit-agent-${VERSION}-linux-amd64.tar.gz" "$WORK/checksums.txt"; then
+ ok "checksums.txt names the asset the installer downloads"
+ else
+ bad "checksums.txt has no entry for serverkit-agent-${VERSION}-linux-amd64.tar.gz"
+ fi
+else
+ bad "checksums.txt missing for v${VERSION} — installs proceed unverified"
+fi
+
+# --------------------------------------------------------------------------
+# 5. Download for real and confirm the archive lays out the way the installer
+# expects. `mv ${TMP_DIR}/serverkit-agent-linux-${ARCH}` is a hard dependency
+# on the entry name inside the tarball.
+# --------------------------------------------------------------------------
+asset="serverkit-agent-${VERSION}-linux-amd64.tar.gz"
+if curl -fsSL "https://github.com/${REPO}/releases/download/v${VERSION}/${asset}" \
+ -o "$WORK/$asset"; then
+ ok "downloaded ${asset}"
+
+ if command -v sha256sum >/dev/null 2>&1 && [ -f "$WORK/checksums.txt" ]; then
+ if (cd "$WORK" && sha256sum -c <(grep "$asset" checksums.txt) >/dev/null 2>&1); then
+ ok "checksum verifies (the installer would accept this archive)"
+ else
+ bad "checksum MISMATCH — the installer would abort the install"
+ fi
+ fi
+
+ expected="$(grep -o 'serverkit-agent-linux-\${ARCH}' "$INSTALLER" | head -1)"
+ if tar -tzf "$WORK/$asset" | grep -qx "serverkit-agent-linux-amd64"; then
+ ok "archive contains serverkit-agent-linux-amd64, the name the installer moves"
+ else
+ bad "archive layout changed; installer expects ${expected:-serverkit-agent-linux-<arch>}: $(tar -tzf "$WORK/$asset" | tr '\n' ' ')"
+ fi
+else
+ bad "could not download ${asset} — enrollment would fail here"
+fi
+
+printf '\n%d passed, %d failed\n\n' "$PASS" "$FAIL"
+[ "$FAIL" -eq 0 ]