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

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -43
Dockerfile CHANGED
@@ -1,25 +1,21 @@
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
 
@@ -31,22 +27,21 @@ WORKDIR /home/appuser
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; \
@@ -61,7 +56,6 @@ http { \
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; \
@@ -70,7 +64,6 @@ http { \
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; \
@@ -79,43 +72,36 @@ http { \
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"]
 
1
  # --- Stage 1: Build remotemoe ---
2
  FROM golang:1.21-alpine AS builder
3
 
 
4
  RUN apk add --no-cache git
 
5
  WORKDIR /app
 
6
  # Clone the repo
7
  RUN git clone https://github.com/fasmide/remotemoe.git .
8
  RUN go mod download
 
9
  # Build statically
10
  RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go
11
 
12
  # --- Stage 2: Runtime ---
13
  FROM alpine:latest
14
 
15
+ # Install Nginx, Curl, and OpenSSH (needed for key generation)
16
+ RUN apk add --no-cache nginx curl openssh-client
17
 
18
+ # Install websocat
19
  RUN curl -L -o /usr/bin/websocat https://github.com/vi/websocat/releases/download/v1.13.0/websocat.x86_64-unknown-linux-musl \
20
  && chmod +x /usr/bin/websocat
21
 
 
27
  # Copy binary
28
  COPY --from=builder /app/remotemoe .
29
 
30
+ # --- SETUP CONFIGURATION ---
31
 
32
+ # 1. Create Nginx Config (Writes to /home/appuser to avoid permission issues)
 
33
  RUN echo ' \
34
  worker_processes auto; \
35
  daemon off; \
36
  pid /home/appuser/nginx.pid; \
37
+ error_log /dev/stderr info; \
38
  \
39
  events { \
40
  worker_connections 1024; \
41
  } \
42
  \
43
  http { \
44
+ access_log /dev/stdout; \
45
  client_body_temp_path /home/appuser/client_body_temp; \
46
  proxy_temp_path /home/appuser/proxy_temp; \
47
  fastcgi_temp_path /home/appuser/fastcgi_temp; \
 
56
  server { \
57
  listen 7860 default_server; \
58
  \
 
59
  location /ssh { \
60
  proxy_pass http://127.0.0.1:9999; \
61
  proxy_http_version 1.1; \
 
64
  proxy_read_timeout 86400; \
65
  } \
66
  \
 
67
  location / { \
68
  proxy_pass http://127.0.0.1:8080; \
69
  proxy_set_header Host $host; \
 
72
  } \
73
  } ' > /home/appuser/nginx.conf
74
 
75
+ # 2. Create the Start Script
76
+ # We add "|| true" to commands so the container doesn't crash if one fails
77
+ RUN echo "#!/bin/sh" > start.sh && \
78
+ echo "echo '--- Starting Container ---'" >> start.sh && \
79
+ echo "echo '1. Generating SSH Host Keys (if needed)...'" >> start.sh && \
80
+ echo "ssh-keygen -A || echo 'Skipping system keys'" >> start.sh && \
81
+ echo "echo '2. Starting remotemoe...'" >> start.sh && \
82
+ echo "./remotemoe --ssh-addr :2222 --http-addr :8080 > remotemoe.log 2>&1 &" >> start.sh && \
83
+ echo "sleep 2" >> start.sh && \
84
+ echo "echo '3. Starting websocat...'" >> start.sh && \
85
+ echo "websocat --binary --exit-on-eof -s 9999 tcp:127.0.0.1:2222 > websocat.log 2>&1 &" >> start.sh && \
86
+ echo "echo '4. Starting Nginx...'" >> start.sh && \
87
+ echo "nginx -c /home/appuser/nginx.conf &" >> start.sh && \
88
+ echo "echo '--- Setup Complete. Tailing logs ---'" >> start.sh && \
89
+ echo "tail -f remotemoe.log websocat.log" >> start.sh && \
90
+ chmod +x start.sh
91
+
92
+ # 3. Create necessary directories and FORCE permissions
 
 
 
 
 
 
 
93
  RUN mkdir -p /home/appuser/client_body_temp \
94
  /home/appuser/proxy_temp \
95
  /home/appuser/fastcgi_temp \
96
  /home/appuser/uwsgi_temp \
97
  /home/appuser/scgi_temp \
98
+ /etc/remotemoe \
99
+ && chown -R appuser:appuser /home/appuser /etc/remotemoe \
100
+ && chmod -R 777 /home/appuser
101
 
102
  # Switch to non-root user
103
  USER appuser
104
 
 
105
  EXPOSE 7860
106
 
107
+ CMD ["./start.sh"]