Spaces:
Paused
Paused
Update Dockerfile
Browse files- Dockerfile +72 -29
Dockerfile
CHANGED
|
@@ -1,78 +1,121 @@
|
|
| 1 |
# --- Stage 1: Build remotemoe ---
|
| 2 |
FROM golang:1.21-alpine AS builder
|
|
|
|
|
|
|
| 3 |
RUN apk add --no-cache git
|
|
|
|
| 4 |
WORKDIR /app
|
|
|
|
|
|
|
| 5 |
RUN git clone https://github.com/fasmide/remotemoe.git .
|
| 6 |
RUN go mod download
|
|
|
|
|
|
|
| 7 |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go
|
| 8 |
|
| 9 |
# --- Stage 2: Runtime ---
|
| 10 |
FROM alpine:latest
|
| 11 |
|
| 12 |
-
# Install Nginx, Supervisor, and
|
| 13 |
RUN apk add --no-cache nginx supervisor curl
|
| 14 |
|
| 15 |
-
# Install websocat (
|
| 16 |
RUN curl -L -o /usr/bin/websocat https://github.com/vi/websocat/releases/download/v1.13.0/websocat.x86_64-unknown-linux-musl \
|
| 17 |
&& chmod +x /usr/bin/websocat
|
| 18 |
|
| 19 |
-
# Create user
|
| 20 |
RUN adduser -D -u 1000 appuser
|
|
|
|
| 21 |
WORKDIR /home/appuser
|
|
|
|
|
|
|
| 22 |
COPY --from=builder /app/remotemoe .
|
| 23 |
|
| 24 |
-
# ---
|
| 25 |
|
| 26 |
-
# 1. Nginx
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
\
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
proxy_http_version 1.1; \
|
| 35 |
-
proxy_set_header Upgrade $http_upgrade; \
|
| 36 |
-
proxy_set_header Connection "Upgrade"; \
|
| 37 |
-
proxy_read_timeout 86400; \
|
| 38 |
} \
|
| 39 |
\
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
} \
|
| 46 |
-
} ' > /
|
| 47 |
|
| 48 |
-
# 2.
|
| 49 |
-
# We run 3 services: Nginx (Front), Websocat (Bridge), Remotemoe (App)
|
| 50 |
RUN mkdir -p /etc/supervisor.d/ && echo ' \
|
| 51 |
[supervisord] \
|
| 52 |
nodaemon=true \
|
| 53 |
-
logfile=/
|
| 54 |
-
pidfile=/
|
| 55 |
\
|
| 56 |
[program:remotemoe] \
|
| 57 |
command=/home/appuser/remotemoe --ssh-addr :2222 --http-addr :8080 \
|
| 58 |
stdout_logfile=/dev/stdout \
|
| 59 |
stderr_logfile=/dev/stderr \
|
|
|
|
| 60 |
\
|
| 61 |
[program:websocat] \
|
| 62 |
-
# Listen on 9999, unwrap WebSocket, forward to SSH port 2222 \
|
| 63 |
command=/usr/bin/websocat --binary --exit-on-eof -s 9999 tcp:127.0.0.1:2222 \
|
| 64 |
stdout_logfile=/dev/stdout \
|
| 65 |
stderr_logfile=/dev/stderr \
|
| 66 |
\
|
| 67 |
[program:nginx] \
|
| 68 |
-
command=nginx -
|
| 69 |
stdout_logfile=/dev/stdout \
|
| 70 |
stderr_logfile=/dev/stderr \
|
| 71 |
' > /etc/supervisord.conf
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
RUN
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
USER appuser
|
| 76 |
|
|
|
|
| 77 |
EXPOSE 7860
|
|
|
|
|
|
|
| 78 |
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
|
|
|
|
| 1 |
# --- Stage 1: Build remotemoe ---
|
| 2 |
FROM golang:1.21-alpine AS builder
|
| 3 |
+
|
| 4 |
+
# Install git
|
| 5 |
RUN apk add --no-cache git
|
| 6 |
+
|
| 7 |
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
# Clone the repo
|
| 10 |
RUN git clone https://github.com/fasmide/remotemoe.git .
|
| 11 |
RUN go mod download
|
| 12 |
+
|
| 13 |
+
# Build statically
|
| 14 |
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go
|
| 15 |
|
| 16 |
# --- Stage 2: Runtime ---
|
| 17 |
FROM alpine:latest
|
| 18 |
|
| 19 |
+
# Install Nginx, Supervisor, and curl
|
| 20 |
RUN apk add --no-cache nginx supervisor curl
|
| 21 |
|
| 22 |
+
# Install websocat (Bridge for SSH over WebSocket)
|
| 23 |
RUN curl -L -o /usr/bin/websocat https://github.com/vi/websocat/releases/download/v1.13.0/websocat.x86_64-unknown-linux-musl \
|
| 24 |
&& chmod +x /usr/bin/websocat
|
| 25 |
|
| 26 |
+
# Create a non-root user
|
| 27 |
RUN adduser -D -u 1000 appuser
|
| 28 |
+
|
| 29 |
WORKDIR /home/appuser
|
| 30 |
+
|
| 31 |
+
# Copy binary
|
| 32 |
COPY --from=builder /app/remotemoe .
|
| 33 |
|
| 34 |
+
# --- CONFIGURATION SECTION ---
|
| 35 |
|
| 36 |
+
# 1. Create a custom Nginx Config (Non-root compliant)
|
| 37 |
+
# We write this to the user's home directory to avoid permission errors in /etc/nginx
|
| 38 |
+
RUN echo ' \
|
| 39 |
+
worker_processes auto; \
|
| 40 |
+
daemon off; \
|
| 41 |
+
pid /home/appuser/nginx.pid; \
|
| 42 |
+
error_log /home/appuser/nginx_error.log warn; \
|
| 43 |
+
\
|
| 44 |
+
events { \
|
| 45 |
+
worker_connections 1024; \
|
| 46 |
+
} \
|
| 47 |
+
\
|
| 48 |
+
http { \
|
| 49 |
+
access_log /home/appuser/nginx_access.log; \
|
| 50 |
+
client_body_temp_path /home/appuser/client_body_temp; \
|
| 51 |
+
proxy_temp_path /home/appuser/proxy_temp; \
|
| 52 |
+
fastcgi_temp_path /home/appuser/fastcgi_temp; \
|
| 53 |
+
uwsgi_temp_path /home/appuser/uwsgi_temp; \
|
| 54 |
+
scgi_temp_path /home/appuser/scgi_temp; \
|
| 55 |
\
|
| 56 |
+
map $http_upgrade $connection_upgrade { \
|
| 57 |
+
default upgrade; \
|
| 58 |
+
"" close; \
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
} \
|
| 60 |
\
|
| 61 |
+
server { \
|
| 62 |
+
listen 7860 default_server; \
|
| 63 |
+
\
|
| 64 |
+
# Route 1: SSH Tunnel via WebSocket \
|
| 65 |
+
location /ssh { \
|
| 66 |
+
proxy_pass http://127.0.0.1:9999; \
|
| 67 |
+
proxy_http_version 1.1; \
|
| 68 |
+
proxy_set_header Upgrade $http_upgrade; \
|
| 69 |
+
proxy_set_header Connection $connection_upgrade; \
|
| 70 |
+
proxy_read_timeout 86400; \
|
| 71 |
+
} \
|
| 72 |
+
\
|
| 73 |
+
# Route 2: Web Dashboard \
|
| 74 |
+
location / { \
|
| 75 |
+
proxy_pass http://127.0.0.1:8080; \
|
| 76 |
+
proxy_set_header Host $host; \
|
| 77 |
+
proxy_set_header X-Real-IP $remote_addr; \
|
| 78 |
+
} \
|
| 79 |
} \
|
| 80 |
+
} ' > /home/appuser/nginx.conf
|
| 81 |
|
| 82 |
+
# 2. Configure Supervisor
|
|
|
|
| 83 |
RUN mkdir -p /etc/supervisor.d/ && echo ' \
|
| 84 |
[supervisord] \
|
| 85 |
nodaemon=true \
|
| 86 |
+
logfile=/home/appuser/supervisord.log \
|
| 87 |
+
pidfile=/home/appuser/supervisord.pid \
|
| 88 |
\
|
| 89 |
[program:remotemoe] \
|
| 90 |
command=/home/appuser/remotemoe --ssh-addr :2222 --http-addr :8080 \
|
| 91 |
stdout_logfile=/dev/stdout \
|
| 92 |
stderr_logfile=/dev/stderr \
|
| 93 |
+
directory=/home/appuser \
|
| 94 |
\
|
| 95 |
[program:websocat] \
|
|
|
|
| 96 |
command=/usr/bin/websocat --binary --exit-on-eof -s 9999 tcp:127.0.0.1:2222 \
|
| 97 |
stdout_logfile=/dev/stdout \
|
| 98 |
stderr_logfile=/dev/stderr \
|
| 99 |
\
|
| 100 |
[program:nginx] \
|
| 101 |
+
command=nginx -c /home/appuser/nginx.conf \
|
| 102 |
stdout_logfile=/dev/stdout \
|
| 103 |
stderr_logfile=/dev/stderr \
|
| 104 |
' > /etc/supervisord.conf
|
| 105 |
|
| 106 |
+
# 3. Create necessary temp directories and set permissions
|
| 107 |
+
RUN mkdir -p /home/appuser/client_body_temp \
|
| 108 |
+
/home/appuser/proxy_temp \
|
| 109 |
+
/home/appuser/fastcgi_temp \
|
| 110 |
+
/home/appuser/uwsgi_temp \
|
| 111 |
+
/home/appuser/scgi_temp \
|
| 112 |
+
&& chown -R appuser:appuser /home/appuser
|
| 113 |
+
|
| 114 |
+
# Switch to non-root user
|
| 115 |
USER appuser
|
| 116 |
|
| 117 |
+
# Expose the HF App Port
|
| 118 |
EXPOSE 7860
|
| 119 |
+
|
| 120 |
+
# Start Supervisor
|
| 121 |
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
|