diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 13875f8..c0fc6f3 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -53,6 +53,68 @@ jobs: run: | cd web npm run build + + build-and-deploy: + needs: test-backend + runs-on: ubuntu-latest + if: success() # Запускается только если тесты прошли успешно + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to container registry + uses: docker/login-action@v3 + with: + registry: gitea.example.com # Замените на ваш Gitea registry + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build Docker image + id: build + uses: docker/build-push-action@v5 + with: + context: . + push: false + load: true + tags: fastapi-app:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Stop and remove old container + run: | + docker stop fastapi-container || true + docker rm fastapi-container || true + + - name: Run new container + run: | + docker run -d \ + --name fastapi-container \ + -p 8080:8000 \ + --restart unless-stopped \ + fastapi-app:latest + + - name: Wait for container to be ready + run: | + for i in {1..30}; do + if curl -s http://localhost:8080/health > /dev/null; then + echo "Container is ready!" + exit 0 + fi + echo "Waiting for container... ($i/30)" + sleep 2 + done + echo "Container failed to start properly" + docker logs fastapi-container + exit 1 + + - name: Verify deployment + run: | + curl -f http://localhost:8080/ || exit 1 + echo "Deployment successful!" # Явный статус для PR pr-status: