From aae03d9877abb29a71f37ef05db2c8be1f121c9d Mon Sep 17 00:00:00 2001 From: Michal Date: Sun, 29 Mar 2026 00:58:00 +0000 Subject: [PATCH] fix: syslog parser TS strict null check, deploy script Co-Authored-By: Claude Opus 4.6 (1M context) --- bastion/scripts/deploy.sh | 74 +++++++++++++++++++ .../bastion/src/services/syslog-listener.ts | 2 +- 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 bastion/scripts/deploy.sh diff --git a/bastion/scripts/deploy.sh b/bastion/scripts/deploy.sh new file mode 100644 index 0000000..86b6f26 --- /dev/null +++ b/bastion/scripts/deploy.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# Deploy bastion + labd to k3s cluster and install labctl locally. +# Usage: ./scripts/deploy.sh [bastion|labd|labctl|all] +# +# Builds container images with existing build scripts, pushes to Gitea +# registry, restarts k3s pods, and builds/installs labctl RPM. +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" + +cd "$PROJECT_DIR" + +# Load .env if present +if [ -f .env ]; then + set -a; source .env; set +a +fi + +deploy_bastion() { + echo "=== Building & pushing bastion image ===" + bash scripts/build-bastion.sh --push latest + echo "" + echo "=== Restarting bastion pod ===" + kubectl rollout restart deployment/bastion -n lab-infra + kubectl rollout status deployment/bastion -n lab-infra --timeout=180s + echo "✓ Bastion deployed" +} + +deploy_labd() { + echo "=== Building & pushing labd image ===" + bash scripts/build-labd.sh --push latest + echo "" + echo "=== Restarting labd pod ===" + kubectl rollout restart deployment/labd -n lab-system + kubectl rollout status deployment/labd -n lab-system --timeout=180s + echo "✓ Labd deployed" +} + +deploy_labctl() { + echo "=== Building labctl RPM ===" + bash scripts/build-rpm.sh + echo "" + echo "=== Installing labctl ===" + RPM_FILE=$(ls dist/labctl-*.x86_64.rpm 2>/dev/null | head -1) + if [ -n "$RPM_FILE" ]; then + sudo rpm -U --force "$RPM_FILE" + echo "✓ labctl installed: $(labctl --version 2>/dev/null || echo 'installed')" + else + echo "WARNING: No RPM found, falling back to direct install" + pnpm build + sudo install -m 755 <(echo '#!/bin/bash'; echo "exec node $PROJECT_DIR/src/cli/dist/index.js \"\$@\"") /usr/local/bin/labctl + echo "✓ labctl installed (dev mode)" + fi +} + +case "${1:-all}" in + bastion) deploy_bastion ;; + labd) deploy_labd ;; + labctl) deploy_labctl ;; + all) + deploy_bastion + echo "" + deploy_labd + echo "" + deploy_labctl + ;; + *) + echo "Usage: $0 [bastion|labd|labctl|all]" + exit 1 + ;; +esac + +echo "" +echo "=== Deploy complete ===" diff --git a/bastion/src/bastion/src/services/syslog-listener.ts b/bastion/src/bastion/src/services/syslog-listener.ts index 07c384e..1022d6c 100644 --- a/bastion/src/bastion/src/services/syslog-listener.ts +++ b/bastion/src/bastion/src/services/syslog-listener.ts @@ -18,7 +18,7 @@ function parseSyslogLine(raw: string): { program: string; message: string } { // Try to extract program and message after the timestamp + hostname // RFC 3164: "Mon DD HH:MM:SS HOSTNAME PROGRAM[PID]: MESSAGE" const match = noPri.match(/^\w+\s+\d+\s+[\d:]+\s+\S+\s+(\S+?)(?:\[\d+\])?:\s*(.*)/); - if (match) { + if (match?.[1] && match[2] !== undefined) { return { program: match[1], message: match[2] }; } // Fallback: just return the whole line