broadfield-dev commited on
Commit
370b01e
·
verified ·
1 Parent(s): e791786

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +39 -9
Dockerfile CHANGED
@@ -1,14 +1,44 @@
1
- FROM python:3.10-slim
2
-
3
- RUN apt-get update && apt-get install -y wget && \
4
- wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/wkhtmltox_0.12.6.1-2.jammy_amd64.deb && \
5
- apt install -y ./wkhtmltox_0.12.6.1-2.jammy_amd64.deb && \
6
- rm -rf /var/lib/apt/lists/*
7
 
 
8
  WORKDIR /app
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  COPY requirements.txt .
10
  RUN pip install --no-cache-dir -r requirements.txt
11
- COPY . .
12
 
13
- ENV PORT=7860
14
- CMD ["python", "app.py"]
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a compatible Python base image
2
+ FROM python:3.9-slim-bookworm
 
 
 
 
3
 
4
+ # Set the working directory inside the container
5
  WORKDIR /app
6
+
7
+ # Update package lists and install all system dependencies
8
+ RUN apt-get update && apt-get install -y --no-install-recommends \
9
+ wget \
10
+ fontconfig \
11
+ libjpeg62-turbo \
12
+ libxext6 \
13
+ xfonts-75dpi \
14
+ xfonts-base \
15
+ libxrender1 \
16
+ libssl3 \
17
+ && apt-get clean \
18
+ && rm -rf /var/lib/apt/lists/*
19
+
20
+ # Download and install the wkhtmltox package
21
+ RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
22
+ dpkg -i wkhtmltox_0.12.6.1-3.bookworm_amd64.deb && \
23
+ rm wkhtmltox_0.12.6.1-3.bookworm_amd64.deb
24
+
25
+ # Create non-root user as required by HF Spaces
26
+ RUN useradd -m -u 1000 user
27
+
28
+ # Copy application files (before switching user)
29
  COPY requirements.txt .
30
  RUN pip install --no-cache-dir -r requirements.txt
 
31
 
32
+ # Switch to non-root user and set environment
33
+ USER user
34
+ ENV HOME=/home/user \
35
+ PATH=/home/user/.local/bin:$PATH
36
+
37
+ # Copy app code with proper ownership
38
+ COPY --chown=1000:1000 app.py .
39
+
40
+ # Expose the port
41
+ EXPOSE 7860
42
+
43
+ # Run with gunicorn
44
+ CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]