diff --git a/.gitea/workflows/production-deploy.yml b/.gitea/workflows/production-deploy.yml index d92ce0c..25fa53f 100644 --- a/.gitea/workflows/production-deploy.yml +++ b/.gitea/workflows/production-deploy.yml @@ -64,29 +64,43 @@ jobs: # Wait for new container to be healthy echo "⏳ Waiting for new container to be healthy..." - for i in {1..60}; do + HEALTH_CHECK_PASSED=false + for i in {1..90}; do NEW_CONTAINER=$(docker ps -q -f name=$CONTAINER_NAME) if [ ! -z "$NEW_CONTAINER" ]; then - # Check health status + # First check HTTP health endpoint (more reliable) + if curl -f -s --max-time 5 http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then + echo "✅ New container is responding to HTTP health check!" + HEALTH_CHECK_PASSED=true + break + fi + # Also check Docker health status as fallback HEALTH=$(docker inspect $NEW_CONTAINER --format='{{.State.Health.Status}}' 2>/dev/null || echo "starting") if [ "$HEALTH" == "healthy" ]; then - echo "✅ New container is healthy!" + echo "✅ New container is healthy (Docker health check)!" + HEALTH_CHECK_PASSED=true break fi - # Also check HTTP health endpoint - if curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then - echo "✅ New container is responding!" - break + # Show container status for debugging + if [ $((i % 10)) -eq 0 ]; then + echo "📊 Container status: $(docker inspect $NEW_CONTAINER --format='{{.State.Status}}' 2>/dev/null || echo 'unknown')" + echo "📊 Health status: $HEALTH" + docker compose -f $COMPOSE_FILE logs --tail=5 portfolio 2>/dev/null || true fi fi - echo "⏳ Waiting... ($i/60)" + echo "⏳ Waiting... ($i/90)" sleep 2 done # Verify new container is working - if ! curl -f http://localhost:$HEALTH_PORT/api/health > /dev/null 2>&1; then + if [ "$HEALTH_CHECK_PASSED" != "true" ]; then echo "❌ New container failed health check!" - docker compose -f $COMPOSE_FILE logs --tail=50 portfolio + echo "📋 Container logs:" + docker compose -f $COMPOSE_FILE logs --tail=100 portfolio + echo "📋 Container inspect:" + docker inspect $NEW_CONTAINER 2>/dev/null || echo "Container not found" + echo "📋 Testing health endpoint directly:" + curl -v http://localhost:$HEALTH_PORT/api/health || echo "Health endpoint not reachable" exit 1 fi diff --git a/Dockerfile b/Dockerfile index c6f108c..2d1f28e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,6 +57,9 @@ WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 +# Install curl for health checks +RUN apt-get update && apt-get install -y --no-install-recommends curl && rm -rf /var/lib/apt/lists/* + # Create a non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs