#!/usr/bin/env bun /** * Print the provision script for Typesense, Postgres and Redis exactly as a * box's first boot runs it (architecture preflight, Pantry bootstrap, then * the services), followed by health checks for each. * * CI runs it as root on an arm64 runner (`.github/workflows/arm64-services.yml`) * so the Graviton path is exercised end to end; it runs the same way on any * disposable Ubuntu 24.04 host: * * bun run scripts/managed-services-smoke.ts > smoke.sh && sudo bash smoke.sh * * Never run it on a machine you care about: it installs and starts services. */ import { randomBytes } from 'node:crypto' import { buildServicesProvisionScript, managedServicePackages } from '../packages/ts-cloud/src/drivers/shared/db-provision' import { buildPantryBootstrapScript, buildPantryPlatformPreflightScript } from '../packages/ts-cloud/src/drivers/shared/package-manager' const services = { typesense: { apiKey: randomBytes(24).toString('hex') }, postgres: true, redis: true, } as const const lines = [ '#!/bin/bash', 'set -euo pipefail', `echo "smoke: $(uname -m), packages: ${managedServicePackages(services).join(' ')}"`, ...buildPantryPlatformPreflightScript(managedServicePackages(services)), ...buildPantryBootstrapScript(), ...buildServicesProvisionScript(services), // Each service answers on its port; Typesense also reports healthy. 'wait_port() { for i in $(seq 1 90); do (exec 3<>"/dev/tcp/127.0.0.1/$1") 2>/dev/null && { echo "smoke: port $1 ($2) answers"; return 0; }; sleep 2; done; echo "smoke: $2 never answered on $1" >&2; return 1; }', 'wait_port 5432 postgres', 'wait_port 6379 redis', 'wait_port 8108 typesense', `curl -fsS http://127.0.0.1:8108/health | grep -q '"ok":true' && echo 'smoke: typesense healthy'`, 'eval "$(cd /opt/pantry && pantry env 2>/dev/null)" || true', 'for bin in typesense-server postgres redis-server; do p=$(command -v "$bin" || true); [ -n "$p" ] && file -L "$p" | sed "s/^/smoke: /"; done', 'echo "smoke: all services up on $(uname -m)"', ] process.stdout.write(`${lines.join('\n')}\n`)