build: update dependencies and fix Dockerfile
This commit is contained in:
39
Dockerfile
39
Dockerfile
@@ -1,18 +1,43 @@
|
||||
FROM golang:1.24-alpine AS builder
|
||||
# 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 . .
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o exporter ./cmd/exporter
|
||||
|
||||
# Build binary
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o keenetic-exporter main.go
|
||||
|
||||
# Runtime stage
|
||||
FROM alpine:latest
|
||||
RUN apk --no-cache add ca-certificates
|
||||
WORKDIR /root/
|
||||
|
||||
COPY --from=builder /app/exporter .
|
||||
COPY --from=builder /app/configs ./configs
|
||||
# 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
|
||||
CMD ["./exporter"]
|
||||
|
||||
# Run the exporter
|
||||
CMD ["./keenetic-exporter"]
|
||||
Reference in New Issue
Block a user