AnuragShirke commited on
Commit
c36d647
·
1 Parent(s): 9114998

refactor: Switch to debian-based Docker image for compatibility

Browse files
Files changed (2) hide show
  1. Dockerfile +68 -20
  2. requirements.txt +1 -1
Dockerfile CHANGED
@@ -1,25 +1,73 @@
1
- # Multi-stage build for Python backend
2
- # Build stage
3
- FROM python:3.11-alpine as builder
4
 
5
  # Install build dependencies
6
- RUN apk add --no-cache \
7
- gcc \
8
- musl-dev \
9
- libffi-dev \
10
- openssl-dev \
11
- python3-dev \
12
- postgresql-dev \
13
- curl
14
-
15
- # Set the working directory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  WORKDIR /app
17
 
18
- # --- TEMPORARY DEBUGGING STEP ---
19
- # We will install pip and then run a command to get the exact platform tag.
20
- RUN python -m ensurepip
21
- RUN pip install --upgrade pip
22
- RUN pip debug --verbose
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- # The build will stop here for now.
25
- CMD ["echo", "Debugging complete. Check logs for platform info."]
 
 
1
+ # Stage 1: Builder
2
+ # Use a standard Debian-based image which has better compatibility for wheels
3
+ FROM python:3.11-slim-bookworm as builder
4
 
5
  # Install build dependencies
6
+ # We use apt-get instead of apk
7
+ RUN apt-get update && apt-get install -y \
8
+ build-essential \
9
+ libpq-dev \
10
+ curl \
11
+ --no-install-recommends && \
12
+ rm -rf /var/lib/apt/lists/*
13
+
14
+ WORKDIR /app
15
+
16
+ COPY requirements.txt .
17
+
18
+ # Create requirements for production (exclude dev dependencies)
19
+ RUN grep -v "pytest" requirements.txt > requirements-prod.txt
20
+
21
+ # Set a higher timeout for pip installations
22
+ ENV PIP_DEFAULT_TIMEOUT=1000
23
+
24
+ # Install dependencies to a local directory
25
+ RUN pip install --no-cache-dir --user -r requirements-prod.txt
26
+
27
+
28
+ # Stage 2: Final Production Image
29
+ FROM python:3.11-slim-bookworm
30
+
31
+ # Install runtime dependencies only
32
+ RUN apt-get update && apt-get install -y \
33
+ curl \
34
+ libpq5 \
35
+ --no-install-recommends && \
36
+ rm -rf /var/lib/apt/lists/*
37
+
38
+ # Create non-root user for security
39
+ RUN addgroup -S appgroup --gid 1001 && \
40
+ adduser -S appuser --uid 1001 --ingroup appgroup
41
+
42
  WORKDIR /app
43
 
44
+ # Copy installed packages from builder stage
45
+ COPY --from=builder /root/.local /home/appuser/.local
46
+
47
+ # Copy the application code
48
+ COPY --chown=appuser:appgroup ./src /app/src
49
+ COPY --chown=appuser:appgroup ./scripts /app/scripts
50
+ COPY --chown=appuser:appgroup ./alembic /app/alembic
51
+ COPY --chown=appuser:appgroup ./alembic.ini /app/alembic.ini
52
+
53
+ # Grant ownership of home directory to appuser
54
+ RUN chown -R appuser:appgroup /home/appuser
55
+
56
+ # Create data directory and set permissions
57
+ RUN mkdir -p /app/data && chown -R appuser:appgroup /app/data
58
+
59
+ # Make scripts executable
60
+ RUN chmod +x /app/scripts/*.sh
61
+
62
+ # Switch to non-root user
63
+ USER appuser
64
+
65
+ # Ensure user's local bin is in PATH
66
+ ENV PATH="/home/appuser/.local/bin:${PATH}"
67
+
68
+ # Expose port 8000
69
+ EXPOSE 8000
70
 
71
+ # Define the command to run the application
72
+ # This will be overridden by the command in Hugging Face settings, but it's good practice to have it.
73
+ CMD ["/app/scripts/init-db.sh"]
requirements.txt CHANGED
@@ -2,7 +2,7 @@ fastapi
2
  uvicorn[standard]
3
  python-multipart
4
  pydantic
5
- PyMuPDF @ https://files.pythonhosted.org/packages/b5/f2/1335a5897823a3d134826b43e8a482a0e5b9622c5e339b4e13f6b3b4f67c/PyMuPDF-1.24.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl#sha256=8d309c368f644396c44c14586f7525c39c5c343d29b33cd41455c889395c4c59
6
  pdfminer.six
7
  beautifulsoup4
8
  sentence-transformers
 
2
  uvicorn[standard]
3
  python-multipart
4
  pydantic
5
+ PyMuPDF
6
  pdfminer.six
7
  beautifulsoup4
8
  sentence-transformers