SwarmCLI modules reference for developers.
bin/
βββ swarm.sh # Entry point
βββ lib/
βββ core.sh # Core: logging, retry
βββ args.sh # Argument parsing
βββ router.sh # Command routing
βββ profiles.sh # Profile operations
βββ yaml.sh # YAML parser
βββ signals.sh # Graceful shutdown
βββ git.sh # Git operations
βββ docker.sh # Docker build/prune
βββ deploy.sh # Deploy, rollback
βββ locks.sh # Locks
βββ secrets.sh # Secrets
βββ commands.sh # CLI commands
βββ validation.sh # Validation
βββ generator.sh # Stack generation
βββ plugins.sh # Plugins
βββ registry.sh # Service registry
βββ wizard.sh # Interactive wizard
βββ dependencies.sh # Dependency check
βββ templates.sh # Bash wrapper for Jinja2 templating
βββ templates.py # Jinja2 templating (Python)
Size: ~260 lines
Functions:
logβ loggingfailβ error with exitwith_spinnerβ animated spinnerretry_with_backoffβ retry with exponential backoffsafe_load_envβ safe .env loading
Size: ~400 lines
Functions:
load_profileβ load profilelist_profilesβ list profilesprofile_existsβ check existenceget_profile_configβ get value from config.yamlsave_default_profileβ save default profileload_default_profileβ load default profilecmd_useβ profile management command
Size: ~120 lines
Functions:
parse_global_argsβ parse global flagsresolve_and_load_profileβ resolve and load profile
Size: ~260 lines
Functions:
resolve_command_aliasβ command aliases (dβdeploy, bβbuild)show_helpβ display helpselect_stack_interactiveβ interactive stack selectionroute_commandβ main command router
Size: ~750 lines
Description: Built-in Bash YAML parser (requires Bash 4.0+). jq required for JSON output.
Functions:
yaml_getβ get valueyaml_get_keysβ get keysget_services_listβ service listget_service_fieldβ service fielditer_variables_yamlβ iterate over variables.yaml
Size: ~320 lines
Description: Graceful shutdown and signal handling module. Solves: zombie processes after Ctrl+C, stuck builds, incomplete cleanup.
Configuration:
GRACEFUL_SHUTDOWN_TIMEOUT=10 # Wait before SIGKILL (sec)
SIGNAL_DEBUG=1 # Signal handling debugFunctions:
init_signal_handlersβ initialize INT/TERM handlersregister_child_pidβ register child process for terminationunregister_child_pidβ unregisterregister_cleanup_handlerβ register cleanup functionset_operation_contextβ set operation context (for logs)run_trackedβ run command with trackingrun_with_graceful_timeoutβ run with timeout and graceful shutdownrun_docker_build_trackedβ docker build with timeout
Shutdown order:
- SIGTERM to all child processes
- Wait
GRACEFUL_SHUTDOWN_TIMEOUTseconds - SIGKILL to remaining processes
- Run cleanup handlers (LIFO)
- Exit with appropriate code
Size: ~150 lines
Functions:
sync_repo_for_serviceβ clone/update repoget_service_commit_shaβ get SHAget_service_current_branchβ current branch
Size: ~200 lines
Functions:
build_for_serviceβ build imagesmart_prune_stack_imagesβ clean old imagesget_service_replicas_statusβ replica status
Size: ~770 lines
Functions:
save_deploy_checkpointβ save checkpointsave_deploy_historyβ save historyrollback_deployβ rollbackrun_hookβ run hookexport_service_tagsβ export TAG_*generate_compose_with_resourcesβ generate compose with resourceswait_for_services_readyβ wait for readinessvalidate_deploy_prerequisitesβ validation
Size: ~80 lines
Functions:
acquire_deploy_lockβ acquire lockrelease_deploy_lockβ releaselist_active_locksβ list activeforce_release_deploy_lockβ force release
Size: ~150 lines
Functions:
secrets_syncβ sync secretscheck_required_secretsβ check requiredsecret_existsβ check existencecmd_secret_createβ create secret
Size: ~400 lines
Functions:
cmd_deployβ deploycmd_buildβ buildcmd_rollbackβ rollbackcmd_repos_syncβ repo syncget_changed_stacksβ changed stacks
Size: ~100 lines
Functions:
validate_services_yamlβ validate services.yamlvalidate_service_branchesβ validate service branchesvalidate_service_referencesβ validate SERVICE_*
graph TD
swarm.sh --> core.sh
swarm.sh --> args.sh
swarm.sh --> router.sh
swarm.sh --> profiles.sh
swarm.sh --> yaml.sh
swarm.sh --> signals.sh
swarm.sh --> commands.sh
args.sh --> profiles.sh
router.sh --> commands.sh
profiles.sh --> yaml.sh
commands.sh --> deploy.sh
commands.sh --> git.sh
commands.sh --> docker.sh
deploy.sh --> yaml.sh
deploy.sh --> locks.sh
deploy.sh --> signals.sh
deploy.sh --> templates.sh
docker.sh --> core.sh
docker.sh --> signals.sh
git.sh --> core.sh
- Create file in
bin/lib/:
#!/usr/bin/env bash
# my_module.sh - Description
my_function() {
local arg="$1"
# ...
}- Include in
swarm.sh:
. "$LIB_DIR/my_module.sh"- Local variables:
local var="value" - Functions:
function_name() { ... } - Checks:
[ -f "$file" ] - Errors:
fail "message"
- Functions:
lower_snake_case - Variables:
UPPER_SNAKE_CASE - Commands:
cmd_<name>
- tech-stack.md β tech stack