Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile +16 -50
- entrypoint.sh +15 -81
Dockerfile
CHANGED
|
@@ -1,67 +1,34 @@
|
|
| 1 |
-
# Base image
|
| 2 |
FROM python:3.9
|
| 3 |
|
| 4 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
|
| 6 |
-
# Install
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
-
openssh-server \
|
| 9 |
curl \
|
| 10 |
wget \
|
| 11 |
git \
|
| 12 |
nano \
|
|
|
|
| 13 |
net-tools \
|
| 14 |
sudo \
|
| 15 |
-
ca-certificates \
|
| 16 |
-
libcap2-bin && \
|
| 17 |
rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
RUN
|
| 21 |
-
|
| 22 |
-
chmod
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
RUN sed -i -E 's/#?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config && \
|
| 26 |
-
sed -i -E 's/#?UsePAM yes/UsePAM no/' /etc/ssh/sshd_config && \
|
| 27 |
-
sed -i -E 's/#?PermitEmptyPasswords .*/PermitEmptyPasswords no/' /etc/ssh/sshd_config && \
|
| 28 |
-
sed -i -E 's/#?ChallengeResponseAuthentication .*/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config && \
|
| 29 |
-
sed -i -E 's/#?PermitRootLogin .*/PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
|
| 30 |
-
|
| 31 |
-
# Create non-root user
|
| 32 |
RUN useradd -m -u 1000 -s /bin/bash user && \
|
| 33 |
-
echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/user
|
| 34 |
-
|
| 35 |
-
# Add your SSH public key
|
| 36 |
-
RUN mkdir -p /home/user/.ssh && \
|
| 37 |
-
echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC8MNnoeALNROR4f5rSdeyTWpB/EfK83UAV9wOMvzgBmKx2bUZLnlQNDnfHzize3iAk0KWjjEped+O9ZIK1PZmGbmrU6qM5MvtV5H3a9ySLlVwzGuvjHEYPR8zprfQPTJYXYfukxfczSyIWNyunpuQoB+O8gLoY9urIQmuwYaX1qTKpooxpBG/tuRgy7LkTmqp0CGD60ugTYS9cJRVfpcssBcbTtQi0kgnr44ml9MRmR7rh53Vo3vqeo3BGAhINTdWdGvR2k7dTU3jVe+CdzYn8U5IeSG7KlkM6VB53gmJWQ8wPSj+Xhp7yB7AYPqKKzj27lud1yA9DSosVf5vKYxvagqx5GMfDHsTsOuWeXfKIZYdzX/XsKr5QZaH4r7K9j65+t4yn2LC5p9oAv8+GK/sUi8/uj20i3sglhHW/ZYxhJ9h3HYEjFmg2bJX5FO0X67YjN7piBQ+5T/mXBXD6mHHYgAOpmC+glLdq39cjoXD4AAV9xPNTjfEQ0sUi+YZU4VE8xu/f9cZuS0+x4Qv35fHrYr7dqwsLGuibLPt4lfXtLHbBUKjzmv1nSXc3YDwbqD3Uic6MA0F+yYHgBubqT5WAtitzeLYEaWK7gfK4qvz0AI0wLdTvFfvlIEKJCP0dKplGXE92JCkNEsK8b4P3U43D1lmLCn0kN64lsK6oxXWXzw== your_email@example.com" \
|
| 38 |
-
> /home/user/.ssh/authorized_keys && \
|
| 39 |
-
chmod 700 /home/user/.ssh && \
|
| 40 |
-
chmod 600 /home/user/.ssh/authorized_keys && \
|
| 41 |
-
chown -R user:user /home/user/.ssh
|
| 42 |
-
|
| 43 |
-
# Also allow root SSH login with the same key (for tunnel use)
|
| 44 |
-
RUN mkdir -p /root/.ssh && \
|
| 45 |
-
cp /home/user/.ssh/authorized_keys /root/.ssh/authorized_keys && \
|
| 46 |
-
chmod 700 /root/.ssh && chmod 600 /root/.ssh/authorized_keys
|
| 47 |
-
|
| 48 |
-
# Install gsocket properly
|
| 49 |
-
RUN wget -qO /tmp/gsocket_install.sh https://gsocket.io/install.sh && \
|
| 50 |
-
bash /tmp/gsocket_install.sh || true && \
|
| 51 |
-
# Fallback: build from source if binary not in PATH
|
| 52 |
-
which gs-netcat || ( \
|
| 53 |
-
apt-get update && apt-get install -y automake autoconf build-essential libssl-dev && \
|
| 54 |
-
git clone --depth=1 https://github.com/hackerschoice/gsocket.git /tmp/gsocket && \
|
| 55 |
-
cd /tmp/gsocket && autoreconf -fi && ./configure && make && make install \
|
| 56 |
-
)
|
| 57 |
-
|
| 58 |
-
# Install code-server (VS Code in browser)
|
| 59 |
-
RUN curl -fsSL https://code-server.dev/install.sh | sh
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 65 |
|
| 66 |
WORKDIR /app
|
| 67 |
COPY . /app
|
|
@@ -69,7 +36,6 @@ COPY . /app
|
|
| 69 |
COPY entrypoint.sh /entrypoint.sh
|
| 70 |
RUN chmod +x /entrypoint.sh
|
| 71 |
|
| 72 |
-
# HF Spaces requires EXPOSE 7860
|
| 73 |
EXPOSE 7860
|
| 74 |
|
| 75 |
-
CMD ["/entrypoint.sh"]
|
|
|
|
|
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
| 3 |
ENV DEBIAN_FRONTEND=noninteractive
|
| 4 |
|
| 5 |
+
# Install dependencies
|
| 6 |
RUN apt-get update && apt-get install -y \
|
|
|
|
| 7 |
curl \
|
| 8 |
wget \
|
| 9 |
git \
|
| 10 |
nano \
|
| 11 |
+
vim \
|
| 12 |
net-tools \
|
| 13 |
sudo \
|
| 14 |
+
ca-certificates && \
|
|
|
|
| 15 |
rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
+
# Install ttyd from prebuilt binary
|
| 18 |
+
RUN wget -q https://github.com/tsl0922/ttyd/releases/download/1.7.3/ttyd.x86_64 \
|
| 19 |
+
-O /usr/local/bin/ttyd && \
|
| 20 |
+
chmod +x /usr/local/bin/ttyd
|
| 21 |
|
| 22 |
+
# Create a non-root user with a password
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
RUN useradd -m -u 1000 -s /bin/bash user && \
|
| 24 |
+
echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/user && \
|
| 25 |
+
echo "user:devpassword" | chpasswd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
# Nice terminal prompt + welcome message
|
| 28 |
+
RUN echo 'export PS1="\[\033[1;32m\]\u@hf-space\[\033[0m\]:\[\033[1;34m\]\w\[\033[0m\]\$ "' \
|
| 29 |
+
>> /home/user/.bashrc && \
|
| 30 |
+
echo 'echo "🟢 Welcome to your HF Dev Space!"' \
|
| 31 |
+
>> /home/user/.bashrc
|
| 32 |
|
| 33 |
WORKDIR /app
|
| 34 |
COPY . /app
|
|
|
|
| 36 |
COPY entrypoint.sh /entrypoint.sh
|
| 37 |
RUN chmod +x /entrypoint.sh
|
| 38 |
|
|
|
|
| 39 |
EXPOSE 7860
|
| 40 |
|
| 41 |
+
CMD ["/entrypoint.sh"]
|
entrypoint.sh
CHANGED
|
@@ -1,84 +1,18 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# 2. Start gsocket to expose sshd over the gsocket network
|
| 20 |
-
# Connect to it from anywhere with:
|
| 21 |
-
# gsocket -s mypass ssh user@gsocket
|
| 22 |
-
# ------------------------------------------------------------------------------
|
| 23 |
-
echo "[*] Starting gsocket tunnel for SSH (passkey: mypass)..."
|
| 24 |
-
gs-netcat -s mypass -l -e /usr/sbin/sshd &
|
| 25 |
-
GSOCKET_PID=$!
|
| 26 |
-
|
| 27 |
-
# ------------------------------------------------------------------------------
|
| 28 |
-
# 3. Start code-server (VS Code) on port 8080 (internal, optional)
|
| 29 |
-
# ------------------------------------------------------------------------------
|
| 30 |
-
echo "[*] Starting code-server on port 8080..."
|
| 31 |
-
code-server --bind-addr 0.0.0.0:8080 --auth none /app &
|
| 32 |
-
|
| 33 |
-
# ------------------------------------------------------------------------------
|
| 34 |
-
# 4. CRITICAL: Serve HTTP on port 7860
|
| 35 |
-
# Hugging Face Spaces REQUIRES port 7860 to respond with HTTP.
|
| 36 |
-
# Without this the Space shows as "unhealthy" and gets killed.
|
| 37 |
-
# This page also shows connection instructions.
|
| 38 |
-
# ------------------------------------------------------------------------------
|
| 39 |
-
echo "[*] Starting HTTP status page on port 7860..."
|
| 40 |
-
python3 - <<'PYEOF' &
|
| 41 |
-
import http.server, socketserver, os
|
| 42 |
-
|
| 43 |
-
HTML = """<!DOCTYPE html>
|
| 44 |
-
<html>
|
| 45 |
-
<head><title>Dev Space</title>
|
| 46 |
-
<style>
|
| 47 |
-
body { font-family: monospace; background: #1e1e2e; color: #cdd6f4; padding: 2em; }
|
| 48 |
-
h1 { color: #89b4fa; }
|
| 49 |
-
code { background: #313244; padding: 2px 8px; border-radius: 4px; }
|
| 50 |
-
pre { background: #313244; padding: 1em; border-radius: 8px; }
|
| 51 |
-
</style>
|
| 52 |
-
</head>
|
| 53 |
-
<body>
|
| 54 |
-
<h1>🟢 Dev Space is Running</h1>
|
| 55 |
-
<p>Connect via gsocket SSH from any machine:</p>
|
| 56 |
-
<pre>gsocket -s mypass ssh user@localhost</pre>
|
| 57 |
-
<p>Or connect to VS Code:</p>
|
| 58 |
-
<pre>code-server is on internal port 8080</pre>
|
| 59 |
-
</body>
|
| 60 |
-
</html>"""
|
| 61 |
-
|
| 62 |
-
class Handler(http.server.BaseHTTPRequestHandler):
|
| 63 |
-
def do_GET(self):
|
| 64 |
-
self.send_response(200)
|
| 65 |
-
self.send_header("Content-Type", "text/html")
|
| 66 |
-
self.end_headers()
|
| 67 |
-
self.wfile.write(HTML.encode())
|
| 68 |
-
def log_message(self, *args):
|
| 69 |
-
pass # suppress access logs
|
| 70 |
-
|
| 71 |
-
with socketserver.TCPServer(("", 7860), Handler) as httpd:
|
| 72 |
-
print("[*] HTTP status page serving on port 7860")
|
| 73 |
-
httpd.serve_forever()
|
| 74 |
-
PYEOF
|
| 75 |
-
|
| 76 |
-
HTTP_PID=$!
|
| 77 |
-
|
| 78 |
-
# ------------------------------------------------------------------------------
|
| 79 |
-
# 5. Keep the container alive — wait on gsocket
|
| 80 |
-
# ------------------------------------------------------------------------------
|
| 81 |
-
echo "[*] All services started. Space is ready."
|
| 82 |
-
echo " - SSH via gsocket: gsocket -s mypass ssh user@localhost"
|
| 83 |
-
echo " - HTTP status page: http://<your-space>.hf.space"
|
| 84 |
-
wait $GSOCKET_PID
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
+
echo "[*] Starting ttyd browser terminal on port 7860..."
|
| 5 |
+
|
| 6 |
+
# ttyd flags:
|
| 7 |
+
# -p 7860 → listen on HF's required port
|
| 8 |
+
# -W → allow clients to write (not read-only)
|
| 9 |
+
# -t fontSize=16 → slightly larger font for comfort
|
| 10 |
+
# -t theme=... → dark theme
|
| 11 |
+
# --writable → enable keyboard input
|
| 12 |
+
# su - user → drop into the non-root user shell
|
| 13 |
+
exec ttyd \
|
| 14 |
+
--port 7860 \
|
| 15 |
+
--writable \
|
| 16 |
+
-t fontSize=16 \
|
| 17 |
+
-t 'theme={"background":"#1e1e2e","foreground":"#cdd6f4","cursor":"#f5c2e7","black":"#45475a","red":"#f38ba8","green":"#a6e3a1","yellow":"#f9e2af","blue":"#89b4fa","magenta":"#cba6f7","cyan":"#89dceb","white":"#bac2de"}' \
|
| 18 |
+
su - user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|