sharenet/pip_ready.sh
continuist d09c5926f7
Some checks are pending
CI/CD Pipeline with Ephemeral PiP / test-backend (push) Waiting to run
CI/CD Pipeline with Ephemeral PiP / test-frontend (push) Blocked by required conditions
CI/CD Pipeline with Ephemeral PiP / build-backend (push) Blocked by required conditions
CI/CD Pipeline with Ephemeral PiP / build-frontend (push) Blocked by required conditions
CI/CD Pipeline with Ephemeral PiP / cleanup (push) Blocked by required conditions
Use ephemeral PiP container in the workflow, and make it secure
2025-09-04 21:16:29 -04:00

61 lines
No EOL
1.9 KiB
Bash

#!/bin/bash
set -euo pipefail
# pip_ready.sh - Readiness probe for PiP container
# Checks if the Podman-in-Podman container is ready for CI operations
PIP_CONTAINER_NAME="ci-pip"
MAX_RETRIES=30
RETRY_DELAY=2
# Function to check PiP readiness
check_pip_ready() {
echo "🔍 Checking PiP container readiness..."
# Check if container exists and is running
if ! podman inspect "${PIP_CONTAINER_NAME}" --format '{{.State.Status}}' 2>/dev/null | grep -q running; then
echo "❌ PiP container not running"
return 1
fi
# Test basic Podman command inside PiP
if ! podman exec "${PIP_CONTAINER_NAME}" podman info --format json >/dev/null 2>&1; then
echo "⚠️ PiP container running but Podman not responsive"
return 1
fi
# Test image pulling capability (network test)
if ! podman exec "${PIP_CONTAINER_NAME}" podman pull --quiet alpine:latest >/dev/null 2>&1; then
echo "⚠️ PiP container ready but network access test failed"
return 1
fi
# Clean up test image
podman exec "${PIP_CONTAINER_NAME}" podman rmi alpine:latest 2>/dev/null || true
echo "✅ PiP container ready and fully operational"
return 0
}
# Main readiness check with retries
attempt=1
while [[ ${attempt} -le ${MAX_RETRIES} ]]; do
if check_pip_ready; then
echo "🎉 PiP container is ready for CI operations!"
exit 0
fi
echo "⏳ PiP not ready yet (attempt ${attempt}/${MAX_RETRIES}), retrying in ${RETRY_DELAY}s..."
sleep ${RETRY_DELAY}
attempt=$((attempt + 1))
done
# If we reach here, all retries failed
echo "❌ ERROR: PiP container failed to become ready after ${MAX_RETRIES} attempts"
echo "📋 Container status:"
podman ps -a --filter "name=${PIP_CONTAINER_NAME}" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || true
echo "📋 Container logs:"
podman logs "${PIP_CONTAINER_NAME}" 2>/dev/null || echo "No logs available"
exit 1