diff --git a/.zshrc b/.zshrc index 6cbc2c3..6055c7b 100644 --- a/.zshrc +++ b/.zshrc @@ -173,7 +173,32 @@ __docker__() { alias dcs="docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'" alias dl="docker compose logs -f" alias dc="docker compose" - alias appupdate="docker compose pull && docker compose up -d --force-recreate" + check_for_updates() { + local updated=false + local images=$(docker compose config | grep 'image:' | awk '{print $2}') + + for image in $images; do + echo -e "${CYAN}Checking for updates for image: ${YELLOW}$image${NC}" + local local_digest=$(docker image inspect "$image" --format '{{index .RepoDigests 0}}' 2>/dev/null) + local remote_digest=$(docker pull --quiet --dry-run "$image" 2>/dev/null | grep 'Digest:' | awk '{print $2}') + + if [[ "$local_digest" != "$remote_digest" ]]; then + echo -e "${GREEN}Update available for $image${NC}" + updated=true + else + echo -e "${YELLOW}No update available for $image${NC}" + fi + done + + if $updated; then + echo -e "${CYAN}Pulling updates and recreating containers...${NC}" + docker compose pull && docker compose up -d --force-recreate + else + echo -e "${GREEN}All images are up to date. No action needed.${NC}" + fi + } + + alias appupdate="check_for_updates" } __git__() {