-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
66 lines (48 loc) · 1.46 KB
/
Dockerfile
File metadata and controls
66 lines (48 loc) · 1.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
# Build stage
FROM golang:1.21-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 -X main.Version=$(git describe --tags --always --dirty 2>/dev/null || echo 'dev')" \
-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"]
# Default environment variables
ENV BROKER_DATA_DIR=/data \
BROKER_LOG_LEVEL=info
# Entry point
ENTRYPOINT ["/usr/local/bin/broker"]
# Default arguments (can be overridden)
CMD ["-id", "broker-1"]