Parse Docker images dynamically from docker-compose files

Replace hardcoded image pulls (postgres:15-alpine, redis:7-alpine,
coolify-realtime:1.0.10) with dynamic extraction using
`docker compose config --images`. This ensures the upgrade script
automatically handles new services and version changes without
manual updates.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai 2025-12-13 22:12:33 +01:00
parent 20a9855c04
commit c6945c86ea

View file

@ -59,6 +59,30 @@ curl -fsSL -L $CDN/.env.production -o /data/coolify/source/.env.production
log "Configuration files downloaded successfully" log "Configuration files downloaded successfully"
echo " Done." echo " Done."
# Extract all images from docker-compose configuration
log "Extracting all images from docker-compose configuration..."
COMPOSE_FILES="-f /data/coolify/source/docker-compose.yml -f /data/coolify/source/docker-compose.prod.yml"
# Check if custom compose file exists
if [ -f /data/coolify/source/docker-compose.custom.yml ]; then
COMPOSE_FILES="$COMPOSE_FILES -f /data/coolify/source/docker-compose.custom.yml"
log "Including custom docker-compose.yml in image extraction"
fi
# Get all unique images from docker compose config
# LATEST_IMAGE env var is needed for image substitution in compose files
IMAGES=$(LATEST_IMAGE=${LATEST_IMAGE} docker compose --env-file "$ENV_FILE" $COMPOSE_FILES config --images 2>/dev/null | sort -u)
if [ -z "$IMAGES" ]; then
log "ERROR: Failed to extract images from docker-compose files"
write_status "error" "Failed to parse docker-compose configuration"
echo " ERROR: Failed to parse docker-compose configuration. Aborting upgrade."
exit 1
fi
log "Images to pull:"
echo "$IMAGES" | while read img; do log " - $img"; done
# Backup existing .env file before making any changes # Backup existing .env file before making any changes
if [ "$SKIP_BACKUP" != "true" ]; then if [ "$SKIP_BACKUP" != "true" ]; then
if [ -f "$ENV_FILE" ]; then if [ -f "$ENV_FILE" ]; then
@ -130,60 +154,35 @@ echo ""
echo "3/6 Pulling Docker images..." echo "3/6 Pulling Docker images..."
echo " This may take a few minutes depending on your connection." echo " This may take a few minutes depending on your connection."
echo " - Pulling Coolify image..." # Also pull the helper image (not in compose files but needed for upgrade)
log "Pulling image: ${REGISTRY_URL:-ghcr.io}/coollabsio/coolify:${LATEST_IMAGE}" HELPER_IMAGE="${REGISTRY_URL:-ghcr.io}/coollabsio/coolify-helper:${LATEST_HELPER_VERSION}"
if docker pull "${REGISTRY_URL:-ghcr.io}/coollabsio/coolify:${LATEST_IMAGE}" >>"$LOGFILE" 2>&1; then echo " - Pulling $HELPER_IMAGE..."
log "Successfully pulled Coolify image" log "Pulling image: $HELPER_IMAGE"
if docker pull "$HELPER_IMAGE" >>"$LOGFILE" 2>&1; then
log "Successfully pulled $HELPER_IMAGE"
else else
log "ERROR: Failed to pull Coolify image" log "ERROR: Failed to pull $HELPER_IMAGE"
write_status "error" "Failed to pull Coolify image" write_status "error" "Failed to pull $HELPER_IMAGE"
echo " ERROR: Failed to pull Coolify image. Aborting upgrade." echo " ERROR: Failed to pull $HELPER_IMAGE. Aborting upgrade."
exit 1 exit 1
fi fi
echo " - Pulling Coolify helper image..." # Pull all images from compose config
log "Pulling image: ${REGISTRY_URL:-ghcr.io}/coollabsio/coolify-helper:${LATEST_HELPER_VERSION}" # Using a for loop to avoid subshell issues with exit
if docker pull "${REGISTRY_URL:-ghcr.io}/coollabsio/coolify-helper:${LATEST_HELPER_VERSION}" >>"$LOGFILE" 2>&1; then for IMAGE in $IMAGES; do
log "Successfully pulled Coolify helper image" if [ -n "$IMAGE" ]; then
else echo " - Pulling $IMAGE..."
log "ERROR: Failed to pull Coolify helper image" log "Pulling image: $IMAGE"
write_status "error" "Failed to pull Coolify helper image" if docker pull "$IMAGE" >>"$LOGFILE" 2>&1; then
echo " ERROR: Failed to pull helper image. Aborting upgrade." log "Successfully pulled $IMAGE"
exit 1 else
fi log "ERROR: Failed to pull $IMAGE"
write_status "error" "Failed to pull $IMAGE"
echo " - Pulling PostgreSQL image..." echo " ERROR: Failed to pull $IMAGE. Aborting upgrade."
log "Pulling image: postgres:15-alpine" exit 1
if docker pull postgres:15-alpine >>"$LOGFILE" 2>&1; then fi
log "Successfully pulled PostgreSQL image" fi
else done
log "ERROR: Failed to pull PostgreSQL image"
write_status "error" "Failed to pull PostgreSQL image"
echo " ERROR: Failed to pull PostgreSQL image. Aborting upgrade."
exit 1
fi
echo " - Pulling Redis image..."
log "Pulling image: redis:7-alpine"
if docker pull redis:7-alpine >>"$LOGFILE" 2>&1; then
log "Successfully pulled Redis image"
else
log "ERROR: Failed to pull Redis image"
write_status "error" "Failed to pull Redis image"
echo " ERROR: Failed to pull Redis image. Aborting upgrade."
exit 1
fi
echo " - Pulling Coolify realtime image..."
log "Pulling image: ${REGISTRY_URL:-ghcr.io}/coollabsio/coolify-realtime:1.0.10"
if docker pull "${REGISTRY_URL:-ghcr.io}/coollabsio/coolify-realtime:1.0.10" >>"$LOGFILE" 2>&1; then
log "Successfully pulled Coolify realtime image"
else
log "ERROR: Failed to pull Coolify realtime image"
write_status "error" "Failed to pull Coolify realtime image"
echo " ERROR: Failed to pull realtime image. Aborting upgrade."
exit 1
fi
log "All images pulled successfully" log "All images pulled successfully"
echo " All images pulled successfully." echo " All images pulled successfully."