fix: increase container wait time, fix status variable name, fix delays array for zsh
This commit is contained in:
43
.github/workflows/deploy.yml
vendored
43
.github/workflows/deploy.yml
vendored
@@ -368,23 +368,30 @@ jobs:
|
||||
|
||||
# Адаптивное ожидание готовности контейнеров
|
||||
wait_for_containers_ready() {
|
||||
local max_wait=180 # 3 минуты максимум
|
||||
local check_interval=5
|
||||
local max_wait=300 # 5 минут максимум (увеличено для медленных контейнеров)
|
||||
local check_interval=10
|
||||
local elapsed=0
|
||||
|
||||
echo "⏳ Waiting for containers to be ready..."
|
||||
|
||||
while [ $elapsed -lt $max_wait ]; do
|
||||
# Проверяем, что все контейнеры запущены (нет Exit или Restarting)
|
||||
if docker-compose ps 2>/dev/null | grep -q "Exit\|Restarting"; then
|
||||
echo "⏳ Some containers not ready yet, waiting ${check_interval}s... (${elapsed}/${max_wait}s)"
|
||||
# Проверяем, что все контейнеры запущены и здоровы (нет Exit, Restarting, или health: starting)
|
||||
local unhealthy=$(docker-compose ps 2>/dev/null | grep -c "Exit\|Restarting\|health: starting" || echo "0")
|
||||
if [ "$unhealthy" -gt 0 ]; then
|
||||
echo "⏳ Some containers not ready yet (${unhealthy} still starting), waiting ${check_interval}s... (${elapsed}/${max_wait}s)"
|
||||
sleep $check_interval
|
||||
elapsed=$((elapsed + check_interval))
|
||||
else
|
||||
# Все контейнеры запущены
|
||||
local running_count=$(docker-compose ps 2>/dev/null | grep -c "Up" || echo "0")
|
||||
# Все контейнеры запущены и здоровы
|
||||
local running_count=$(docker-compose ps 2>/dev/null | grep -c "Up.*healthy" || echo "0")
|
||||
if [ "$running_count" -gt 0 ]; then
|
||||
echo "✅ All containers are ready! (waited ${elapsed}s, ${running_count} containers running)"
|
||||
echo "✅ All containers are ready and healthy! (waited ${elapsed}s, ${running_count} containers healthy)"
|
||||
return 0
|
||||
else
|
||||
# Проверяем хотя бы что контейнеры запущены (даже если еще не healthy)
|
||||
local up_count=$(docker-compose ps 2>/dev/null | grep -c "Up" || echo "0")
|
||||
if [ "$up_count" -gt 0 ]; then
|
||||
echo "✅ All containers are up (${up_count} running), continuing with health checks..."
|
||||
return 0
|
||||
else
|
||||
echo "⏳ Waiting for containers to start... (${elapsed}/${max_wait}s)"
|
||||
@@ -392,6 +399,7 @@ jobs:
|
||||
elapsed=$((elapsed + check_interval))
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo "⚠️ Containers not fully ready after ${max_wait}s, but continuing with health checks..."
|
||||
@@ -416,8 +424,10 @@ jobs:
|
||||
local service=$1
|
||||
local url=$2
|
||||
local attempt=1
|
||||
local delays=(5 15 45) # Экспоненциальные задержки: 5s, 15s, 45s
|
||||
local max_attempts=${#delays[@]}
|
||||
local delay1=10
|
||||
local delay2=30
|
||||
local delay3=60
|
||||
local max_attempts=3
|
||||
|
||||
echo "🔍 Checking $service health..."
|
||||
|
||||
@@ -427,7 +437,11 @@ jobs:
|
||||
return 0
|
||||
else
|
||||
if [ $attempt -lt $max_attempts ]; then
|
||||
delay=${delays[$((attempt - 1))]}
|
||||
case $attempt in
|
||||
1) delay=$delay1 ;;
|
||||
2) delay=$delay2 ;;
|
||||
*) delay=$delay3 ;;
|
||||
esac
|
||||
echo "⏳ $service not ready yet (attempt $attempt/$max_attempts), waiting ${delay} seconds..."
|
||||
sleep $delay
|
||||
else
|
||||
@@ -537,14 +551,13 @@ jobs:
|
||||
|
||||
if [ -f "$DEPLOY_HISTORY" ]; then
|
||||
# Обновляем последнюю запись со статусом deploying на success или failed
|
||||
deploy_status="failed"
|
||||
if [ "${{ job.status }}" = "success" ]; then
|
||||
status="success"
|
||||
else
|
||||
status="failed"
|
||||
deploy_status="success"
|
||||
fi
|
||||
|
||||
# Обновляем статус безопасно
|
||||
safe_update_history_status "$status"
|
||||
safe_update_history_status "$deploy_status"
|
||||
fi
|
||||
|
||||
- name: Send deployment notification
|
||||
|
||||
Reference in New Issue
Block a user