41 lines
1.3 KiB
Bash
Executable File
41 lines
1.3 KiB
Bash
Executable File
#!/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!"
|