blob: c21391411b1a68ab734b1a7060084629f701a25c [file] [log] [blame]
Philip Zeyliger7b604492025-04-29 11:45:59 -07001#!/usr/bin/env bash
2
3# This script lists all currently running sketch containers in Docker,
4# displaying their container names, local URLs, and sketch titles.
5# It extracts port mappings and queries each sketch's state endpoint
6# to provide a convenient overview of running sketches.
7
8docker ps --format "{{.Names}}|{{.Ports}}" | \
9 grep sketch | \
Philip Zeyligerd5f0a3e2025-06-30 09:38:21 -070010 sed -n -E 's/.*0\.0\.0\.0:([0-9]+)->80.*/\1/p' | \
Philip Zeyliger7b604492025-04-29 11:45:59 -070011 while read port; do
12 # Get container name for this port
13 name=$(docker ps --filter "publish=$port" --format "{{.Names}}")
Philip Zeyligerd5f0a3e2025-06-30 09:38:21 -070014
Philip Zeyliger7b604492025-04-29 11:45:59 -070015 # Get sketch title from its state endpoint
Philip Zeyliger95594bb2025-06-16 08:57:21 -070016 title=$(curl --connect-timeout 1 -s "http://localhost:$port/state" | jq -r '.slug // "N/A"')
17 message_count=$(curl --connect-timeout 1 -s "http://localhost:$port/state" | jq -r '.message_count // "N/A"')
Philip Zeyligerd5f0a3e2025-06-30 09:38:21 -070018
Philip Zeyliger7b604492025-04-29 11:45:59 -070019 # Format and print the result
Philip Zeyliger95594bb2025-06-16 08:57:21 -070020 printf "%-30s http://localhost:%d/ %s %s\n" "$name" "$port" "$title" "$message_count"
Philip Zeyliger7b604492025-04-29 11:45:59 -070021 done