Adarshu07 commited on
Commit
b2031a9
Β·
verified Β·
1 Parent(s): fcbe7be

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +21 -36
Dockerfile CHANGED
@@ -1,24 +1,25 @@
1
  # ╔══════════════════════════════════════════════════════════════╗
2
  # β•‘ Dockerfile β€” Cloudflare AI API β•‘
3
- # β•‘ β•‘
4
- # β•‘ Stack: Python 3.11 Β· FastAPI Β· Chrome Β· Xvfb β•‘
5
- # β•‘ Port: 7860 (HuggingFace Spaces default) β•‘
6
- # β•‘ β•‘
7
- # β•‘ KEY FIX: /tmp/.X11-unix is pre-created as root with β•‘
8
- # β•‘ sticky-bit 1777 so non-root Xvfb can use it. β•‘
9
- # β•‘ Xvfb is started by entrypoint.sh (not pyvirtualdisplay) β•‘
10
- # β•‘ so we have full control over display :99. β•‘
11
  # β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
12
 
13
  FROM python:3.11-slim
14
 
15
- # ── System deps ───────────────────────────────────────────────
 
 
 
 
 
 
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
  xvfb \
18
  x11-utils \
19
  wget \
20
- gnupg \
21
  ca-certificates \
 
 
22
  libx11-6 \
23
  libx11-xcb1 \
24
  libxcb1 \
@@ -50,7 +51,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
50
  procps \
51
  && rm -rf /var/lib/apt/lists/*
52
 
53
- # ── Google Chrome stable ───────────────────────────────────────
54
  RUN wget -q -O /tmp/chrome.deb \
55
  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
56
  && apt-get update \
@@ -59,46 +60,30 @@ RUN wget -q -O /tmp/chrome.deb \
59
  && rm -rf /var/lib/apt/lists/* \
60
  && google-chrome --version
61
 
62
- # ── Pre-create X11 socket directory AS ROOT ───────────────────
63
- # CRITICAL FIX: Xvfb needs /tmp/.X11-unix to exist with sticky-bit.
64
- # When running as non-root, Xvfb cannot create it β†’ "euid != 0" error.
65
- # Creating it here (as root at build time) permanently fixes this.
66
  RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix
67
 
68
- # ── Working directory ──────────────────────────────────────────
69
  WORKDIR /app
70
 
71
- # ── Python deps ────────────────────────────────────────────────
72
  COPY requirements.txt .
73
  RUN pip install --no-cache-dir --upgrade pip \
74
  && pip install --no-cache-dir -r requirements.txt
75
 
76
- # ── App source ─────────────────────────────────────────────────
77
- COPY cloudflare_provider.py .
78
- COPY server.py .
79
- COPY entrypoint.sh .
80
 
81
- # ── Directories + permissions ──────────────────────────────────
82
- RUN mkdir -p /app/cache \
83
- && useradd -m -u 1000 appuser \
84
  && chown -R appuser:appuser /app \
85
  && chmod +x /app/entrypoint.sh \
86
- # Keep X11 socket dir world-writable after user creation
87
  && chmod 1777 /tmp/.X11-unix
88
 
89
  USER appuser
90
 
91
- # ── Environment ────────────────────────────────────────────────
92
- ENV PYTHONUNBUFFERED=1 \
93
- PYTHONDONTWRITEBYTECODE=1 \
94
- # Display set by entrypoint.sh (Xvfb :99)
95
- DISPLAY=:99 \
96
- # VR_DISPLAY=0: we manage Xvfb ourselves in entrypoint.sh
97
- # so pyvirtualdisplay does NOT try to start a second Xvfb
98
- VR_DISPLAY=0 \
99
- # Signals the provider that a real display exists via DISPLAY env
100
  XVFB_EXTERNAL=1 \
101
- # Pool config
102
  POOL_SIZE=2 \
103
  PORT=7860 \
104
  HOST=0.0.0.0 \
@@ -107,4 +92,4 @@ ENV PYTHONUNBUFFERED=1 \
107
 
108
  EXPOSE 7860
109
 
110
- CMD ["/app/start.sh"]
 
1
  # ╔══════════════════════════════════════════════════════════════╗
2
  # β•‘ Dockerfile β€” Cloudflare AI API β•‘
3
+ # β•‘ Stack: Python 3.11 Β· FastAPI Β· Chrome Β· Xvfb β•‘
4
+ # β•‘ Port: 7860 β•‘
 
 
 
 
 
 
5
  # β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
6
 
7
  FROM python:3.11-slim
8
 
9
+ ENV DEBIAN_FRONTEND=noninteractive \
10
+ PYTHONUNBUFFERED=1 \
11
+ PYTHONDONTWRITEBYTECODE=1
12
+
13
+ SHELL ["/bin/bash", "-o", "pipefail", "-c"]
14
+
15
+ # System deps
16
  RUN apt-get update && apt-get install -y --no-install-recommends \
17
  xvfb \
18
  x11-utils \
19
  wget \
 
20
  ca-certificates \
21
+ gnupg \
22
+ curl \
23
  libx11-6 \
24
  libx11-xcb1 \
25
  libxcb1 \
 
51
  procps \
52
  && rm -rf /var/lib/apt/lists/*
53
 
54
+ # Google Chrome stable
55
  RUN wget -q -O /tmp/chrome.deb \
56
  https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
57
  && apt-get update \
 
60
  && rm -rf /var/lib/apt/lists/* \
61
  && google-chrome --version
62
 
63
+ # Pre-create X11 socket directory
 
 
 
64
  RUN mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix
65
 
 
66
  WORKDIR /app
67
 
68
+ # Python deps
69
  COPY requirements.txt .
70
  RUN pip install --no-cache-dir --upgrade pip \
71
  && pip install --no-cache-dir -r requirements.txt
72
 
73
+ # App source
74
+ COPY cloudflare_provider.py server.py entrypoint.sh ./
 
 
75
 
76
+ # User + permissions
77
+ RUN useradd -m -u 1000 appuser \
78
+ && mkdir -p /app/cache \
79
  && chown -R appuser:appuser /app \
80
  && chmod +x /app/entrypoint.sh \
 
81
  && chmod 1777 /tmp/.X11-unix
82
 
83
  USER appuser
84
 
85
+ ENV DISPLAY=:99 \
 
 
 
 
 
 
 
 
86
  XVFB_EXTERNAL=1 \
 
87
  POOL_SIZE=2 \
88
  PORT=7860 \
89
  HOST=0.0.0.0 \
 
92
 
93
  EXPOSE 7860
94
 
95
+ CMD ["/app/entrypoint.sh"]