Greg-House commited on
Commit
471b659
·
verified ·
1 Parent(s): 4446181

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +28 -44
Dockerfile CHANGED
@@ -1,35 +1,24 @@
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
 
22
- # Create a non-root user
23
  RUN adduser -D -u 1000 appuser
24
-
25
  WORKDIR /home/appuser
26
 
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; \
@@ -56,14 +45,16 @@ http { \
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; \
62
  proxy_set_header Upgrade $http_upgrade; \
63
  proxy_set_header Connection $connection_upgrade; \
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,36 +63,29 @@ http { \
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"]
 
1
+ # --- Stage 1: Runtime ---
 
 
 
 
 
 
 
 
 
 
 
2
  FROM alpine:latest
3
 
4
+ # Install Nginx, Curl, and Supervisor
5
+ RUN apk add --no-cache nginx curl supervisor
6
 
7
+ # --- Install Chisel ---
8
+ # We download the official binary (Arch: amd64 for HF Spaces)
9
+ RUN curl -L -o /tmp/chisel.gz https://github.com/jpillora/chisel/releases/download/v1.9.1/chisel_1.9.1_linux_amd64.gz \
10
+ && gzip -d /tmp/chisel.gz \
11
+ && mv /tmp/chisel /usr/bin/chisel \
12
+ && chmod +x /usr/bin/chisel
13
 
14
+ # Create a non-root user (Required for HF)
15
  RUN adduser -D -u 1000 appuser
 
16
  WORKDIR /home/appuser
17
 
18
+ # --- CONFIGURATION ---
 
19
 
20
+ # 1. Nginx Config
21
+ # This splits traffic: Normal users go to port 8080 (Your App), Tunnel goes to 7777 (Chisel)
 
22
  RUN echo ' \
23
  worker_processes auto; \
24
  daemon off; \
 
45
  server { \
46
  listen 7860 default_server; \
47
  \
48
+ # 1. The Chisel Tunnel Endpoint \
49
+ location /_tunnel { \
50
+ proxy_pass http://127.0.0.1:7777/; \
51
  proxy_http_version 1.1; \
52
  proxy_set_header Upgrade $http_upgrade; \
53
  proxy_set_header Connection $connection_upgrade; \
54
  proxy_read_timeout 86400; \
55
  } \
56
  \
57
+ # 2. The Public View (Your Local App) \
58
  location / { \
59
  proxy_pass http://127.0.0.1:8080; \
60
  proxy_set_header Host $host; \
 
63
  } \
64
  } ' > /home/appuser/nginx.conf
65
 
66
+ # 2. Start Script
67
+ # Runs Nginx and Chisel Server
68
  RUN echo "#!/bin/sh" > start.sh && \
69
+ echo "echo '--- Starting Chisel Server ---'" >> start.sh && \
70
+ echo "# --reverse allows clients to expose ports" >> start.sh && \
71
+ echo "chisel server --port 7777 --reverse &" >> start.sh && \
72
+ echo "echo '--- Starting Nginx ---'" >> start.sh && \
 
 
 
 
 
73
  echo "nginx -c /home/appuser/nginx.conf &" >> start.sh && \
74
+ echo "echo '--- Running ---'" >> start.sh && \
75
+ echo "tail -f /dev/null" >> start.sh && \
76
  chmod +x start.sh
77
 
78
+ # 3. Permissions
79
  RUN mkdir -p /home/appuser/client_body_temp \
80
  /home/appuser/proxy_temp \
81
  /home/appuser/fastcgi_temp \
82
  /home/appuser/uwsgi_temp \
83
  /home/appuser/scgi_temp \
84
+ && chown -R appuser:appuser /home/appuser \
 
85
  && chmod -R 777 /home/appuser
86
 
87
+ # Switch User
88
  USER appuser
89
 
90
  EXPOSE 7860
 
91
  CMD ["./start.sh"]