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() {
|
wait_for_containers_ready() {
|
||||||
local max_wait=180 # 3 минуты максимум
|
local max_wait=300 # 5 минут максимум (увеличено для медленных контейнеров)
|
||||||
local check_interval=5
|
local check_interval=10
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
|
|
||||||
echo "⏳ Waiting for containers to be ready..."
|
echo "⏳ Waiting for containers to be ready..."
|
||||||
|
|
||||||
while [ $elapsed -lt $max_wait ]; do
|
while [ $elapsed -lt $max_wait ]; do
|
||||||
# Проверяем, что все контейнеры запущены (нет Exit или Restarting)
|
# Проверяем, что все контейнеры запущены и здоровы (нет Exit, Restarting, или health: starting)
|
||||||
if docker-compose ps 2>/dev/null | grep -q "Exit\|Restarting"; then
|
local unhealthy=$(docker-compose ps 2>/dev/null | grep -c "Exit\|Restarting\|health: starting" || echo "0")
|
||||||
echo "⏳ Some containers not ready yet, waiting ${check_interval}s... (${elapsed}/${max_wait}s)"
|
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
|
sleep $check_interval
|
||||||
elapsed=$((elapsed + check_interval))
|
elapsed=$((elapsed + check_interval))
|
||||||
else
|
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
|
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
|
return 0
|
||||||
else
|
else
|
||||||
echo "⏳ Waiting for containers to start... (${elapsed}/${max_wait}s)"
|
echo "⏳ Waiting for containers to start... (${elapsed}/${max_wait}s)"
|
||||||
@@ -392,6 +399,7 @@ jobs:
|
|||||||
elapsed=$((elapsed + check_interval))
|
elapsed=$((elapsed + check_interval))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "⚠️ Containers not fully ready after ${max_wait}s, but continuing with health checks..."
|
echo "⚠️ Containers not fully ready after ${max_wait}s, but continuing with health checks..."
|
||||||
@@ -416,8 +424,10 @@ jobs:
|
|||||||
local service=$1
|
local service=$1
|
||||||
local url=$2
|
local url=$2
|
||||||
local attempt=1
|
local attempt=1
|
||||||
local delays=(5 15 45) # Экспоненциальные задержки: 5s, 15s, 45s
|
local delay1=10
|
||||||
local max_attempts=${#delays[@]}
|
local delay2=30
|
||||||
|
local delay3=60
|
||||||
|
local max_attempts=3
|
||||||
|
|
||||||
echo "🔍 Checking $service health..."
|
echo "🔍 Checking $service health..."
|
||||||
|
|
||||||
@@ -427,7 +437,11 @@ jobs:
|
|||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
if [ $attempt -lt $max_attempts ]; then
|
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..."
|
echo "⏳ $service not ready yet (attempt $attempt/$max_attempts), waiting ${delay} seconds..."
|
||||||
sleep $delay
|
sleep $delay
|
||||||
else
|
else
|
||||||
@@ -537,14 +551,13 @@ jobs:
|
|||||||
|
|
||||||
if [ -f "$DEPLOY_HISTORY" ]; then
|
if [ -f "$DEPLOY_HISTORY" ]; then
|
||||||
# Обновляем последнюю запись со статусом deploying на success или failed
|
# Обновляем последнюю запись со статусом deploying на success или failed
|
||||||
|
deploy_status="failed"
|
||||||
if [ "${{ job.status }}" = "success" ]; then
|
if [ "${{ job.status }}" = "success" ]; then
|
||||||
status="success"
|
deploy_status="success"
|
||||||
else
|
|
||||||
status="failed"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Обновляем статус безопасно
|
# Обновляем статус безопасно
|
||||||
safe_update_history_status "$status"
|
safe_update_history_status "$deploy_status"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Send deployment notification
|
- name: Send deployment notification
|
||||||
|
|||||||
Reference in New Issue
Block a user