S-Dreamer commited on
Commit
fb0957c
·
verified ·
1 Parent(s): d65815d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +25 -23
Dockerfile CHANGED
@@ -1,36 +1,38 @@
1
- # Use a smaller, more efficient base image
2
  FROM python:3.11-slim
3
 
4
- # Set environment variables to prevent caching and writing .pyc files
5
- ENV PYTHONDONTWRITEBYTECODE 1
6
- ENV PYTHONUNBUFFERED 1
7
 
8
- # Set the working directory
9
- WORKDIR /code
10
 
11
- # Create a non-root user and group to run the application
12
- RUN addgroup --system appgroup && adduser --system --group appuser
13
 
14
- # Create necessary directories and set permissions *before* copying files
15
- # This improves layer caching.
16
- RUN mkdir -p /.cache ./.chroma \
17
- && chown -R appuser:appgroup /.cache ./.chroma
 
 
18
 
19
- # Copy dependency file and set permissions
20
- COPY --chown=appuser:appgroup ./requirements.txt /code/requirements.txt
 
21
 
22
- # Install dependencies
23
- RUN python3 -m pip install --no-cache-dir --upgrade pip
24
- RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
25
-
26
- # Copy the rest of the application code and set permissions
27
  COPY --chown=appuser:appgroup . .
28
 
29
- # Switch to the non-root user
 
 
 
30
  USER appuser
31
 
32
- # Expose the port the app runs on
33
  EXPOSE 7860
34
 
35
- # Define the command to run the application
36
- CMD ["panel", "serve", "/code/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
 
1
+ # Use a lightweight Python base image
2
  FROM python:3.11-slim
3
 
4
+ # Prevent .pyc files and ensure stdout/stderr are unbuffered
5
+ ENV PYTHONDONTWRITEBYTECODE=1 \
6
+ PYTHONUNBUFFERED=1
7
 
8
+ # Set working directory inside the container
9
+ WORKDIR /app
10
 
11
+ # Create a non-root user and group
12
+ RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser
13
 
14
+ # Install system-level dependencies (e.g., for building wheels or fonts for Panel)
15
+ RUN apt-get update && apt-get install -y --no-install-recommends \
16
+ build-essential \
17
+ libgl1 \
18
+ curl \
19
+ && apt-get clean && rm -rf /var/lib/apt/lists/*
20
 
21
+ # Copy and install Python dependencies
22
+ COPY --chown=appuser:appgroup requirements.txt .
23
+ RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
24
 
25
+ # Copy the full app code
 
 
 
 
26
  COPY --chown=appuser:appgroup . .
27
 
28
+ # Set file permissions
29
+ RUN mkdir -p /.cache /app/.chroma && chown -R appuser:appgroup /.cache /app
30
+
31
+ # Use non-root user
32
  USER appuser
33
 
34
+ # Expose Panel's default port
35
  EXPOSE 7860
36
 
37
+ # Launch the app
38
+ CMD ["panel", "serve", "app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]