102 lines
3.6 KiB
Plaintext
102 lines
3.6 KiB
Plaintext
![]() |
status:
|
||
|
#!/usr/bin/env bash
|
||
|
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "📊 Running Containers"
|
||
|
docker ps --format "table {{"{{.Names}}\t{{.Status}}"}}" | gum table
|
||
|
|
||
|
# Interactive logs viewer with gum
|
||
|
logs:
|
||
|
#!/usr/bin/env bash
|
||
|
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "📝 Docker Logs Viewer"
|
||
|
|
||
|
# Get running container names
|
||
|
containers=($(docker ps --format "{{"{{.Names}}"}}"))
|
||
|
|
||
|
if [ ${#containers[@]} -eq 0 ]; then
|
||
|
gum style --foreground 1 "⚠️ No running containers found"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Select container using gum choose
|
||
|
container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container:" --cursor.foreground 212)
|
||
|
|
||
|
if [ -z "$container" ]; then
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
# Select number of lines using gum choose
|
||
|
lines=$(gum choose --header "Select number of log lines:" --cursor.foreground 212 \
|
||
|
"5 lines" "10 lines" "25 lines" "50 lines" "100 lines" "200 lines")
|
||
|
|
||
|
if [ -z "$lines" ]; then
|
||
|
exit 0
|
||
|
fi
|
||
|
|
||
|
# Extract number from selection
|
||
|
lines=${lines%% *}
|
||
|
|
||
|
# Show spinner while fetching logs
|
||
|
gum spin --spinner dot --title "Fetching logs..." -- sleep 1
|
||
|
|
||
|
# Show logs
|
||
|
docker logs "$container" 2>&1 | tail -n "$lines" | gum pager
|
||
|
|
||
|
docker-disk:
|
||
|
#!/usr/bin/env bash
|
||
|
gum style --foreground 212 --bold --border normal --align center --width 50 --margin "1 2" "💾 Docker Disk Usage"
|
||
|
docker system df | gum table
|
||
|
|
||
|
docker-restart:
|
||
|
#!/usr/bin/env bash
|
||
|
containers=($(docker ps --format "{{"{{.Names}}"}}"))
|
||
|
if [ ${#containers[@]} -eq 0 ]; then
|
||
|
gum style --foreground 1 "⚠️ No running containers found"
|
||
|
exit 1
|
||
|
fi
|
||
|
container=$(printf "%s\n" "${containers[@]}" | gum choose --header "Select a container to restart:" --cursor.foreground 212)
|
||
|
if [ -n "$container" ]; then
|
||
|
gum spin --spinner dot --title "Restarting $container..." -- docker restart "$container"
|
||
|
gum style --foreground 212 "✅ Container $container restarted successfully!"
|
||
|
fi
|
||
|
|
||
|
update-containers:
|
||
|
#!/usr/bin/env bash
|
||
|
set -e # Exit on error
|
||
|
CONTAINERS=($(docker ps --format "{{"{{.Names}}"}}"))
|
||
|
|
||
|
echo "Will update these containers:"
|
||
|
printf '%s\n' "${CONTAINERS[@]}" | gum table && \
|
||
|
gum confirm "Continue?" || exit 0
|
||
|
|
||
|
# First collect all image information
|
||
|
declare -A CONTAINER_IMAGES
|
||
|
echo "Collecting image information..."
|
||
|
for container in "${CONTAINERS[@]}"; do
|
||
|
FULL_IMAGE=$(docker inspect "$container" --format '{{"{{.Config.Image}}"}}')
|
||
|
CONTAINER_IMAGES[$container]=$(echo "$FULL_IMAGE" | sed 's/@sha256.*$//')
|
||
|
echo "$container -> ${CONTAINER_IMAGES[$container]}"
|
||
|
done
|
||
|
|
||
|
echo "Stopping containers..." && \
|
||
|
for container in "${CONTAINERS[@]}"; do
|
||
|
echo "Stopping $container..."
|
||
|
sudo systemctl stop "docker-$container.service"
|
||
|
done
|
||
|
|
||
|
echo "Pulling new images..." && \
|
||
|
for container in "${CONTAINERS[@]}"; do
|
||
|
IMAGE="${CONTAINER_IMAGES[$container]}"
|
||
|
echo -e "\n📥 Pulling $IMAGE for $container..." | gum style --foreground 99
|
||
|
if ! docker pull "$IMAGE" --quiet=false; then
|
||
|
echo "❌ Failed to pull $IMAGE" | gum style --foreground 196
|
||
|
exit 1
|
||
|
fi
|
||
|
echo "------------------------"
|
||
|
done
|
||
|
|
||
|
echo "Starting containers..." && \
|
||
|
for container in "${CONTAINERS[@]}"; do
|
||
|
echo "Starting $container..."
|
||
|
sudo systemctl start "docker-$container.service"
|
||
|
done && \
|
||
|
gum style --foreground 212 "✅ Containers updated successfully!"
|