From 3e611621d63b6c6a34009cecc9daaa6209ab7617 Mon Sep 17 00:00:00 2001 From: Stefano Fiorini Date: Sun, 8 Mar 2026 20:56:17 -0500 Subject: [PATCH] Make portainer skill use portable config paths --- docs/portainer.md | 5 ++-- skills/portainer/SKILL.md | 2 +- skills/portainer/scripts/get-endpoint-id.sh | 23 +++++++++++++++++-- skills/portainer/scripts/get-stack-compose.sh | 23 +++++++++++++++++-- skills/portainer/scripts/get-stack-env.sh | 23 +++++++++++++++++-- skills/portainer/scripts/get-stack-id.sh | 23 +++++++++++++++++-- skills/portainer/scripts/get-stack-status.sh | 23 +++++++++++++++++-- skills/portainer/scripts/list-stacks.sh | 21 ++++++++++++++++- .../portainer/scripts/prune-stack-images.sh | 23 +++++++++++++++++-- skills/portainer/scripts/restart-stack.sh | 23 +++++++++++++++++-- skills/portainer/scripts/start-stack.sh | 23 +++++++++++++++++-- skills/portainer/scripts/stop-stack.sh | 23 +++++++++++++++++-- skills/portainer/scripts/update-stack.sh | 23 +++++++++++++++++-- 13 files changed, 234 insertions(+), 24 deletions(-) diff --git a/docs/portainer.md b/docs/portainer.md index c765a35..2db8928 100644 --- a/docs/portainer.md +++ b/docs/portainer.md @@ -10,8 +10,9 @@ This skill provides a comprehensive set of commands for managing Portainer Docke ### Auth Configuration -Create a config file at: +Create a config file at one of these locations: ``` +workspace/.clawdbot/credentials/portainer/config.json ~/.clawdbot/credentials/portainer/config.json ``` @@ -152,7 +153,7 @@ All scripts: - Print results to stdout Common errors: -- **Missing config file**: Create the auth configuration file +- **Missing config file**: Create the auth configuration file in the workspace `.clawdbot/credentials/portainer/` path or in `~/.clawdbot/credentials/portainer/` - **Invalid API key**: Generate a new API key in Portainer - **Stack not found**: Check the stack name with `list-stacks.sh` - **504 Gateway Timeout**: The operation is still running in the background; wait and then run the prune command diff --git a/skills/portainer/SKILL.md b/skills/portainer/SKILL.md index c5734ac..22e58a9 100644 --- a/skills/portainer/SKILL.md +++ b/skills/portainer/SKILL.md @@ -9,7 +9,7 @@ Manage Portainer stacks via API. All stack commands accept names and resolve IDs ## Required auth config -`/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json` +`workspace .clawdbot/credentials/portainer/config.json (preferred) or ~/.clawdbot/credentials/portainer/config.json` ```json { diff --git a/skills/portainer/scripts/get-endpoint-id.sh b/skills/portainer/scripts/get-endpoint-id.sh index 2c3c3c9..f3d8964 100755 --- a/skills/portainer/scripts/get-endpoint-id.sh +++ b/skills/portainer/scripts/get-endpoint-id.sh @@ -1,7 +1,26 @@ #!/usr/bin/env bash set -euo pipefail -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -18,7 +37,7 @@ Usage: get-endpoint-id.sh "" Looks up a Portainer endpoint (environment) by exact name and prints its ID. Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/get-stack-compose.sh b/skills/portainer/scripts/get-stack-compose.sh index ff31e9c..894f9a8 100755 --- a/skills/portainer/scripts/get-stack-compose.sh +++ b/skills/portainer/scripts/get-stack-compose.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -19,7 +38,7 @@ Usage: get-stack-compose.sh "" Gets the docker-compose.yml content for a Portainer stack by name. Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/get-stack-env.sh b/skills/portainer/scripts/get-stack-env.sh index 2220be2..6485061 100755 --- a/skills/portainer/scripts/get-stack-env.sh +++ b/skills/portainer/scripts/get-stack-env.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -20,7 +39,7 @@ Usage: get-stack-env.sh "" Gets environment variables for a Portainer stack by name (resolves ID automatically). Outputs JSON array of {name, value} objects. Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/get-stack-id.sh b/skills/portainer/scripts/get-stack-id.sh index a84e126..36a1ee1 100755 --- a/skills/portainer/scripts/get-stack-id.sh +++ b/skills/portainer/scripts/get-stack-id.sh @@ -1,7 +1,26 @@ #!/usr/bin/env bash set -euo pipefail -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -18,7 +37,7 @@ Usage: get-stack-id.sh "" Looks up a Portainer stack by exact name and prints its ID. Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/get-stack-status.sh b/skills/portainer/scripts/get-stack-status.sh index 424b1a2..7e343de 100755 --- a/skills/portainer/scripts/get-stack-status.sh +++ b/skills/portainer/scripts/get-stack-status.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -19,7 +38,7 @@ Usage: get-stack-status.sh "" Gets detailed status for a Portainer stack by name (resolves ID automatically). Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/list-stacks.sh b/skills/portainer/scripts/list-stacks.sh index 364b8d8..b26b504 100755 --- a/skills/portainer/scripts/list-stacks.sh +++ b/skills/portainer/scripts/list-stacks.sh @@ -1,7 +1,26 @@ #!/usr/bin/env bash set -euo pipefail -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 diff --git a/skills/portainer/scripts/prune-stack-images.sh b/skills/portainer/scripts/prune-stack-images.sh index 92742ac..1d08217 100755 --- a/skills/portainer/scripts/prune-stack-images.sh +++ b/skills/portainer/scripts/prune-stack-images.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -21,7 +40,7 @@ Removes unused images that were previously associated with a stack. Run this after an update-stack --pull completes to clean up old image versions. Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/restart-stack.sh b/skills/portainer/scripts/restart-stack.sh index 341bbc6..8189885 100755 --- a/skills/portainer/scripts/restart-stack.sh +++ b/skills/portainer/scripts/restart-stack.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -19,7 +38,7 @@ Usage: restart-stack.sh "" Restarts a Portainer stack by name (resolves ID automatically). Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/start-stack.sh b/skills/portainer/scripts/start-stack.sh index fa99a5a..b158ee5 100755 --- a/skills/portainer/scripts/start-stack.sh +++ b/skills/portainer/scripts/start-stack.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -19,7 +38,7 @@ Usage: start-stack.sh "" Starts a Portainer stack by name (resolves ID automatically). Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/stop-stack.sh b/skills/portainer/scripts/stop-stack.sh index 21f5903..81fde0e 100755 --- a/skills/portainer/scripts/stop-stack.sh +++ b/skills/portainer/scripts/stop-stack.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -19,7 +38,7 @@ Usage: stop-stack.sh "" Stops a Portainer stack by name (resolves ID automatically). Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 } diff --git a/skills/portainer/scripts/update-stack.sh b/skills/portainer/scripts/update-stack.sh index 2f92c9b..6d4014c 100755 --- a/skills/portainer/scripts/update-stack.sh +++ b/skills/portainer/scripts/update-stack.sh @@ -2,7 +2,26 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -CONFIG_PATH="/home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SEARCH_DIR="$SCRIPT_DIR" +CONFIG_PATH="" + +while true; do + CANDIDATE="$SEARCH_DIR/.clawdbot/credentials/portainer/config.json" + if [[ -f "$CANDIDATE" ]]; then + CONFIG_PATH="$CANDIDATE" + break + fi + PARENT="$(dirname "$SEARCH_DIR")" + if [[ "$PARENT" == "$SEARCH_DIR" ]]; then + break + fi + SEARCH_DIR="$PARENT" +done + +if [[ -z "$CONFIG_PATH" && -f "$HOME/.clawdbot/credentials/portainer/config.json" ]]; then + CONFIG_PATH="$HOME/.clawdbot/credentials/portainer/config.json" +fi err() { echo "Error: $*" >&2 @@ -32,7 +51,7 @@ Options: but are no longer in use (old versions left dangling). Requires config at: - /home/node/.openclaw/workspace/.clawdbot/credentials/portainer/config.json + workspace .clawdbot/credentials/portainer/config.json or ~/.clawdbot/credentials/portainer/config.json EOF exit 2 }