-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContainerfile
More file actions
64 lines (48 loc) · 1.92 KB
/
Copy pathContainerfile
File metadata and controls
64 lines (48 loc) · 1.92 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
# Build stage
FROM golang:1.27.1-alpine AS builder
# Build arguments for metadata
ARG BUILD_NUMBER
ARG GIT_COMMIT
ARG BUILD_TIME
# Set build arguments for cross-compilation
ARG TARGETOS
ARG TARGETARCH
# Set working directory
WORKDIR /app
# Install build dependencies
RUN apk add --no-cache git ca-certificates
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application with cross-compilation support
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH:-amd64} \
go build -a -installsuffix cgo \
-ldflags="-w -s -X main.version=${BUILD_NUMBER:-dev} -X main.commit=${GIT_COMMIT:-unknown} -X main.buildTime=${BUILD_TIME:-unknown}" \
-o manager ./cmd/main.go
# Final stage - using distroless for minimal attack surface
FROM gcr.io/distroless/static-debian12:nonroot
# Build arguments for metadata
ARG BUILD_NUMBER
ARG GIT_COMMIT
ARG BUILD_TIME
# Add OCI labels for better metadata
LABEL org.opencontainers.image.title="Mosquitto Operator" \
org.opencontainers.image.description="A Kubernetes operator for provisioning highly available Mosquitto MQTT brokers" \
org.opencontainers.image.vendor="Guided Traffic" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.documentation="https://github.com/guided-traffic/mosquitto-operator" \
org.opencontainers.image.source="https://github.com/guided-traffic/mosquitto-operator" \
org.opencontainers.image.version="${BUILD_NUMBER:-dev}" \
org.opencontainers.image.revision="${GIT_COMMIT:-unknown}" \
org.opencontainers.image.created="${BUILD_TIME:-0}"
# distroless images run as non-root user 65532 (nonroot) by default
# distroless includes ca-certificates and tzdata
WORKDIR /app
# Copy the binary from builder stage
COPY --from=builder /app/manager .
# Expose metrics and health probe ports
EXPOSE 8080 8081
ENTRYPOINT ["./manager"]