Fred808 commited on
Commit
68da5cc
·
verified ·
1 Parent(s): 80adcc5

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -19
Dockerfile CHANGED
@@ -1,20 +1,20 @@
1
- # Use Python 3.11 slim as base image
2
  FROM python:3.11-slim as builder
3
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
- # Install system dependencies
8
  RUN apt-get update && apt-get install -y \
9
  gcc \
10
  libpq-dev \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
- # Install Python dependencies
14
  COPY requirements.txt .
15
  RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
16
 
17
- # Final stage
18
  FROM python:3.11-slim
19
 
20
  # Create non-root user
@@ -23,24 +23,24 @@ RUN useradd -m appuser
23
  # Set working directory
24
  WORKDIR /app
25
 
26
- # Install system dependencies
27
  RUN apt-get update && apt-get install -y \
28
  libpq5 \
29
  && rm -rf /var/lib/apt/lists/*
30
 
31
- # Copy wheels from builder stage
32
  COPY --from=builder /app/wheels /wheels
33
  COPY --from=builder /app/requirements.txt .
34
 
35
- # Install Python packages
36
  RUN pip install --no-cache /wheels/*
37
 
38
- # Copy application code
39
  COPY ./app app/
40
  COPY ./alembic.ini .
41
  COPY ./alembic alembic/
42
 
43
- # Create necessary directories with proper permissions
44
  RUN mkdir -p /app/logs /app/uploads/images /app/uploads/documents /app/backups && \
45
  chown -R appuser:appuser /app
46
 
@@ -49,17 +49,11 @@ USER appuser
49
 
50
  # Set environment variables
51
  ENV PYTHONPATH=/app \
52
- PYTHONUNBUFFERED=1
 
53
 
54
- services:
55
- redis:
56
- image: redis:6-alpine
57
- ports:
58
- - "6379:6379"
59
-
60
-
61
- # Expose port required by Hugging Face
62
  EXPOSE 7860
63
 
64
- # Start the application with uvicorn on port 7860
65
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # Stage 1 - Build wheels
2
  FROM python:3.11-slim as builder
3
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
+ # Install build dependencies
8
  RUN apt-get update && apt-get install -y \
9
  gcc \
10
  libpq-dev \
11
  && rm -rf /var/lib/apt/lists/*
12
 
13
+ # Install Python dependencies into wheel format
14
  COPY requirements.txt .
15
  RUN pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
16
 
17
+ # Stage 2 - Final image
18
  FROM python:3.11-slim
19
 
20
  # Create non-root user
 
23
  # Set working directory
24
  WORKDIR /app
25
 
26
+ # Install system runtime dependencies
27
  RUN apt-get update && apt-get install -y \
28
  libpq5 \
29
  && rm -rf /var/lib/apt/lists/*
30
 
31
+ # Copy built wheels
32
  COPY --from=builder /app/wheels /wheels
33
  COPY --from=builder /app/requirements.txt .
34
 
35
+ # Install packages from wheels
36
  RUN pip install --no-cache /wheels/*
37
 
38
+ # Copy app source code
39
  COPY ./app app/
40
  COPY ./alembic.ini .
41
  COPY ./alembic alembic/
42
 
43
+ # Create runtime directories and set permissions
44
  RUN mkdir -p /app/logs /app/uploads/images /app/uploads/documents /app/backups && \
45
  chown -R appuser:appuser /app
46
 
 
49
 
50
  # Set environment variables
51
  ENV PYTHONPATH=/app \
52
+ PYTHONUNBUFFERED=1 \
53
+ REDIS_URL=redis://redis:6379/0
54
 
55
+ # Expose FastAPI port
 
 
 
 
 
 
 
56
  EXPOSE 7860
57
 
58
+ # Start the FastAPI server
59
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]