# --- Stage 1: Build remotemoe --- FROM golang:1.21-alpine AS builder RUN apk add --no-cache git WORKDIR /app # Copy dependency files and source COPY go.mod go.sum ./ RUN go mod download COPY . . # Build statically RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go # --- Stage 2: Runtime --- FROM alpine:latest # Install sslh (multiplexer) and supervisor (process manager) RUN apk add --no-cache sslh supervisor ca-certificates WORKDIR /root/ # Copy binary from builder COPY --from=builder /app/remotemoe . # Create directories RUN mkdir -p /etc/remotemoe /var/log/supervisor # 1. Configure Supervisor # This runs both remotemoe and sslh at the same time RUN echo "[supervisord]" > /etc/supervisord.conf && \ echo "nodaemon=true" >> /etc/supervisord.conf && \ echo "" >> /etc/supervisord.conf && \ echo "[program:remotemoe]" >> /etc/supervisord.conf && \ echo "command=/root/remotemoe --ssh-addr :2222 --http-addr :8080" >> /etc/supervisord.conf && \ echo "stdout_logfile=/dev/stdout" >> /etc/supervisord.conf && \ echo "stdout_logfile_maxbytes=0" >> /etc/supervisord.conf && \ echo "stderr_logfile=/dev/stderr" >> /etc/supervisord.conf && \ echo "stderr_logfile_maxbytes=0" >> /etc/supervisord.conf && \ echo "" >> /etc/supervisord.conf && \ echo "[program:sslh]" >> /etc/supervisord.conf && \ echo "# Listen on 7860, forward SSH to 2222, HTTP to 8080" >> /etc/supervisord.conf && \ echo "command=sslh -f -u root -p 0.0.0.0:7860 --ssh 127.0.0.1:2222 --http 127.0.0.1:8080" >> /etc/supervisord.conf && \ echo "stdout_logfile=/dev/stdout" >> /etc/supervisord.conf && \ echo "stdout_logfile_maxbytes=0" >> /etc/supervisord.conf && \ echo "stderr_logfile=/dev/stderr" >> /etc/supervisord.conf && \ echo "stderr_logfile_maxbytes=0" >> /etc/supervisord.conf # Expose the HF App Port EXPOSE 7860 # Start Supervisor (which starts the other two) CMD ["supervisord", "-c", "/etc/supervisord.conf"]