Spaces:
Paused
Paused
| # --- Stage 1: Build remotemoe --- | |
| FROM golang:1.21-alpine AS builder | |
| RUN apk add --no-cache git | |
| WORKDIR /app | |
| # Clone the repo | |
| RUN git clone https://github.com/fasmide/remotemoe.git . | |
| RUN go mod download | |
| # Build statically | |
| RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go | |
| # --- Stage 2: Runtime --- | |
| FROM alpine:latest | |
| # Install Nginx, Curl, and OpenSSH (needed for key generation) | |
| RUN apk add --no-cache nginx curl openssh-client | |
| # Install websocat | |
| RUN curl -L -o /usr/bin/websocat https://github.com/vi/websocat/releases/download/v1.13.0/websocat.x86_64-unknown-linux-musl \ | |
| && chmod +x /usr/bin/websocat | |
| # Create a non-root user | |
| RUN adduser -D -u 1000 appuser | |
| WORKDIR /home/appuser | |
| # Copy binary | |
| COPY --from=builder /app/remotemoe . | |
| # --- SETUP CONFIGURATION --- | |
| # 1. Create Nginx Config (Writes to /home/appuser to avoid permission issues) | |
| RUN echo ' \ | |
| worker_processes auto; \ | |
| daemon off; \ | |
| pid /home/appuser/nginx.pid; \ | |
| error_log /dev/stderr info; \ | |
| \ | |
| events { \ | |
| worker_connections 1024; \ | |
| } \ | |
| \ | |
| http { \ | |
| access_log /dev/stdout; \ | |
| client_body_temp_path /home/appuser/client_body_temp; \ | |
| proxy_temp_path /home/appuser/proxy_temp; \ | |
| fastcgi_temp_path /home/appuser/fastcgi_temp; \ | |
| uwsgi_temp_path /home/appuser/uwsgi_temp; \ | |
| scgi_temp_path /home/appuser/scgi_temp; \ | |
| \ | |
| map $http_upgrade $connection_upgrade { \ | |
| default upgrade; \ | |
| "" close; \ | |
| } \ | |
| \ | |
| server { \ | |
| listen 7860 default_server; \ | |
| \ | |
| location /ssh { \ | |
| proxy_pass http://127.0.0.1:9999; \ | |
| proxy_http_version 1.1; \ | |
| proxy_set_header Upgrade $http_upgrade; \ | |
| proxy_set_header Connection $connection_upgrade; \ | |
| proxy_read_timeout 86400; \ | |
| } \ | |
| \ | |
| location / { \ | |
| proxy_pass http://127.0.0.1:8080; \ | |
| proxy_set_header Host $host; \ | |
| proxy_set_header X-Real-IP $remote_addr; \ | |
| } \ | |
| } \ | |
| } ' > /home/appuser/nginx.conf | |
| # 2. Create the Start Script | |
| # We add "|| true" to commands so the container doesn't crash if one fails | |
| RUN echo "#!/bin/sh" > start.sh && \ | |
| echo "echo '--- Starting Container ---'" >> start.sh && \ | |
| echo "echo '1. Generating SSH Host Keys (if needed)...'" >> start.sh && \ | |
| echo "ssh-keygen -A || echo 'Skipping system keys'" >> start.sh && \ | |
| echo "echo '2. Starting remotemoe...'" >> start.sh && \ | |
| echo "./remotemoe --ssh-addr :2222 --http-addr :8080 > remotemoe.log 2>&1 &" >> start.sh && \ | |
| echo "sleep 2" >> start.sh && \ | |
| echo "echo '3. Starting websocat...'" >> start.sh && \ | |
| echo "websocat --binary --exit-on-eof -s 9999 tcp:127.0.0.1:2222 > websocat.log 2>&1 &" >> start.sh && \ | |
| echo "echo '4. Starting Nginx...'" >> start.sh && \ | |
| echo "nginx -c /home/appuser/nginx.conf &" >> start.sh && \ | |
| echo "echo '--- Setup Complete. Tailing logs ---'" >> start.sh && \ | |
| echo "tail -f remotemoe.log websocat.log" >> start.sh && \ | |
| chmod +x start.sh | |
| # 3. Create necessary directories and FORCE permissions | |
| RUN mkdir -p /home/appuser/client_body_temp \ | |
| /home/appuser/proxy_temp \ | |
| /home/appuser/fastcgi_temp \ | |
| /home/appuser/uwsgi_temp \ | |
| /home/appuser/scgi_temp \ | |
| /etc/remotemoe \ | |
| && chown -R appuser:appuser /home/appuser /etc/remotemoe \ | |
| && chmod -R 777 /home/appuser | |
| # Switch to non-root user | |
| USER appuser | |
| EXPOSE 7860 | |
| CMD ["./start.sh"] |