File size: 1,800 Bytes
6b65116
05bbd13
d28a325
05bbd13
d28a325
 
05bbd13
6b65116
 
d28a325
 
 
 
 
 
05bbd13
d28a325
 
 
 
 
05bbd13
6b65116
d28a325
 
 
 
 
 
 
 
 
 
 
 
6b65116
 
 
 
 
05bbd13
 
6b65116
05bbd13
 
 
6b65116
05bbd13
 
 
 
 
 
 
 
 
 
 
 
 
 
6b65116
 
05bbd13
 
 
d28a325
 
6b65116
d28a325
 
6b65116
d28a325
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Use the latest supported python slim image
FROM python:3.9-slim

# 1. Install system dependencies
# We suppress prompts to avoid build errors
ENV DEBIAN_FRONTEND=noninteractive

# Note: Removed 'numpy' from this list.
# Added 'dbus-x11' which is often needed for XFCE to start correctly in containers.
RUN apt-get update && apt-get install -y \
    xfce4 \
    xfce4-terminal \
    xvfb \
    x11vnc \
    novnc \
    websockify \
    firefox-esr \
    sudo \
    curl \
    git \
    vim \
    procps \
    dbus-x11 \
    && rm -rf /var/lib/apt/lists/*

# 2. Setup a non-root user (Hugging Face Spaces defaults to UID 1000)
RUN useradd -m -u 1000 user
RUN echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# 3. Set up the working directory
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME

# 4. Install Python dependencies (Numpy goes here!)
RUN pip install --no-cache-dir numpy

# 5. Create the start script
# We configure the VNC and NoVNC connection here
RUN echo '#!/bin/bash\n\
\n\
# Set VNC password (default: password)\n\
export VNC_PASSWD=${VNC_PASSWD:-password}\n\
\n\
# Start Xvfb (Virtual Monitor)\n\
# 1280x720 is a good standard size\n\
Xvfb :1 -screen 0 1280x720x16 &\n\
export DISPLAY=:1\n\
sleep 2\n\
\n\
# Start Window Manager (XFCE)\n\
startxfce4 &\n\
sleep 2\n\
\n\
# Start VNC Server\n\
mkdir -p ~/.vnc\n\
x11vnc -storepasswd "$VNC_PASSWD" ~/.vnc/passwd\n\
x11vnc -display :1 -rfbauth ~/.vnc/passwd -forever -shared -bg\n\
\n\
# Start NoVNC (The Web Interface)\n\
# This bridges the VNC server (5900) to the Web Port (7860)\n\
echo "Starting NoVNC..."\n\
websockify --web /usr/share/novnc/ 7860 localhost:5900\n\
' > start.sh

RUN chmod +x start.sh

# 6. Expose the Hugging Face port
EXPOSE 7860

# 7. Run the start script
CMD ["./start.sh"]