Commit
·
c36d647
1
Parent(s):
9114998
refactor: Switch to debian-based Docker image for compatibility
Browse files- Dockerfile +68 -20
- requirements.txt +1 -1
Dockerfile
CHANGED
|
@@ -1,25 +1,73 @@
|
|
| 1 |
-
#
|
| 2 |
-
#
|
| 3 |
-
FROM python:3.11-
|
| 4 |
|
| 5 |
# Install build dependencies
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
WORKDIR /app
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
|
|
|
|
|
| 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
|
| 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
|