-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDockerfile
More file actions
129 lines (100 loc) · 3.46 KB
/
Dockerfile
File metadata and controls
129 lines (100 loc) · 3.46 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Build stage 1: Frontend
FROM node:20-bookworm-slim AS frontend-builder
WORKDIR /app/frontend
# Copy frontend package files
COPY frontend/package*.json ./
# Install dependencies
RUN npm ci --legacy-peer-deps
# Copy frontend source
COPY frontend/ ./
# Build frontend
RUN npm run build
# Build stage 2: Go binary
FROM golang:1.24-bookworm AS go-builder
# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
git ca-certificates tzdata \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy go mod files first for better caching
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY cmd/ ./cmd/
COPY internal/ ./internal/
COPY assets/ ./assets/
COPY docs/ ./docs/
# Copy built frontend from previous stage
COPY --from=frontend-builder /app/frontend/dist ./assets/frontend/
# Build arguments for multi-platform support
ARG TARGETOS=linux
ARG TARGETARCH
# Build the binary for target platform
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags="-s -w -X main.Version=docker" \
-o /app/web-cli \
./cmd/web-cli
# Final stage: Debian-based runtime for proper bash support
FROM debian:bookworm-slim
# Install required packages:
# - ca-certificates: for HTTPS connections
# - tzdata: for timezone support
# - bash: full bash shell for script execution
# - coreutils: standard Unix utilities
# - curl: for health checks and HTTP operations
# - openssh-client: for SSH connections to remote servers
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
tzdata \
bash \
zsh \
coreutils \
curl \
openssh-client \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean
# Create non-root user for security
# Add user to tty group for PTY access (required for interactive terminal)
RUN groupadd -g 1000 webcli && \
useradd -u 1000 -g webcli -G tty -s /bin/bash -m webcli
# Create data and config directories
RUN mkdir -p /data /config && \
chown -R webcli:webcli /data /config
# Create .ssh directory for SSH key operations
RUN mkdir -p /home/webcli/.ssh && \
chown webcli:webcli /home/webcli/.ssh && \
chmod 700 /home/webcli/.ssh
# Create tmp directory for session files (SSH configs, keys, wrappers)
# This ensures the non-root user can create temp files for terminal sessions
RUN mkdir -p /home/webcli/tmp && \
chown webcli:webcli /home/webcli/tmp && \
chmod 700 /home/webcli/tmp
WORKDIR /app
# Copy binary from builder
COPY --from=go-builder /app/web-cli /app/web-cli
# Copy healthcheck script
COPY scripts/healthcheck.sh /app/healthcheck.sh
# Set ownership
RUN chown webcli:webcli /app/web-cli /app/healthcheck.sh && \
chmod +x /app/healthcheck.sh
# Switch to non-root user
USER webcli
# Expose default port
EXPOSE 7777
# Health check using script (auto-detects http/https based on TLS config)
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
CMD ["/app/healthcheck.sh"]
# Environment variables with defaults
# Note: WEBCLI_ENCRYPTION_KEY_PATH is a file path to the key file, not the secret itself
# TMPDIR is set to user's home for proper temp file creation in non-root context
# hadolint ignore=DL3044
ENV WEBCLI_PORT=7777 \
WEBCLI_HOST=0.0.0.0 \
WEBCLI_DATABASE_PATH=/data/web-cli.db \
WEBCLI_ENCRYPTION_KEY_PATH=/data/.encryption_key \
TMPDIR=/home/webcli/tmp \
SHELL=/bin/bash
# Volume for persistent data
VOLUME ["/data", "/config"]
# Run the application
ENTRYPOINT ["/app/web-cli"]