ci: update pipline to run api tests and build docker

This commit is contained in:
Black_Raven committed 2026-03-22 17:04:05 +03:00
1 parent 4ee6765b53
commit 1e50c9de10
1 file changed
+71 -1
+71 -1
View File
@@ -43,11 +43,81 @@ jobs:
export FLASK_APP=app.py export FLASK_APP=app.py
export FLASK_ENV=development export FLASK_ENV=development
flask run --host 0.0.0.0 --debug & flask run --host 0.0.0.0 --debug &
- name: Wait for Flask app to start
run: |
echo "Waiting for Flask app to start..."
for i in {1..10}; do
if curl -f http://localhost:80/health 2>/dev/null; then
echo "✅ Flask app is running"
exit 0
fi
echo "Attempt $i: Flask app not ready yet..."
sleep 2
done
echo "❌ Flask app failed to start"
exit 1
- name: Install test dependencies
run: |
. venv/bin/activate
pip install requests pytest pytest-cov
- name: Run API tests with coverage
run: |
. venv/bin/activate
echo "Running API tests..."
python test_api.py
echo "✅ API tests completed"
- name: Run additional pytest tests (if exist)
run: |
. venv/bin/activate
if [ -d tests ] && [ "$(ls -A tests)" ]; then
pytest tests/ -v --tb=short
else
echo "No pytest tests found, skipping"
fi
- name: Install release dependencies - name: Install release dependencies
run: | run: |
. venv/bin/activate
pip install gunicorn pip install gunicorn
- name: Release build (simulated) - name: Release build (simulated)
run: | run: |
. venv/bin/activate
gunicorn --check-config app:app gunicorn --check-config app:app
echo "✅ Gunicorn configuration is valid"
- name: Build Docker image
run: |
if [ -f Dockerfile ]; then
echo "🐳 Building Docker image..."
docker build -t PVH:${{ github.sha }} -t PVH:latest .
docker images | grep PVH
echo "✅ Docker image built successfully"
# Проверяем, что образ создался
docker run --rm PVH:latest python -c "import sys; print('Python version:', sys.version)" || true
fi
- name: Test Docker image
run: |
echo "Testing Docker image..."
docker run -d -p 5001:5000 --name flask-test-container flask-app:latest
sleep 5
curl -f http://localhost:5001/health || (docker logs flask-test-container && exit 1)
docker stop flask-test-container
docker rm flask-test-container
echo "✅ Docker image test passed"
- name: Stop Flask app
if: always()
run: |
pkill -f "flask run" || pkill -f "python app.py" || true
- name: Cleanup Docker
if: always()
run: |
docker system prune -f || true