bin/ 230 CLI tools (ask-*, br-*, agent-*, roadid, carpool) scripts/ 99 automation scripts fleet/ Node configs and deployment workers/ Cloudflare Worker sources (roadpay, road-search, squad webhooks) roadc/ RoadC programming language roadnet/ Mesh network (5 APs, WireGuard) operator/ Memory system scripts config/ System configs dotfiles/ Shell configs docs/ Documentation BlackRoad OS — Pave Tomorrow. RoadChain-SHA2048: d1a24f55318d338b RoadChain-Identity: alexa@sovereign RoadChain-Full: d1a24f55318d338b24b60bad7be39286379c76ae5470817482100cb0ddbbcb97e147d07ac7243da0a9f0363e4e5c833d612b9c0df3a3cd20802465420278ef74875a5b77f55af6fe42a931b8b635b3d0d0b6bde9abf33dc42eea52bc03c951406d8cbe49f1a3d29b26a94dade05e9477f34a7d4d4c6ec4005c3c2ac54e73a68440c512c8e83fd9b1fe234750b898ef8f4032c23db173961fe225e67a0432b5293a9714f76c5c57ed5fdf35b9fb40fd73c03ebf88b7253c6a0575f5afb6a6b49b3bda310602fb1ef676859962dad2aebbb2875814b30eee0a8ba195e482d4cbc91d8819e7f38f6db53e8063401649c77bb994371473cabfb917fb53e8cbe73d60
177 lines
4.7 KiB
Bash
Executable File
177 lines
4.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# br-deploy - BlackRoad OS Deployment Workflow Engine
|
|
# Custom deployment workflows for fleet-wide or per-node deployments
|
|
# Usage: br-deploy <workflow|run|list|create> [args]
|
|
set -euo pipefail
|
|
|
|
source "$HOME/.blackroad/config/nodes.sh" 2>/dev/null || true
|
|
|
|
WORKFLOWS_DIR="$HOME/.blackroad/workflows"
|
|
DEPLOY_LOG="$HOME/.blackroad/logs/deploy.log"
|
|
mkdir -p "$WORKFLOWS_DIR" "$(dirname "$DEPLOY_LOG")"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
${PINK}br-deploy${RESET} - BlackRoad OS Deployment Workflow Engine
|
|
|
|
${BLUE}USAGE:${RESET}
|
|
br-deploy run <workflow> [node] Run a deployment workflow
|
|
br-deploy list List available workflows
|
|
br-deploy create <name> Create a new workflow
|
|
br-deploy status Show last deployment status
|
|
br-deploy rollback <workflow> Rollback last deployment
|
|
|
|
${AMBER}WORKFLOWS:${RESET}
|
|
Workflows are shell scripts in ~/.blackroad/workflows/
|
|
They receive NODE, IP, USER as environment variables.
|
|
Use hooks: pre-deploy, deploy, post-deploy, verify
|
|
|
|
${GREEN}EXAMPLES:${RESET}
|
|
br-deploy run update-ollama cecilia
|
|
br-deploy run sync-configs
|
|
br-deploy create my-workflow
|
|
EOF
|
|
}
|
|
|
|
log_deploy() {
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$DEPLOY_LOG"
|
|
}
|
|
|
|
cmd_list() {
|
|
printf '%b%-24s %s%b\n' "$BLUE" "WORKFLOW" "DESCRIPTION" "$RESET"
|
|
printf '%-24s %s\n' "────────" "───────────"
|
|
for f in "$WORKFLOWS_DIR/"*.sh; do
|
|
[[ -f "$f" ]] || continue
|
|
name=$(basename "$f" .sh)
|
|
desc=$(head -5 "$f" | grep -m1 '^#[^!]' | sed 's/^# *//')
|
|
printf '%-24s %s\n' "$name" "${desc:-—}"
|
|
done
|
|
}
|
|
|
|
cmd_create() {
|
|
local name="$1"
|
|
local wf="$WORKFLOWS_DIR/${name}.sh"
|
|
|
|
if [[ -f "$wf" ]]; then
|
|
echo "Workflow '$name' already exists."
|
|
return 1
|
|
fi
|
|
|
|
cat > "$wf" <<'WORKFLOW'
|
|
#!/bin/bash
|
|
# Custom deployment workflow
|
|
# Receives: $NODE (name), $IP (address), $USER (ssh user), $SSH_TARGET (user@ip)
|
|
set -euo pipefail
|
|
|
|
pre_deploy() {
|
|
echo "Pre-deploy checks on $NODE ($IP)..."
|
|
# Add pre-flight checks here
|
|
# Return non-zero to abort deployment
|
|
}
|
|
|
|
deploy() {
|
|
echo "Deploying to $NODE ($IP)..."
|
|
# Add deployment steps here
|
|
# Example:
|
|
# scp -q ./my-app "$SSH_TARGET:/opt/blackroad/bin/"
|
|
# ssh "$SSH_TARGET" "sudo systemctl restart my-app"
|
|
}
|
|
|
|
post_deploy() {
|
|
echo "Post-deploy verification on $NODE..."
|
|
# Add verification steps here
|
|
}
|
|
|
|
verify() {
|
|
echo "Verifying deployment on $NODE..."
|
|
# Return non-zero if verification fails
|
|
# Example:
|
|
# ssh "$SSH_TARGET" "curl -sf http://localhost:8080/health" || return 1
|
|
}
|
|
|
|
# Workflow execution
|
|
pre_deploy && deploy && post_deploy && verify
|
|
WORKFLOW
|
|
|
|
chmod +x "$wf"
|
|
printf '%bCreated workflow: %s%b\n' "$GREEN" "$wf" "$RESET"
|
|
}
|
|
|
|
cmd_run() {
|
|
local workflow_name="$1"
|
|
local target_node="${2:-}"
|
|
local wf="$WORKFLOWS_DIR/${workflow_name}.sh"
|
|
|
|
if [[ ! -f "$wf" ]]; then
|
|
printf '%bWorkflow %s not found%b\n' "$RED" "$workflow_name" "$RESET"
|
|
return 1
|
|
fi
|
|
|
|
local targets=()
|
|
if [[ -n "$target_node" ]]; then
|
|
targets=("$target_node")
|
|
else
|
|
targets=("${PI_NODES[@]}")
|
|
fi
|
|
|
|
log_deploy "=== DEPLOY START: $workflow_name ==="
|
|
local success=0 fail=0
|
|
|
|
for node in "${targets[@]}"; do
|
|
local ip="${NODE_IP[$node]:-}"
|
|
local user="${NODE_USER[$node]:-}"
|
|
|
|
if [[ -z "$ip" ]]; then
|
|
log_deploy "SKIP $node: unknown node"
|
|
continue
|
|
fi
|
|
|
|
printf '\n%b>>> Deploying %s to %s (%s)%b\n' "$AMBER" "$workflow_name" "$node" "$ip" "$RESET"
|
|
|
|
if ! br_ping "$node" 2>/dev/null; then
|
|
log_deploy "SKIP $node: offline"
|
|
printf '%b %s offline — skipping%b\n' "$RED" "$node" "$RESET"
|
|
((fail++)) || true
|
|
continue
|
|
fi
|
|
|
|
# Export node context for the workflow
|
|
export NODE="$node"
|
|
export IP="$ip"
|
|
export USER="$user"
|
|
export SSH_TARGET="${user}@${ip}"
|
|
|
|
if bash "$wf" 2>&1 | tee -a "$DEPLOY_LOG"; then
|
|
log_deploy "OK $node"
|
|
printf '%b %s: deployed%b\n' "$GREEN" "$node" "$RESET"
|
|
((success++)) || true
|
|
else
|
|
log_deploy "FAIL $node"
|
|
printf '%b %s: FAILED%b\n' "$RED" "$node" "$RESET"
|
|
((fail++)) || true
|
|
fi
|
|
done
|
|
|
|
log_deploy "=== DEPLOY END: $workflow_name (ok=$success fail=$fail) ==="
|
|
printf '\n%bDeployment complete: %d success, %d failed%b\n' "$PINK" "$success" "$fail" "$RESET"
|
|
}
|
|
|
|
cmd_status() {
|
|
if [[ ! -f "$DEPLOY_LOG" ]]; then
|
|
echo "No deployments yet."
|
|
return
|
|
fi
|
|
printf '%bRecent deployments:%b\n' "$BLUE" "$RESET"
|
|
tail -20 "$DEPLOY_LOG"
|
|
}
|
|
|
|
# Main
|
|
case "${1:-}" in
|
|
run) cmd_run "${2:?workflow name required}" "${3:-}" ;;
|
|
list) cmd_list ;;
|
|
create) cmd_create "${2:?workflow name required}" ;;
|
|
status) cmd_status ;;
|
|
-h|--help|help|"") usage ;;
|
|
*) echo "Unknown: $1"; usage; exit 1 ;;
|
|
esac
|