Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/scripts/smoke-test-deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────────────
# DEB Package Installation Test for Devolutions Gateway
#
# Runs inside an Ubuntu container to validate:
# - Package installs correctly via apt-get
# - Expected files and directories are present
# - Binary is functional (--help, --config-init-only)
# - systemd unit file is installed (part of the .deb package)
# - Default configuration file is generated
#
# Environment variables (required):
# PACKAGE_FILE Absolute path to the .deb file inside the container.
# VERSION Expected package version (e.g. 2026.1.0).
# PACKAGE_NAME Package name (e.g. devolutions-gateway).
#
# LIMITATION — systemd in containers:
# Docker containers do not normally run systemd, so the postinst script
# skips config initialization and service enablement (both gated on
# /run/systemd/system). This script compensates by running
# --config-init-only manually. Full service start/stop validation is
# best-effort and only attempted when systemd is detected.
# ──────────────────────────────────────────────────────────────────────────────

set -euo pipefail

# ── Validate environment ──────────────────────────────────────────────────────

: "${PACKAGE_FILE:?PACKAGE_FILE must be set}"
: "${VERSION:?VERSION must be set}"
: "${PACKAGE_NAME:?PACKAGE_NAME must be set}"

# ── Constants ─────────────────────────────────────────────────────────────────

BINARY=/usr/bin/devolutions-gateway
LIB_DIR=/usr/lib/devolutions-gateway
LIB_PATH=$LIB_DIR/libxmf.so
WEBAPP_DIR=/usr/share/devolutions-gateway/webapp
CONFIG_DIR=/etc/devolutions-gateway
CONFIG_FILE=$CONFIG_DIR/gateway.json

# The .deb package installs the unit file via dh_installsystemd.
UNIT_FILE_PATHS=(
/lib/systemd/system/devolutions-gateway.service
/usr/lib/systemd/system/devolutions-gateway.service
)

# The library is in a non-standard path; cover the LD_LIBRARY_PATH lookup
# case in addition to RPATH or env-var-based resolution the binary may use.
export LD_LIBRARY_PATH="$LIB_DIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"

# ── Source shared library ─────────────────────────────────────────────────────

# shellcheck source=smoke-test-lib.sh
source "$(dirname "${BASH_SOURCE[0]}")/smoke-test-lib.sh"

# ── Diagnostics (deb-specific) ────────────────────────────────────────────────

diagnostics() {
echo ""
echo "── Diagnostics ──────────────────────────────────────────────"
echo ""
echo "Package metadata:"
dpkg -s "$PACKAGE_NAME" 2>/dev/null || echo " (not installed)"
echo ""
echo "Package file list:"
dpkg -L "$PACKAGE_NAME" 2>/dev/null || echo " (not installed)"
echo ""
echo "Config directory:"
ls -la "$CONFIG_DIR/" 2>/dev/null || echo " (not found)"
echo ""
echo "Binary info:"
ls -la "$BINARY" 2>/dev/null || echo " (not found)"
file "$BINARY" 2>/dev/null || true
echo ""
echo "Dynamic library dependencies (ldd):"
ldd "$BINARY" 2>/dev/null || echo " (ldd failed or binary not found)"
echo ""
echo "Webapp directory:"
ls -laR "$WEBAPP_DIR/" 2>/dev/null | head -40 || echo " (not found)"
echo ""
echo "Library directory:"
ls -la "$LIB_DIR/" 2>/dev/null || echo " (not found)"
echo ""
echo "systemd unit files:"
UNIT_FILES=$(find /lib/systemd /usr/lib/systemd /etc/systemd -name '*devolutions*' 2>/dev/null || true)
if [ -n "$UNIT_FILES" ]; then echo "$UNIT_FILES"; else echo " (none found)"; fi
echo "────────────────────────────────────────────────────────────"
}

# ── Main ══════════════════════════════════════════════════════════════════════

echo "════════════════════════════════════════════════════════════════"
echo " DEB Package Installation Test"
echo " Package: $(basename "$PACKAGE_FILE")"
echo " Version: $VERSION"
echo " Container: $(grep PRETTY_NAME /etc/os-release 2>/dev/null | cut -d= -f2 | tr -d '"' || echo unknown)"
echo "════════════════════════════════════════════════════════════════"
echo ""

