Skip to content

Commit

Permalink
Introduce helper script for easier docker API questioning
Browse files Browse the repository at this point in the history
  • Loading branch information
brablc committed Jun 3, 2024
1 parent 34ac257 commit 07796e6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 21 additions & 0 deletions docker-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

url=$1
shift

if (( $# )); then
url="$url?"
fi

while (( $# > 1 )); do
key=$1
value=$2
shift 2
url="${url}$key=$(echo $value | jq -s -R -r @uri)&"
done

if (( $# )); then
url="${url}$1"
fi

curl -s --fail-with-body --unix-socket /var/run/docker.sock "http://v1.45$url"
5 changes: 1 addition & 4 deletions services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
source ./config.sh
source ./logger.sh

sock=/var/run/docker.sock
url=http://v1.45

LABEL="swarm-health-alerter.port"

curl -s --fail-with-body --unix-socket $sock $url/services -o /tmp/services
./docker-api.sh /services > /tmp/services
if [ $? -ne 0 ]; then
log_error "$(jq -r .message /tmp/services 2>/dev/null || cat /tmp/services)"
exit 1
Expand Down

0 comments on commit 07796e6

Please sign in to comment.