Episode 18: Portainer CE, Arcane, Dockge and Komodo measured next to a running stack
This commit is contained in:
parent
55b2fe7646
commit
76a3132a17
42 changed files with 1639 additions and 0 deletions
42
managers/portainer.sh
Normal file
42
managers/portainer.sh
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
# ep18 Portainer-Messung über die API. Aufruf: portainer.sh init|see|deploy|redeploy|updates|cleanup
|
||||
. /root/ep18/lib.sh; . /root/ep18/testcompose.sh; set -a; . /root/ep18/secrets.env; set +a
|
||||
U=https://127.0.0.1:9443/api
|
||||
J() { curl -sk -H "Authorization: Bearer $(cat /root/ep18/.ptok 2>/dev/null)" "$@"; }
|
||||
case $1 in
|
||||
init)
|
||||
TOK=$(docker logs portainer 2>&1 | grep -o 'setup_token=[^ ]*' | tail -1 | cut -d= -f2)
|
||||
echo '$ POST /api/users/admin/init mit X-Setup-Token aus docker logs'
|
||||
curl -sk -w " HTTP %{http_code}\n" -X POST $U/users/admin/init -H 'Content-Type: application/json' -H "X-Setup-Token: $TOK" -d "{\"Username\":\"opsadmin\",\"Password\":\"$PORTAINER_PW\"}" | sed -E 's/"Password":"[^"]*"/"Password":"REDACTED"/'
|
||||
curl -sk -X POST $U/auth -H 'Content-Type: application/json' -d "{\"Username\":\"opsadmin\",\"Password\":\"$PORTAINER_PW\"}" | jq -r .jwt > /root/ep18/.ptok; chmod 600 /root/ep18/.ptok
|
||||
echo '$ GET /api/endpoints'; J $U/endpoints | jq -c '[.[]|{Id,Name,Type,URL}]'
|
||||
;;
|
||||
see)
|
||||
E=$(J $U/endpoints | jq '.[0].Id'); echo "endpoint id $E"
|
||||
echo '$ GET /api/endpoints/E/docker/containers/json?all=1 (was Portainer sieht)'
|
||||
J "$U/endpoints/$E/docker/containers/json?all=1" | jq -r '.[] | [.Names[0], (.Labels["com.docker.compose.project"] // "-"), .State] | @tsv' | sort | column -t
|
||||
echo "containers seen: $(J "$U/endpoints/$E/docker/containers/json?all=1" | jq length), docker ps -a says: $(docker ps -aq | wc -l)"
|
||||
echo '$ GET /api/stacks (von Portainer verwaltete Stacks)'; J $U/stacks | jq -c '[.[]|{Id,Name,Status}]'
|
||||
;;
|
||||
deploy)
|
||||
E=$(J $U/endpoints | jq '.[0].Id'); D=$(mktemp -d); writetest $D 0
|
||||
echo '$ POST /api/stacks/create/standalone/string name ep18-whoami'
|
||||
T0=$(now); jq -n --rawfile c $D/compose.yaml '{name:"ep18-whoami", stackFileContent:$c, env:[]}' | J -X POST "$U/stacks/create/standalone/string?endpointId=$E" -H 'Content-Type: application/json' -d @- | jq -c '{Id,Name,ProjectPath,EntryPoint,Status}'; echo "API returned after $(el $T0 $(now)) s"
|
||||
T0=$T0 watchrun ep18-whoami 0
|
||||
;;
|
||||
redeploy)
|
||||
E=$(J $U/endpoints | jq '.[0].Id'); S=$(J $U/stacks | jq '.[]|select(.Name=="ep18-whoami")|.Id'); D=$(mktemp -d)
|
||||
for n in 1 2 3; do writetest $D $n
|
||||
echo "\$ PUT /api/stacks/$S (RUN=$n, pullImage false, prune false)"
|
||||
export T0=$(now); jq -n --rawfile c $D/compose.yaml '{stackFileContent:$c, env:[], prune:false, pullImage:false}' | J -X PUT "$U/stacks/$S?endpointId=$E" -H 'Content-Type: application/json' -d @- -o /dev/null -w " HTTP %{http_code}, API returned after %{time_total} s\n"
|
||||
watchrun ep18-whoami $n; sleep 3; done
|
||||
;;
|
||||
updates)
|
||||
E=$(J $U/endpoints | jq '.[0].Id'); S=$(J $U/stacks | jq '.[]|select(.Name=="ep18-whoami")|.Id')
|
||||
echo "\$ GET /api/stacks/$S/images_status?refresh=true"; J "$U/stacks/$S/images_status?refresh=true" -w " HTTP %{http_code}\n"
|
||||
for c in $(docker ps -q --filter label=com.docker.compose.project=ep18-whoami); do n=$(docker inspect -f '{{.Name}} {{.Config.Image}}' $c)
|
||||
echo "\$ GET /api/docker/$E/containers/<id>/image_status?refresh=true $n"; J "$U/docker/$E/containers/$c/image_status?refresh=true" -w " HTTP %{http_code}\n"; done
|
||||
for t in latest v1.11.0 v1.12.0; do echo "registry traefik/whoami:$t = $(regdigest traefik/whoami $t)"; done
|
||||
echo "local traefik/whoami:latest = $(docker image inspect -f '{{.Id}}' traefik/whoami:latest)"
|
||||
;;
|
||||
esac
|
||||
Loading…
Add table
Add a link
Reference in a new issue