forked from treydock/eseries_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
91 lines (66 loc) · 2.38 KB
/
Dockerfile
File metadata and controls
91 lines (66 loc) · 2.38 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# syntax=docker/dockerfile:1
# ============================================
# Stage 1: Linting
# ============================================
FROM golangci/golangci-lint:v1.64-alpine AS linter
WORKDIR /app
COPY go.mod go.sum ./
COPY .golangci.yml ./
COPY cmd/ ./cmd/
COPY internal/ ./internal/
RUN golangci-lint run --timeout=5m
# ============================================
# Stage 2: Testing
# ============================================
FROM golang:1.24-alpine AS tester
WORKDIR /app
# Install build dependencies including gcc for race detector
RUN apk add --no-cache git make gcc musl-dev
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Run tests with race detector and coverage
RUN CGO_ENABLED=1 go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
# ============================================
# Stage 3: Builder
# ============================================
FROM golang:1.24-alpine AS builder
ARG VERSION=dev
ARG COMMIT=unknown
ARG BUILD_DATE
ARG BUILD_USER=docker
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git make ca-certificates
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Build with version info
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-s -w \
-X github.com/prometheus/common/version.Version=${VERSION} \
-X github.com/prometheus/common/version.Revision=${COMMIT} \
-X github.com/prometheus/common/version.Branch=main \
-X github.com/prometheus/common/version.BuildUser=${BUILD_USER} \
-X github.com/prometheus/common/version.BuildDate=${BUILD_DATE}" \
-o eseries_exporter ./cmd/eseries_exporter
# ============================================
# Stage 4: Runtime
# ============================================
FROM alpine:3.21
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata
WORKDIR /
# Copy binary from builder
COPY --from=builder /app/eseries_exporter /eseries_exporter
# Use nobody user for security
USER nobody
EXPOSE 9313
ENTRYPOINT ["/eseries_exporter"]
CMD ["--config.file=/eseries_exporter.yaml"]
# Labels
LABEL org.opencontainers.image.title="NetApp E-Series Exporter" \
org.opencontainers.image.description="Prometheus exporter for NetApp E-Series storage systems" \
org.opencontainers.image.vendor="sckyzo" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.source="https://github.com/sckyzo/eseries_exporter"