Spaces:
Running
Running
| name: Deploy LMAF | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: deploy-lmaf | |
| cancel-in-progress: false | |
| jobs: | |
| test: | |
| name: Test | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: pip install -r requirements.txt pytest | |
| - name: Run tests | |
| run: python -m pytest tests/ -v | |
| deploy-prod: | |
| name: Deploy to prod | |
| needs: test | |
| runs-on: [self-hosted, local] | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Pull deployment config | |
| run: ssh prod "cd ~/SecondLayer && git pull origin main" | |
| - name: Build container | |
| run: | | |
| ssh prod "cd ~/SecondLayer/deployment && \ | |
| docker compose -f docker-compose.prod.yml --env-file .env.prod \ | |
| build --no-cache lmaf-prod" | |
| - name: Start container | |
| run: | | |
| ssh prod "cd ~/SecondLayer/deployment && \ | |
| docker compose -f docker-compose.prod.yml --env-file .env.prod \ | |
| up -d lmaf-prod" | |
| - name: Health check | |
| run: | | |
| for i in $(seq 1 45); do | |
| if ssh prod "docker exec lmaf-prod python -c \"import urllib.request; urllib.request.urlopen('http://localhost:7860/')\"" 2>/dev/null; then | |
| echo "Container healthy after $((i*2))s" | |
| exit 0 | |
| fi | |
| sleep 2 | |
| done | |
| echo "Health check failed" | |
| ssh prod "docker logs --tail 30 lmaf-prod" || true | |
| exit 1 | |
| sync-hf: | |
| name: Sync to HuggingFace Space | |
| needs: test | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Push to HuggingFace | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| git remote add hf https://overthelex:${HF_TOKEN}@huggingface.co/spaces/overthelex/lmaf || true | |
| git push hf main --force | |