fix: PXE boot debugging — bisect root cause, syslog logging, serial console #3

Merged
michal merged 31 commits from wip/ks-debugging into main 2026-03-29 00:50:05 +00:00
4 changed files with 288 additions and 80 deletions
Showing only changes of commit 52e1932bde - Show all commits

View File

@@ -79,7 +79,7 @@ jobs:
- name: Run tests - name: Run tests
run: pnpm test:run run: pnpm test:run
# -- Build & package --------------------------------------- # -- Build & package (both architectures) -------------------
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -112,28 +112,38 @@ jobs:
curl -sL -o /tmp/nfpm.tar.gz "https://github.com/goreleaser/nfpm/releases/download/v2.45.0/nfpm_2.45.0_Linux_x86_64.tar.gz" curl -sL -o /tmp/nfpm.tar.gz "https://github.com/goreleaser/nfpm/releases/download/v2.45.0/nfpm_2.45.0_Linux_x86_64.tar.gz"
tar xzf /tmp/nfpm.tar.gz -C /usr/local/bin nfpm tar xzf /tmp/nfpm.tar.gz -C /usr/local/bin nfpm
- name: Bundle standalone binary - name: Bundle x86_64 binary
run: | run: |
mkdir -p dist mkdir -p dist
bun build src/cli/src/index.ts --compile --outfile dist/lab bun build src/cli/src/index.ts --compile --target=bun-linux-x64 --outfile dist/lab-x86_64
- name: Package RPM - name: Bundle arm64 binary
run: nfpm pkg --packager rpm --target dist/ run: |
bun build src/cli/src/index.ts --compile --target=bun-linux-arm64 --outfile dist/lab-arm64
- name: Package DEB - name: Package x86_64 RPM + DEB
run: nfpm pkg --packager deb --target dist/ run: |
sed -e 's|^arch:.*|arch: amd64|' -e 's|src: ./dist/lab$|src: ./dist/lab-x86_64|' nfpm.yaml > /tmp/nfpm-x86_64.yaml
nfpm pkg --config /tmp/nfpm-x86_64.yaml --packager rpm --target dist/
nfpm pkg --config /tmp/nfpm-x86_64.yaml --packager deb --target dist/
- name: Upload RPM artifact - name: Package arm64 RPM + DEB
run: |
sed -e 's|^arch:.*|arch: arm64|' -e 's|src: ./dist/lab$|src: ./dist/lab-arm64|' nfpm.yaml > /tmp/nfpm-arm64.yaml
nfpm pkg --config /tmp/nfpm-arm64.yaml --packager rpm --target dist/
nfpm pkg --config /tmp/nfpm-arm64.yaml --packager deb --target dist/
- name: Upload RPM artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: rpm-package name: rpm-packages
path: bastion/dist/lab-*.rpm path: bastion/dist/lab-*.rpm
retention-days: 7 retention-days: 7
- name: Upload DEB artifact - name: Upload DEB artifacts
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: deb-package name: deb-packages
path: bastion/dist/lab*.deb path: bastion/dist/lab*.deb
retention-days: 7 retention-days: 7
@@ -149,25 +159,27 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Download RPM artifact - name: Download RPM artifacts
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: rpm-package name: rpm-packages
path: bastion/dist/ path: bastion/dist/
- name: Install rpm tools - name: Install rpm tools
run: sudo apt-get update && sudo apt-get install -y rpm run: sudo apt-get update && sudo apt-get install -y rpm
- name: Publish RPM to Gitea - name: Publish RPMs to Gitea
env: env:
GITEA_TOKEN: ${{ secrets.PACKAGES_TOKEN }} GITEA_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
GITEA_URL: http://${{ env.GITEA_REGISTRY }} GITEA_URL: http://${{ env.GITEA_REGISTRY }}
GITEA_OWNER: ${{ env.GITEA_OWNER }} GITEA_OWNER: ${{ env.GITEA_OWNER }}
GITEA_REPO: lab GITEA_REPO: lab
run: | run: |
RPM_FILE=$(ls dist/lab-*.rpm | head -1) for RPM_FILE in dist/lab-*.rpm; do
[ -f "$RPM_FILE" ] || continue
RPM_VERSION=$(rpm -qp --queryformat '%{VERSION}-%{RELEASE}' "$RPM_FILE") RPM_VERSION=$(rpm -qp --queryformat '%{VERSION}-%{RELEASE}' "$RPM_FILE")
echo "Publishing $RPM_FILE (version $RPM_VERSION)..." RPM_ARCH=$(rpm -qp --queryformat '%{ARCH}' "$RPM_FILE")
echo "Publishing $RPM_FILE (version $RPM_VERSION, arch $RPM_ARCH)..."
# Delete existing version if present # Delete existing version if present
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
@@ -187,7 +199,8 @@ jobs:
--upload-file "$RPM_FILE" \ --upload-file "$RPM_FILE" \
"${GITEA_URL}/api/packages/${GITEA_OWNER}/rpm/upload" "${GITEA_URL}/api/packages/${GITEA_OWNER}/rpm/upload"
echo "Published successfully!" echo "Published $RPM_FILE successfully!"
done
# Link package to repo # Link package to repo
source scripts/link-package.sh source scripts/link-package.sh
@@ -203,26 +216,28 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Download DEB artifact - name: Download DEB artifacts
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: deb-package name: deb-packages
path: bastion/dist/ path: bastion/dist/
- name: Publish DEB to Gitea - name: Publish DEBs to Gitea
env: env:
GITEA_TOKEN: ${{ secrets.PACKAGES_TOKEN }} GITEA_TOKEN: ${{ secrets.PACKAGES_TOKEN }}
GITEA_URL: http://${{ env.GITEA_REGISTRY }} GITEA_URL: http://${{ env.GITEA_REGISTRY }}
GITEA_OWNER: ${{ env.GITEA_OWNER }} GITEA_OWNER: ${{ env.GITEA_OWNER }}
GITEA_REPO: lab GITEA_REPO: lab
run: | run: |
DEB_FILE=$(ls dist/lab*.deb | head -1)
DEB_VERSION=$(dpkg-deb --field "$DEB_FILE" Version)
echo "Publishing $DEB_FILE (version $DEB_VERSION)..."
# Publish to each supported distribution # Publish to each supported distribution
DISTRIBUTIONS="trixie forky noble plucky" DISTRIBUTIONS="trixie forky noble plucky"
for DEB_FILE in dist/lab*.deb; do
[ -f "$DEB_FILE" ] || continue
DEB_VERSION=$(dpkg-deb --field "$DEB_FILE" Version)
DEB_ARCH=$(dpkg-deb --field "$DEB_FILE" Architecture)
echo "Publishing $DEB_FILE (version $DEB_VERSION, arch $DEB_ARCH)..."
for DIST in $DISTRIBUTIONS; do for DIST in $DISTRIBUTIONS; do
echo " -> $DIST..." echo " -> $DIST..."
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
@@ -239,6 +254,7 @@ jobs:
echo " WARNING: Upload to $DIST returned HTTP $HTTP_CODE" echo " WARNING: Upload to $DIST returned HTTP $HTTP_CODE"
fi fi
done done
done
echo "Published successfully!" echo "Published successfully!"

