43 lines
841 B
Docker
43 lines
841 B
Docker
# Build stage
|
|
FROM golang:1.25.3-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy go mod files and download dependencies
|
|
COPY go.mod go.sum ./
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build binary
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o keenetic-exporter main.go
|
|
|
|
# Runtime stage
|
|
FROM alpine:latest
|
|
|
|
# Install ca-certificates for HTTPS requests
|
|
RUN apk --no-cache add ca-certificates tzdata
|
|
|
|
# Create non-root user
|
|
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /app/keenetic-exporter .
|
|
|
|
# Copy default config
|
|
COPY config.default.yaml .
|
|
|
|
# Change ownership to non-root user
|
|
RUN chown -R appuser:appgroup /app
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Expose prometheus metrics port
|
|
EXPOSE 9090
|
|
|
|
# Run the exporter
|
|
CMD ["./keenetic-exporter"] |