chore: fix linting violations and configure ruff rules for CI #76
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docker Build and Publish | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - 'v*.*.*' | |
| workflow_dispatch: | |
| jobs: | |
| detect-changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| main: ${{ steps.filter.outputs.main }} | |
| inference: ${{ steps.filter.outputs.inference }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: dorny/paths-filter@v4 | |
| id: filter | |
| with: | |
| filters: | | |
| main: | |
| - 'main_api/**' | |
| inference: | |
| - 'inference_api/**' | |
| ci-main-api: | |
| needs: detect-changes | |
| if: ${{ needs.detect-changes.outputs.main == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v10.0.1 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "main_api/uv.lock" | |
| - name: Set up Python | |
| uses: actions/setup-python@v7 | |
| with: | |
| python-version-file: "main_api/.python-version" | |
| - name: Install dependencies | |
| working-directory: ./main_api | |
| run: uv sync --all-extras --dev | |
| - name: Run Mypy Type Checking | |
| working-directory: ./main_api | |
| run: uv run mypy . | |
| - name: Run Ruff Linting | |
| working-directory: ./main_api | |
| run: uv run ruff check . | |
| - name: Run Pytest | |
| working-directory: ./main_api | |
| run: uv run pytest | |
| ci-inference-api: | |
| needs: detect-changes | |
| if: ${{ needs.detect-changes.outputs.inference == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| - name: Install uv | |
| uses: astral-sh/setup-uv@v10.0.1 | |
| with: | |
| enable-cache: true | |
| cache-dependency-glob: "inference_api/uv.lock" | |
| - name: Set up Python | |
| uses: actions/setup-python@v7 | |
| with: | |
| python-version-file: "inference_api/.python-version" | |
| - name: Install dependencies | |
| working-directory: ./inference_api | |
| run: uv sync --all-extras --dev | |
| - name: Run Mypy Type Checking | |
| working-directory: ./inference_api | |
| run: uv run mypy . | |
| - name: Run Ruff Linting | |
| working-directory: ./inference_api | |
| run: uv run ruff check . | |
| - name: Run Pytest | |
| working-directory: ./inference_api | |
| run: uv run pytest | |
| build-and-push-main-api: | |
| needs: [detect-changes, ci-main-api] | |
| if: ${{ needs.detect-changes.outputs.main == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata for main_api | |
| id: meta_main | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ secrets.DOCKERHUB_USERNAME }}/main_api | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=sha,format=short | |
| type=semver,pattern={{version}} | |
| - name: Build and push main_api | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ./main_api | |
| file: ./main_api/Dockerfile | |
| push: true | |
| tags: ${{ steps.meta_main.outputs.tags }} | |
| labels: ${{ steps.meta_main.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| build-and-push-inference-cpu: | |
| needs: [detect-changes, ci-inference-api] | |
| if: ${{ needs.detect-changes.outputs.inference == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata for inference_api (CPU) | |
| id: meta_cpu | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ secrets.DOCKERHUB_USERNAME }}/inference_api | |
| tags: | | |
| type=raw,value=cpu-latest,enable={{is_default_branch}} | |
| type=sha,format=short,prefix=cpu- | |
| type=semver,pattern=cpu-{{version}} | |
| - name: Build and push inference_api (CPU) | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ./inference_api | |
| file: ./inference_api/Dockerfile | |
| push: true | |
| tags: ${{ steps.meta_cpu.outputs.tags }} | |
| labels: ${{ steps.meta_cpu.outputs.labels }} | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/inference_api:buildcache-cpu | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/inference_api:buildcache-cpu,mode=max | |
| build-and-push-inference-gpu: | |
| needs: [detect-changes, ci-inference-api] | |
| if: ${{ needs.detect-changes.outputs.inference == 'true' }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v4 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Extract metadata for inference_api (GPU) | |
| id: meta_gpu | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ secrets.DOCKERHUB_USERNAME }}/inference_api | |
| tags: | | |
| type=raw,value=gpu-latest,enable={{is_default_branch}} | |
| type=sha,format=short,prefix=gpu- | |
| type=semver,pattern=gpu-{{version}} | |
| - name: Build and push inference_api (GPU) | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: ./inference_api | |
| file: ./inference_api/Dockerfile.gpu | |
| push: true | |
| tags: ${{ steps.meta_gpu.outputs.tags }} | |
| labels: ${{ steps.meta_gpu.outputs.labels }} | |
| cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/inference_api:buildcache-gpu | |
| cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/inference_api:buildcache-gpu,mode=max | |
| deploy-all: | |
| needs: [build-and-push-main-api, build-and-push-inference-gpu] | |
| if: | | |
| always() && | |
| (needs.build-and-push-main-api.result != 'failure' && needs.build-and-push-main-api.result != 'cancelled') && | |
| (needs.build-and-push-inference-gpu.result != 'failure' && needs.build-and-push-inference-gpu.result != 'cancelled') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| - name: Generate .env from Infisical | |
| run: | | |
| curl -1sLf 'https://artifacts-cli.infisical.com/setup.deb.sh' | sudo -E bash | |
| sudo apt-get install -y infisical | |
| export INFISICAL_TOKEN=$(infisical login --method=universal-auth --client-id="${{ secrets.INFISICAL_MACHINE_IDENTITY_CLIENT_ID }}" --client-secret="${{ secrets.INFISICAL_MACHINE_IDENTITY_CLIENT_SECRET }}" --plain --silent) | |
| infisical export --projectId="${{ secrets.INFISICAL_PROJECT_ID }}" --env=prod --format=dotenv > .env | |
| - name: Prepare configs for VM | |
| run: | | |
| mkdir -p rabbitmq | |
| cp config/rabbitmq/rabbitmq.conf rabbitmq/rabbitmq.conf | |
| - name: Fix permissions on GCP VM before SCP | |
| uses: appleboy/ssh-action@v1.2.3 | |
| with: | |
| host: ${{ secrets.GCP_VM_IP }} | |
| username: github-actions | |
| key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} | |
| script: | | |
| sudo mkdir -p /app | |
| sudo chown -R github-actions:github-actions /app | |
| - name: Copy Compose and configs to VM | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.GCP_VM_IP }} | |
| username: github-actions | |
| key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} | |
| source: "docker-compose.yml,rabbitmq/rabbitmq.conf,.env" | |
| target: "/app" | |
| - name: Deploy to Google Cloud VM | |
| uses: appleboy/ssh-action@v1.2.3 | |
| with: | |
| host: ${{ secrets.GCP_VM_IP }} | |
| username: github-actions | |
| key: ${{ secrets.GCP_SSH_PRIVATE_KEY }} | |
| script: | | |
| cd /app | |
| sudo docker compose pull | |
| SCALE_ARGS="" | |
| for SERVICE in $(sudo docker compose config --services); do | |
| COUNT=$(sudo docker compose ps -q $SERVICE | wc -l) | |
| if [ "$COUNT" -gt 1 ]; then | |
| SCALE_ARGS="$SCALE_ARGS --scale $SERVICE=$COUNT" | |
| echo "Preserving scale for $SERVICE: $COUNT replicas" | |
| fi | |
| done | |
| sudo docker compose up -d --force-recreate $SCALE_ARGS | |
| sudo docker exec eventsnap_nginx nginx -s reload | |