-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (45 loc) · 1.4 KB
/
Copy pathDockerfile
File metadata and controls
63 lines (45 loc) · 1.4 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
# Build stage
FROM golang:1.25-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git make
# Set working directory
WORKDIR /app
# Copy go mod files first for better caching
COPY go.mod go.sum ./
RUN go mod download
# Copy source code
COPY . .
# Build the binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /broker .
# Runtime stage
FROM alpine:3.19
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata
# Create non-root user for security
RUN addgroup -g 1000 broker && \
adduser -u 1000 -G broker -s /bin/sh -D broker
# Create data directory
RUN mkdir -p /data && chown -R broker:broker /data
# Copy binary from builder
COPY --from=builder /broker /usr/local/bin/broker
# Set ownership
RUN chown broker:broker /usr/local/bin/broker
# Switch to non-root user
USER broker
# Expose ports
# 8080: gRPC client API
# 9080: Raft controller communication
# 9180: Inter-broker replication
# 9090: Prometheus metrics
EXPOSE 8080 9080 9180 9090
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget -qO- http://localhost:9090/health || exit 1
# Data volume
VOLUME ["/data"]
# Run from / so the default data dir (data/<node-id>) lands in the volume
WORKDIR /
# Entry point
ENTRYPOINT ["/usr/local/bin/broker"]
# Default arguments (can be overridden)
CMD ["-id", "broker-1", "-data-dir", "/data/broker-1"]