# Multi-stage build for MEV Bot V2 # Stage 1: Build FROM golang:1.21-alpine AS builder # Install build dependencies RUN apk add --no-cache git make gcc musl-dev linux-headers # Set working directory WORKDIR /build # Copy go mod files COPY go.mod go.sum ./ # Download dependencies RUN go mod download # Copy source code COPY . . # Update go.sum with all dependencies RUN go mod tidy # Build the application RUN go build -o mev-bot-v2 -ldflags="-w -s" ./cmd/mev-bot-v2 # Stage 2: Runtime FROM alpine:latest # Install runtime dependencies RUN apk add --no-cache ca-certificates tzdata # Create non-root user RUN addgroup -g 1000 mevbot && \ adduser -D -u 1000 -G mevbot mevbot # Set working directory WORKDIR /app # Copy binary from builder COPY --from=builder /build/mev-bot-v2 . # Create directories RUN mkdir -p /app/logs /app/data && \ chown -R mevbot:mevbot /app # Switch to non-root user USER mevbot # Expose metrics port EXPOSE 9090 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:9090/metrics || exit 1 # Run the application ENTRYPOINT ["/app/mev-bot-v2"]