Add portainer skill for stack management via API

- 11 scripts for stack lifecycle (start/stop/restart, update, prune)
- Detailed documentation with usage examples and workflow
- Updated README.md files with portainer skill info
This commit is contained in:
Luke
2026-02-12 05:25:44 +00:00
parent 47314f50c9
commit f435487eb0
15 changed files with 1257 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json"
err() {
echo "Error: $*" >&2
exit 1
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || err "Required command not found: $1"
}
usage() {
cat >&2 <<'EOF'
Usage: start-stack.sh "<stack-name>"
Starts a Portainer stack by name (resolves ID automatically).
Requires config at:
/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json
EOF
exit 2
}
[[ $# -eq 1 ]] || usage
STACK_NAME="$1"
require_cmd curl
require_cmd jq
[[ -f "$CONFIG_PATH" ]] || err "Missing config file: $CONFIG_PATH"
BASE_URL="$(jq -r '.base_url // empty' "$CONFIG_PATH")"
API_KEY="$(jq -r '.api_key // empty' "$CONFIG_PATH")"
[[ -n "$BASE_URL" ]] || err "config.base_url is missing"
[[ -n "$API_KEY" ]] || err "config.api_key is missing"
BASE_URL="${BASE_URL%/}"
# Resolve stack ID from name
STACK_ID="$(bash "$SCRIPT_DIR/get-stack-id.sh" "$STACK_NAME")"
[[ -n "$STACK_ID" ]] || err "Failed to resolve stack ID for: $STACK_NAME"
# Get endpoint ID for the stack
STACK_INFO="$(curl -sS -w $'\n%{http_code}' \
-H "X-API-Key: $API_KEY" \
"$BASE_URL/api/stacks/$STACK_ID")"
http_code="$(printf '%s' "$STACK_INFO" | tail -n1)"
body="$(printf '%s' "$STACK_INFO" | sed '$d')"
if [[ "$http_code" -lt 200 || "$http_code" -ge 300 ]]; then
msg="$(printf '%s' "$body" | jq -r '.message // empty' 2>/dev/null || true)"
[[ -n "$msg" ]] || msg="$body"
err "Failed to fetch stack info (HTTP $http_code): $msg"
fi
ENDPOINT_ID="$(printf '%s' "$body" | jq -r '.EndpointId')"
[[ -n "$ENDPOINT_ID" && "$ENDPOINT_ID" != "null" ]] || err "Could not determine endpoint ID for stack"
# Start the stack
response="$(curl -sS -w $'\n%{http_code}' -X POST \
-H "X-API-Key: $API_KEY" \
"$BASE_URL/api/stacks/$STACK_ID/start?endpointId=$ENDPOINT_ID")"
http_code="$(printf '%s' "$response" | tail -n1)"
body="$(printf '%s' "$response" | sed '$d')"
if [[ "$http_code" -lt 200 || "$http_code" -ge 300 ]]; then
msg="$(printf '%s' "$body" | jq -r '.message // empty' 2>/dev/null || true)"
[[ -n "$msg" ]] || msg="$body"
err "Failed to start stack (HTTP $http_code): $msg"
fi
echo "Stack '$STACK_NAME' (ID: $STACK_ID) started successfully"