-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.agent.optimized
More file actions
61 lines (52 loc) · 1.96 KB
/
Dockerfile.agent.optimized
File metadata and controls
61 lines (52 loc) · 1.96 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
# Multi-stage Docker build for optimized ChaosLab Agent
# This Dockerfile implements best practices for build speed, security, and size optimization
# Build cache stage - reused across builds for faster iterations
FROM golang:1.24-alpine AS build-cache
WORKDIR /build-cache
# Install build dependencies and cache them
RUN apk add --no-cache git ca-certificates tzdata make
# Pre-download common Go modules to cache layer
COPY agent/go.mod agent/go.sum ./
RUN go mod download
# Development build stage - optimized for fast rebuilds
FROM build-cache AS development
WORKDIR /app
# Copy source code
COPY agent/ .
# Build with debug info and race detection disabled for faster builds
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-w -s" \
-o agent-dev .
# Production build stage - optimized binary
FROM build-cache AS production
WORKDIR /app
# Copy source code
COPY agent/ .
# Build optimized binary
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-w -s -X main.Version=1.0.0 -X main.BuildTime=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-trimpath \
-o agent .
# Final stage - minimal runtime image
FROM alpine:3.23 AS runtime
RUN apk --no-cache add ca-certificates tzdata wget
WORKDIR /app
# Create non-root user
RUN addgroup -g 1000 chaoslabs && \
adduser -u 1000 -G chaoslabs -s /bin/sh -D chaoslabs
# Copy binary from production stage
COPY --from=production --chown=1000:1000 /app/agent .
RUN chmod +x ./agent
# Metrics endpoint is always registered; use it as a liveness probe.
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget -qO- http://127.0.0.1:9090/metrics >/dev/null || exit 1
USER 1000:1000
EXPOSE 9090
ENTRYPOINT ["./agent"]
# Debug variant - includes delve debugger
FROM golang:1.24-alpine AS debug
RUN go install github.com/go-delve/delve/cmd/dlv@latest
WORKDIR /app
COPY --from=development /app .
EXPOSE 9090 2346
CMD ["dlv", "--listen=:2346", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "./agent-dev"]