youssefreda9 commited on
Commit
68921c9
·
1 Parent(s): a281968

Switch backend from Render to HuggingFace Spaces (free, no card required)

Browse files
Files changed (4) hide show
  1. .github/workflows/deploy.yml +5 -18
  2. Dockerfile +27 -0
  3. README_HF.md +8 -0
  4. vercel.json +1 -1
.github/workflows/deploy.yml CHANGED
@@ -47,34 +47,20 @@ jobs:
47
  grep -q "https://test.supabase.co" src/index.html && echo "✅ Supabase URL injected" || exit 1
48
  grep -q "test-key-1234" src/index.html && echo "✅ Supabase key injected" || exit 1
49
 
50
- deploy-backend:
51
- name: Deploy Backend (Render)
52
- needs: lint-and-validate
53
- if: github.ref == 'refs/heads/main' && github.event_name == 'push'
54
- runs-on: ubuntu-latest
55
- steps:
56
- - name: Trigger Render Deploy
57
- run: |
58
- if [ -n "${{ secrets.RENDER_DEPLOY_HOOK }}" ]; then
59
- curl -s -X POST "${{ secrets.RENDER_DEPLOY_HOOK }}" && echo "✅ Render deploy triggered"
60
- else
61
- echo "⚠️ RENDER_DEPLOY_HOOK not set — skipping backend deploy"
62
- fi
63
-
64
  health-check:
65
  name: Post-Deploy Health Check
66
- needs: deploy-backend
67
  if: github.ref == 'refs/heads/main' && github.event_name == 'push'
68
  runs-on: ubuntu-latest
69
  steps:
70
- - name: Wait for Render to deploy
71
- run: sleep 90
72
 
73
  - name: Check backend health
74
  run: |
75
  HEALTH_URL="${{ secrets.BACKEND_URL }}/api/health"
76
  if [ -z "${{ secrets.BACKEND_URL }}" ]; then
77
- HEALTH_URL="https://bayan-api.onrender.com/api/health"
78
  fi
79
  echo "Checking: $HEALTH_URL"
80
  response=$(curl -s -w "\n%{http_code}" "$HEALTH_URL")
@@ -88,3 +74,4 @@ jobs:
88
  echo "❌ Backend health check failed"
89
  exit 1
90
  fi
 
 
47
  grep -q "https://test.supabase.co" src/index.html && echo "✅ Supabase URL injected" || exit 1
48
  grep -q "test-key-1234" src/index.html && echo "✅ Supabase key injected" || exit 1
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  health-check:
51
  name: Post-Deploy Health Check
52
+ needs: lint-and-validate
53
  if: github.ref == 'refs/heads/main' && github.event_name == 'push'
54
  runs-on: ubuntu-latest
55
  steps:
56
+ - name: Wait for HuggingFace Spaces to deploy
57
+ run: sleep 120
58
 
59
  - name: Check backend health
60
  run: |
61
  HEALTH_URL="${{ secrets.BACKEND_URL }}/api/health"
62
  if [ -z "${{ secrets.BACKEND_URL }}" ]; then
63
+ HEALTH_URL="https://mohamedatef24-bayan-api.hf.space/api/health"
64
  fi
65
  echo "Checking: $HEALTH_URL"
66
  response=$(curl -s -w "\n%{http_code}" "$HEALTH_URL")
 
74
  echo "❌ Backend health check failed"
75
  exit 1
76
  fi
77
+
Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+
3
+ WORKDIR /app
4
+
5
+ # Install system dependencies
6
+ RUN apt-get update && apt-get install -y --no-install-recommends \
7
+ build-essential \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ # Copy requirements and install Python dependencies
11
+ COPY requirements.txt .
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
+
14
+ # Copy application code
15
+ COPY src/ ./src/
16
+ COPY .env* ./
17
+
18
+ # Set environment variables
19
+ ENV PORT=7860
20
+ ENV DEBUG=False
21
+ ENV PYTHONUNBUFFERED=1
22
+
23
+ # Expose port
24
+ EXPOSE 7860
25
+
26
+ # Start the app with gunicorn
27
+ CMD ["gunicorn", "--chdir", "src", "app:app", "--bind", "0.0.0.0:7860", "--timeout", "120", "--workers", "1"]
README_HF.md ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Bayan API
3
+ emoji: ✍️
4
+ colorFrom: green
5
+ colorTo: blue
6
+ sdk: docker
7
+ app_port: 7860
8
+ ---
vercel.json CHANGED
@@ -4,7 +4,7 @@
4
  "rewrites": [
5
  {
6
  "source": "/api/:path*",
7
- "destination": "https://bayan-api.onrender.com/api/:path*"
8
  },
9
  {
10
  "source": "/(.*)",
 
4
  "rewrites": [
5
  {
6
  "source": "/api/:path*",
7
+ "destination": "https://mohamedatef24-bayan-api.hf.space/api/:path*"
8
  },
9
  {
10
  "source": "/(.*)",