View File

@@ -11,14 +11,72 @@ if [ -f .env ]; then
set -a; source .env; set +a set -a; source .env; set +a
fi fi
# ── Argument parsing ───────────────────────────────────────────────
TARGET_ARCH=""
usage() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS] [TAG]
Build bastion container image and optionally push to registry.
Options:
--arch ARCH Target platform: x86_64 or arm64 (default: host arch)
-h, --help Show this help message
Arguments:
TAG Image tag (default: version from package.json)
EOF
exit 0
}
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--arch)
TARGET_ARCH="$2"
shift 2
;;
-h|--help)
usage
;;
*)
POSITIONAL_ARGS+=("$1")
shift
;;
esac
done
# Registry defaults to internal address (external proxy has body size limit) # Registry defaults to internal address (external proxy has body size limit)
REGISTRY="${GITEA_REGISTRY:-mysources.co.uk}" REGISTRY="${GITEA_REGISTRY:-mysources.co.uk}"
IMAGE="lab-bastion" IMAGE="lab-bastion"
VERSION=$(node -p "require('./package.json').version") VERSION=$(node -p "require('./package.json').version")
TAG="${1:-$VERSION}" TAG="${POSITIONAL_ARGS[0]:-$VERSION}"
echo "==> Building bastion image (tag: $TAG)..." # ── Resolve target platform ───────────────────────────────────────
podman build -t "$IMAGE:$TAG" -f stack/Dockerfile . detect_host_arch() {
local machine
machine="$(uname -m)"
case "$machine" in
x86_64) echo "x86_64" ;;
aarch64) echo "arm64" ;;
arm64) echo "arm64" ;;
*) echo "$machine" ;;
esac
}
docker_platform_for() {
case "$1" in
x86_64) echo "linux/amd64" ;;
arm64) echo "linux/arm64" ;;
esac
}
ARCH="${TARGET_ARCH:-$(detect_host_arch)}"
PLATFORM="$(docker_platform_for "$ARCH")"
echo "==> Building bastion image (tag: $TAG, platform: $PLATFORM)..."
podman build --platform "$PLATFORM" -t "$IMAGE:$TAG" -f stack/Dockerfile .
echo "==> Tagging as $REGISTRY/michal/$IMAGE:$TAG..." echo "==> Tagging as $REGISTRY/michal/$IMAGE:$TAG..."
podman tag "$IMAGE:$TAG" "$REGISTRY/michal/$IMAGE:$TAG" podman tag "$IMAGE:$TAG" "$REGISTRY/michal/$IMAGE:$TAG"
@@ -41,3 +99,4 @@ fi
echo "==> Done!" echo "==> Done!"
echo " Image: $REGISTRY/michal/$IMAGE:$TAG" echo " Image: $REGISTRY/michal/$IMAGE:$TAG"
echo " Platform: $PLATFORM"

