Greg-House commited on
Commit
c6e324f
·
verified ·
1 Parent(s): f8ac40b

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +29 -30
Dockerfile CHANGED
@@ -1,53 +1,52 @@
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
 
7
- # Copy dependency files and source
8
  COPY go.mod go.sum ./
9
  RUN go mod download
10
- COPY . .
11
 
 
 
12
  # Build statically
13
  RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go
14
 
15
  # --- Stage 2: Runtime ---
16
  FROM alpine:latest
17
 
18
- # Install sslh (multiplexer) and supervisor (process manager)
19
- RUN apk add --no-cache sslh supervisor ca-certificates
20
 
21
- WORKDIR /root/
 
22
 
23
- # Copy binary from builder
 
 
24
  COPY --from=builder /app/remotemoe .
25
 
26
- # Create directories
27
- RUN mkdir -p /etc/remotemoe /var/log/supervisor
28
-
29
- # 1. Configure Supervisor
30
- # This runs both remotemoe and sslh at the same time
31
- RUN echo "[supervisord]" > /etc/supervisord.conf && \
32
- echo "nodaemon=true" >> /etc/supervisord.conf && \
33
- echo "" >> /etc/supervisord.conf && \
34
- echo "[program:remotemoe]" >> /etc/supervisord.conf && \
35
- echo "command=/root/remotemoe --ssh-addr :2222 --http-addr :8080" >> /etc/supervisord.conf && \
36
- echo "stdout_logfile=/dev/stdout" >> /etc/supervisord.conf && \
37
- echo "stdout_logfile_maxbytes=0" >> /etc/supervisord.conf && \
38
- echo "stderr_logfile=/dev/stderr" >> /etc/supervisord.conf && \
39
- echo "stderr_logfile_maxbytes=0" >> /etc/supervisord.conf && \
40
- echo "" >> /etc/supervisord.conf && \
41
- echo "[program:sslh]" >> /etc/supervisord.conf && \
42
- echo "# Listen on 7860, forward SSH to 2222, HTTP to 8080" >> /etc/supervisord.conf && \
43
- 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 && \
44
- echo "stdout_logfile=/dev/stdout" >> /etc/supervisord.conf && \
45
- echo "stdout_logfile_maxbytes=0" >> /etc/supervisord.conf && \
46
- echo "stderr_logfile=/dev/stderr" >> /etc/supervisord.conf && \
47
- echo "stderr_logfile_maxbytes=0" >> /etc/supervisord.conf
48
 
49
  # Expose the HF App Port
50
  EXPOSE 7860
51
 
52
- # Start Supervisor (which starts the other two)
53
- CMD ["supervisord", "-c", "/etc/supervisord.conf"]
 
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
+ # Copy dependency files and download
10
  COPY go.mod go.sum ./
11
  RUN go mod download
 
12
 
13
+ # Copy source and build
14
+ COPY . .
15
  # Build statically
16
  RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o remotemoe main.go
17
 
18
  # --- Stage 2: Runtime ---
19
  FROM alpine:latest
20
 
21
+ # Install sslh (multiplexer) and ca-certificates
22
+ RUN apk add --no-cache sslh ca-certificates
23
 
24
+ # Create a non-root user with ID 1000
25
+ RUN adduser -D -u 1000 appuser
26
 
27
+ WORKDIR /home/appuser
28
+
29
+ # Copy the binary
30
  COPY --from=builder /app/remotemoe .
31
 
32
+ # Create a start script
33
+ RUN echo "#!/bin/sh" > start.sh && \
34
+ echo "echo 'Starting remotemoe...'" >> start.sh && \
35
+ echo "./remotemoe --ssh-addr :2222 --http-addr :8080 &" >> start.sh && \
36
+ echo "echo 'Waiting for remotemoe to initialize...'" >> start.sh && \
37
+ echo "sleep 2" >> start.sh && \
38
+ echo "echo 'Starting sslh on port 7860...'" >> start.sh && \
39
+ echo "exec sslh -f -v -p 0.0.0.0:7860 --ssh 127.0.0.1:2222 --http 127.0.0.1:8080" >> start.sh && \
40
+ chmod +x start.sh
41
+
42
+ # Fix permissions so the non-root user can write SSH keys and logs
43
+ RUN chown -R appuser:appuser /home/appuser
44
+
45
+ # Switch to non-root user
46
+ USER appuser
 
 
 
 
 
 
 
47
 
48
  # Expose the HF App Port
49
  EXPOSE 7860
50
 
51
+ # Run the script
52
+ CMD ["./start.sh"]