File size: 1,351 Bytes
f8ac40b
 
 
c6e324f
f8ac40b
c6e324f
f8ac40b
 
c6e324f
f8ac40b
 
 
c6e324f
 
f8ac40b
 
 
 
 
 
c6e324f
 
f8ac40b
c6e324f
 
f8ac40b
c6e324f
 
 
f8ac40b
 
c6e324f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f8ac40b
 
 
 
c6e324f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# --- Stage 1: Build remotemoe ---
FROM golang:1.21-alpine AS builder

# Install git
RUN apk add --no-cache git

WORKDIR /app

# Copy dependency files and download
COPY go.mod go.sum ./
RUN go mod download

# Copy source and build
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 ca-certificates
RUN apk add --no-cache sslh ca-certificates

# Create a non-root user with ID 1000
RUN adduser -D -u 1000 appuser

WORKDIR /home/appuser

# Copy the binary
COPY --from=builder /app/remotemoe .

# Create a start script
RUN echo "#!/bin/sh" > start.sh && \
    echo "echo 'Starting remotemoe...'" >> start.sh && \
    echo "./remotemoe --ssh-addr :2222 --http-addr :8080 &" >> start.sh && \
    echo "echo 'Waiting for remotemoe to initialize...'" >> start.sh && \
    echo "sleep 2" >> start.sh && \
    echo "echo 'Starting sslh on port 7860...'" >> start.sh && \
    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 && \
    chmod +x start.sh

# Fix permissions so the non-root user can write SSH keys and logs
RUN chown -R appuser:appuser /home/appuser

# Switch to non-root user
USER appuser

# Expose the HF App Port
EXPOSE 7860

# Run the script
CMD ["./start.sh"]