Greg-House commited on
Commit
e9d67cd
·
verified ·
1 Parent(s): a237db9

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +121 -0
Dockerfile ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"]