Retry CI docker compose startup

This commit is contained in:
Jeppe B
2026-06-02 10:08:01 +02:00
parent ac60596218
commit ee2af5091c
+18 -1
View File
@@ -51,6 +51,23 @@ collect_logs() {
docker compose $compose_files cp php1:/var/log/php "$log_dir/php-logs" >/dev/null 2>&1 || true
}
retry_command() {
max_attempts="$1"
shift
attempt=1
while :; do
"$@" && return 0
status="$?"
if [ "$attempt" -ge "$max_attempts" ]; then
return "$status"
fi
sleep_seconds=$((attempt * 5))
echo "Command failed with status $status; retrying in ${sleep_seconds}s (attempt $((attempt + 1))/$max_attempts): $*" >&2
sleep "$sleep_seconds"
attempt=$((attempt + 1))
done
}
cleanup() {
status="$?"
collect_logs "$status"
@@ -70,7 +87,7 @@ cleanup() {
}
trap cleanup EXIT INT TERM
docker compose $compose_files up -d redis mysql-debug php1
retry_command "${PHP_CI_DOCKER_RETRIES:-3}" docker compose $compose_files up -d redis mysql-debug php1
docker compose $compose_files exec -T php1 sh -lc '
set -eu