GitHub Actions commited on
Commit
0e27589
·
1 Parent(s): 976eb67

Deploy backend from GitHub Actions

Browse files

🚀 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>

Files changed (2) hide show
  1. Dockerfile +17 -11
  2. app.py +12 -19
Dockerfile CHANGED
@@ -1,6 +1,12 @@
1
- # Use Python 3.11 slim image optimized for HF Spaces
2
  FROM python:3.11-slim
3
 
 
 
 
 
 
 
4
  # Set the working directory
5
  WORKDIR /app
6
 
@@ -9,26 +15,26 @@ RUN apt-get update && apt-get install -y \
9
  gcc \
10
  g++ \
11
  curl \
 
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
- # Copy the pyproject.toml file first
15
  COPY pyproject.toml ./
16
 
17
- # Install build dependencies
18
- RUN pip install --no-cache-dir build
19
-
20
  # Install Python dependencies
 
21
  RUN pip install --no-cache-dir -e .
22
 
23
  # Copy the rest of the application code
24
  COPY . .
25
 
26
- # Create necessary directories
27
- RUN mkdir -p database logs
 
 
28
 
29
- # Create a non-root user for security (optional for HF Spaces)
30
- RUN useradd -m -u 1000 user && chown -R user:user /app
31
- USER user
32
 
33
  # Expose the port (HF Spaces default)
34
  EXPOSE 7860
@@ -37,5 +43,5 @@ EXPOSE 7860
37
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
38
  CMD curl -f http://localhost:7860/health || exit 1
39
 
40
- # Run the application with database initialization
41
  CMD ["python", "start_server.py"]
 
1
+ # Use Python 3.11 slim image
2
  FROM python:3.11-slim
3
 
4
+ # Set environment variables
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PYTHONDONTWRITEBYTECODE=1 \
7
+ PIP_NO_CACHE_DIR=1 \
8
+ PIP_DISABLE_PIP_VERSION_CHECK=1
9
+
10
  # Set the working directory
11
  WORKDIR /app
12
 
 
15
  gcc \
16
  g++ \
17
  curl \
18
+ build-essential \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
+ # Copy requirements first for better caching
22
  COPY pyproject.toml ./
23
 
 
 
 
24
  # Install Python dependencies
25
+ RUN pip install --upgrade pip setuptools wheel
26
  RUN pip install --no-cache-dir -e .
27
 
28
  # Copy the rest of the application code
29
  COPY . .
30
 
31
+ # Create necessary directories and set permissions
32
+ RUN mkdir -p database logs && \
33
+ touch database/auth.db && \
34
+ chmod +x start_server.py
35
 
36
+ # For HF Spaces, we run as root to avoid permission issues
37
+ # USER user
 
38
 
39
  # Expose the port (HF Spaces default)
40
  EXPOSE 7860
 
43
  HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
44
  CMD curl -f http://localhost:7860/health || exit 1
45
 
46
+ # Run the application
47
  CMD ["python", "start_server.py"]
app.py CHANGED
@@ -1,22 +1,15 @@
1
- import gradio as gr
2
- import uvicorn
3
- from fastapi import FastAPI
4
- from main import app
5
-
6
- # Create Gradio interface that just forwards to FastAPI
7
- def create_gradio_interface():
8
- # This will wrap our FastAPI app
9
- interface = gr.mount_gradio_app(app, None, path="/")
10
- return interface
11
 
 
12
  if __name__ == "__main__":
13
- # Mount FastAPI app
14
- demo = create_gradio_interface()
 
 
 
 
15
 
16
- # Launch the app
17
- demo.launch(
18
- server_name="0.0.0.0",
19
- server_port=7860,
20
- share=False,
21
- show_api=True
22
- )
 
1
+ import os
2
+ import sys
3
+ import subprocess
 
 
 
 
 
 
 
4
 
5
+ # For HF Spaces Docker deployment, just start the server directly
6
  if __name__ == "__main__":
7
+ print("🚀 Starting application via app.py for Hugging Face Spaces...")
8
+
9
+ # Change to backend directory if needed
10
+ if os.path.exists("backend"):
11
+ os.chdir("backend")
12
+ print("Changed to backend directory")
13
 
14
+ # Run start_server.py
15
+ os.execvp(sys.executable, [sys.executable, "start_server.py"])