AmirTrader commited on
Commit
153df19
·
verified ·
1 Parent(s): 61f5135

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -12
Dockerfile CHANGED
@@ -1,19 +1,42 @@
1
- FROM python:3.12-slim
 
 
 
2
 
3
- WORKDIR /code
4
 
5
- COPY ./requirements.txt /code/requirements.txt
6
- RUN python3 -m pip install --no-cache-dir --upgrade pip
7
- RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
9
- COPY . .
 
 
 
10
 
11
- EXPOSE 7860
 
 
 
12
 
13
- CMD ["panel", "serve", "/code/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
 
 
14
 
15
- RUN mkdir /.cache
16
- RUN chmod 777 /.cache
17
- RUN mkdir .chroma
18
- RUN chmod 777 .chroma
 
 
 
19
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1
2
+ #
3
+ # Stage 1: build wheels using full base image (with compilers)
4
+ FROM python:3.12-slim AS builder
5
 
6
+ WORKDIR /app
7
 
8
+ # Prevent unwanted cache and bytecode files
9
+ ENV PYTHONDONTWRITEBYTECODE=1 \
10
+ PYTHONUNBUFFERED=1
11
 
12
+ # Install build dependencies
13
+ RUN apt-get update && \
14
+ apt-get install -y --no-install-recommends gcc build-essential && \
15
+ rm -rf /var/lib/apt/lists/*
16
 
17
+ # Install dependencies as wheels to avoid needing compilers in final stage
18
+ COPY requirements.txt .
19
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
20
+ pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
21
 
22
+ # Stage 2: final runtime image
23
+ FROM python:3.12-slim AS runtime
24
+ WORKDIR /app
25
 
26
+ # Copy wheels and install runtime dependencies
27
+ COPY --from=builder /app/wheels /wheels
28
+ COPY requirements.txt .
29
+ RUN python3 -m pip install --no-cache-dir /wheels/*
30
+
31
+ # Copy application code
32
+ COPY . .
33
 
34
+ # Create cache directories with proper permissions (if needed)
35
+ RUN mkdir /.cache /.chroma && chmod 777 /.cache /.chroma
36
+
37
+ # Use non‑root user for better security
38
+ RUN useradd --no-log-init -r appuser && chown -R appuser /app /.cache /.chroma
39
+ USER appuser
40
+
41
+ EXPOSE 7860
42
+ CMD ["panel", "serve", "/app/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]