View File

@@ -13,9 +13,147 @@ fi
# Ensure tools are on PATH # Ensure tools are on PATH
export PATH="$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH" export PATH="$HOME/.npm-global/bin:$HOME/.bun/bin:$HOME/.local/bin:$PATH"
# ── Argument parsing ───────────────────────────────────────────────
BUILD_ALL=false
TARGET_ARCH=""
SKIP_TESTS=false
usage() {
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
Build lab binary and produce RPM/DEB packages.
Options:
--arch ARCH Target architecture: x86_64 or arm64 (default: host arch)
--all Build for both x86_64 and arm64
--skip-tests Skip unit tests (useful in CI where tests ran separately)
-h, --help Show this help message
EOF
exit 0
}
while [[ $# -gt 0 ]]; do
case "$1" in
--arch)
TARGET_ARCH="$2"
shift 2
;;
--all)
BUILD_ALL=true
shift
;;
--skip-tests)
SKIP_TESTS=true
shift
;;
-h|--help)
usage
;;
*)
echo "Unknown option: $1"
usage
;;
esac
done
# ── Resolve host architecture ─────────────────────────────────────
detect_host_arch() {
local machine
machine="$(uname -m)"
case "$machine" in
x86_64) echo "x86_64" ;;
aarch64) echo "arm64" ;;
arm64) echo "arm64" ;;
*) echo "$machine" ;;
esac
}
# ── Architecture mapping helpers ──────────────────────────────────
# Maps our canonical arch names to the values each tool expects.
bun_target_for() {
case "$1" in
x86_64) echo "bun-linux-x64" ;;
arm64) echo "bun-linux-arm64" ;;
esac
}
nfpm_arch_for() {
case "$1" in
x86_64) echo "amd64" ;;
arm64) echo "arm64" ;;
esac
}
rpm_arch_for() {
case "$1" in
x86_64) echo "x86_64" ;;
arm64) echo "aarch64" ;;
esac
}
deb_arch_for() {
case "$1" in
x86_64) echo "amd64" ;;
arm64) echo "arm64" ;;
esac
}
# ── Build one architecture ────────────────────────────────────────
build_arch() {
local arch="$1"
local bun_target nfpm_arch binary_name
bun_target="$(bun_target_for "$arch")"
nfpm_arch="$(nfpm_arch_for "$arch")"
binary_name="dist/lab-${arch}"
echo ""
echo "==> Bundling standalone binary for ${arch}..."
bun build src/cli/src/index.ts --compile --target="${bun_target}" --outfile "${binary_name}"
echo "==> Packaging RPM (${arch})..."
# Create a temporary nfpm config with the correct arch and binary path
local tmpconfig
tmpconfig="$(mktemp /tmp/nfpm-XXXXXX.yaml)"
sed -e "s|^arch:.*|arch: ${nfpm_arch}|" \
-e "s|src: ./dist/lab$|src: ./${binary_name}|" \
nfpm.yaml > "$tmpconfig"
nfpm pkg --config "$tmpconfig" --packager rpm --target dist/
rm -f "$tmpconfig"
local rpm_arch
rpm_arch="$(rpm_arch_for "$arch")"
RPM_FILE=$(ls dist/lab-*.${rpm_arch}.rpm 2>/dev/null | head -1)
echo "==> Built: $RPM_FILE"
echo " Size: $(du -h "$RPM_FILE" | cut -f1)"
echo ""
echo "==> Packaging DEB (${arch})..."
local deb_arch
deb_arch="$(deb_arch_for "$arch")"
tmpconfig="$(mktemp /tmp/nfpm-XXXXXX.yaml)"
sed -e "s|^arch:.*|arch: ${nfpm_arch}|" \
-e "s|src: ./dist/lab$|src: ./${binary_name}|" \
nfpm.yaml > "$tmpconfig"
nfpm pkg --config "$tmpconfig" --packager deb --target dist/
rm -f "$tmpconfig"
DEB_FILE=$(ls dist/lab_*_${deb_arch}.deb 2>/dev/null | head -1)
echo "==> Built: $DEB_FILE"
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"
}
# ── Main ──────────────────────────────────────────────────────────
if [ "$SKIP_TESTS" = false ]; then
echo "==> Running unit tests..." echo "==> Running unit tests..."
pnpm test:run pnpm test:run
echo "" echo ""
fi
echo "==> Building TypeScript..." echo "==> Building TypeScript..."
pnpm build pnpm build
@@ -23,25 +161,20 @@ pnpm build
echo "==> Generating shell completions..." echo "==> Generating shell completions..."
pnpm completions:generate pnpm completions:generate
echo "==> Bundling standalone binary..."
mkdir -p dist mkdir -p dist
rm -f dist/lab dist/lab-*.rpm dist/lab*.deb rm -f dist/lab dist/lab-x86_64 dist/lab-arm64 dist/lab-*.rpm dist/lab*.deb
bun build src/cli/src/index.ts --compile --outfile dist/lab if [ "$BUILD_ALL" = true ]; then
build_arch "x86_64"
echo "==> Packaging RPM..." build_arch "arm64"
nfpm pkg --packager rpm --target dist/ elif [ -n "$TARGET_ARCH" ]; then
build_arch "$TARGET_ARCH"
RPM_FILE=$(ls dist/lab-*.rpm 2>/dev/null | head -1) else
echo "==> Built: $RPM_FILE" # Default to host architecture
echo " Size: $(du -h "$RPM_FILE" | cut -f1)" HOST_ARCH="$(detect_host_arch)"
rpm -qpi "$RPM_FILE" build_arch "$HOST_ARCH"
fi
echo "" echo ""
echo "==> Packaging DEB..." echo "==> Build complete. Artifacts in dist/:"
rm -f dist/lab*.deb ls -lh dist/lab* 2>/dev/null || echo " (none)"
nfpm pkg --packager deb --target dist/
DEB_FILE=$(ls dist/lab*.deb 2>/dev/null | head -1)
echo "==> Built: $DEB_FILE"
echo " Size: $(du -h "$DEB_FILE" | cut -f1)"

View File

@@ -13,8 +13,8 @@ fi
echo "=== lab-bastion release ===" echo "=== lab-bastion release ==="
echo "" echo ""
# 1. Build binaries & packages # 1. Build binaries & packages (both architectures)
bash scripts/build-rpm.sh bash scripts/build-rpm.sh --all
echo "" echo ""