# ── Install ───────────────────────────────────────────────────────────────────

info "Updating apt and installing prerequisites…"
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
PREREQ_LOG=$(mktemp)
if apt-get install -y -qq file python3 > "$PREREQ_LOG" 2>&1; then
rm -f "$PREREQ_LOG"
else
echo "Prerequisites installation output:"
cat "$PREREQ_LOG"
rm -f "$PREREQ_LOG"
fail "Prerequisites installation failed (file, python3)"
diagnostics
summary
fi

info "Installing package: $(basename "$PACKAGE_FILE")"
# apt-get resolves dependencies automatically and supports local .deb paths.
# The package declares Depends: libc6 (>= 2.27); Ubuntu 18.04 provides 2.27.
INSTALL_LOG=$(mktemp)
if apt-get install -y "$PACKAGE_FILE" > "$INSTALL_LOG" 2>&1; then
pass "Package installation succeeded"
else
echo "Installation output:"
cat "$INSTALL_LOG"
fail "Package installation failed"
diagnostics
summary
fi
rm -f "$INSTALL_LOG"

# ── Package metadata ──────────────────────────────────────────────────────────

info "Checking package metadata…"
INSTALLED_VERSION=$(dpkg -s "$PACKAGE_NAME" 2>/dev/null | grep '^Version:' | awk '{print $2}')
if echo "$INSTALLED_VERSION" | grep -q "$VERSION"; then
pass "Installed version ($INSTALLED_VERSION) contains expected version ($VERSION)"
else
fail "Version mismatch: installed=$INSTALLED_VERSION expected contains=$VERSION"
fi

# ── File existence ────────────────────────────────────────────────────────────

info "Checking expected files and directories…"
check_binary_executable
check_native_library
check_webapp
check_config_dir

# ── Binary functionality ──────────────────────────────────────────────────────

info "Checking binary functionality…"
check_binary_help

# ── Config initialization ─────────────────────────────────────────────────────
# The postinst runs --config-init-only only when systemd is present.
# In a container without systemd we run it manually.

info "Checking config initialization…"
check_config_init

# ── systemd unit file ─────────────────────────────────────────────────────────
# The .deb package installs the unit file via dh_installsystemd,
# so it must be present regardless of whether systemd is running.

info "Checking systemd unit file…"
check_unit_file "fail"

# ── Service startup (best-effort) ─────────────────────────────────────────────

check_service_startup

# ── Final output ──────────────────────────────────────────────────────────────

diagnostics
summary
158 changes: 158 additions & 0 deletions .github/scripts/smoke-test-lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────────────
# Shared library for Devolutions Gateway Linux packaging smoke tests.
# Sourced by smoke-test-deb.sh and smoke-test-rpm.sh.
#
# Expects the following constants to be defined in the sourcing script
# before any check function is called:
# BINARY Path to the gateway binary.
# LIB_DIR Directory containing native libraries.
# LIB_PATH Path to libxmf.so.
# WEBAPP_DIR Path to the webapp root directory.
# CONFIG_DIR Path to the config directory.
# CONFIG_FILE Path to gateway.json.
# UNIT_FILE_PATHS Array of candidate systemd unit file paths (in priority order).
# ──────────────────────────────────────────────────────────────────────────────

# ── Test bookkeeping ──────────────────────────────────────────────────────────

TESTS_PASSED=0
TESTS_FAILED=0

pass() { echo "✅ PASS: $1"; TESTS_PASSED=$((TESTS_PASSED + 1)); }
fail() { echo "❌ FAIL: $1" >&2; TESTS_FAILED=$((TESTS_FAILED + 1)); }
info() { echo "ℹ️ $1"; }
warn() { echo "⚠️ WARN: $1"; }

# ── Summary ───────────────────────────────────────────────────────────────────

summary() {
echo ""
echo "════════════════════════════════════════════════════════════════"
echo " Test Summary: $TESTS_PASSED passed, $TESTS_FAILED failed"
echo "════════════════════════════════════════════════════════════════"
if [ "$TESTS_FAILED" -gt 0 ]; then
exit 1
fi
}

# ── Check functions ───────────────────────────────────────────────────────────

check_binary_executable() {
if [ -x "$BINARY" ]; then
pass "Main binary exists and is executable: $BINARY"
else
fail "Main binary missing or not executable: $BINARY"
fi
}

check_native_library() {
if [ -f "$LIB_PATH" ] && file "$LIB_PATH" 2>/dev/null | grep -q 'ELF'; then
pass "Native library exists and is a valid ELF: $LIB_PATH"
else
fail "Native library missing or not a valid ELF: $LIB_PATH"
fi
}

check_webapp() {
if [ -d "$WEBAPP_DIR" ]; then
pass "Webapp directory exists: $WEBAPP_DIR"
else
fail "Webapp directory missing: $WEBAPP_DIR"
fi
for app in client player; do
if find "$WEBAPP_DIR/$app" -name 'index.html' 2>/dev/null | grep -q .; then
pass "Webapp $app contains index.html"
else
fail "Webapp $app missing index.html"
fi
done
}

check_config_dir() {
if [ -d "$CONFIG_DIR" ]; then
pass "Config directory exists: $CONFIG_DIR"
else
fail "Config directory missing: $CONFIG_DIR"
fi
}

check_binary_help() {
HELP_OUTPUT=$("$BINARY" --help 2>&1) && HELP_RC=$? || HELP_RC=$?
if [ "$HELP_RC" -eq 0 ] || echo "$HELP_OUTPUT" | grep -qi 'gateway\|usage\|help'; then
pass "Binary responds to --help"
else
fail "Binary does not respond to --help (exit code: $HELP_RC)"
fi
}

check_config_init() {
if [ ! -f "$CONFIG_FILE" ]; then
info "Config file not generated by postinst (expected without systemd)."
info "Running config initialization manually…"
CONFIG_INIT_LOG=$(mktemp)
if "$BINARY" --config-init-only > "$CONFIG_INIT_LOG" 2>&1; then
pass "Config initialization command succeeded"
else
echo "config-init-only output:"
cat "$CONFIG_INIT_LOG"
fail "Config initialization command failed"
fi
rm -f "$CONFIG_INIT_LOG"
fi

if [ -f "$CONFIG_FILE" ]; then
pass "Default config file exists: $CONFIG_FILE"
if python3 -c "import json; json.load(open('$CONFIG_FILE'))" 2>/dev/null; then
pass "$(basename "$CONFIG_FILE") is valid JSON"
else
fail "$(basename "$CONFIG_FILE") exists but is not valid JSON"
fi
else
fail "Default config file missing after initialization: $CONFIG_FILE"
fi
}

# Usage: check_unit_file <fail|warn>
# Searches UNIT_FILE_PATHS in order; on absence, either fails or warns.
check_unit_file() {
local on_absent="$1"
local unit_file=""
for path in "${UNIT_FILE_PATHS[@]}"; do
if [ -f "$path" ]; then
unit_file="$path"
break
fi
done

if [ -n "$unit_file" ]; then
pass "systemd unit file exists: $unit_file"
if grep -q "$BINARY" "$unit_file"; then
pass "Unit file references correct binary path"
else
fail "Unit file does not reference $BINARY"
fi
elif [ "$on_absent" = "fail" ]; then
fail "systemd unit file not found"
else
warn "systemd unit file not found after registration attempt."
info "This is expected in container environments without systemd."
fi
}

check_service_startup() {
info "[Best-effort] Checking service startup…"
warn "systemd service startup testing is best-effort in containers."
warn "Full service validation requires a real systemd environment."
if [ -d /run/systemd/system ]; then
info "systemd detected; attempting service start…"
if systemctl start devolutions-gateway 2>&1; then
pass "[Best-effort] Service started successfully"
systemctl status devolutions-gateway 2>&1 || true
else
warn "Service start failed (expected in some container environments)."
fi
else
info "No systemd detected; skipping service startup test."
fi
}
Loading
Loading