-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.scratch
More file actions
82 lines (66 loc) · 2.75 KB
/
Dockerfile.scratch
File metadata and controls
82 lines (66 loc) · 2.75 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
# syntax=docker/dockerfile:1@sha256:b6afd42430b15f2d2a4c5a02b919e98a525b785b1aaff16747d2f623364e39b6
##### Stage 1: Build (pinned & minimal, multi-arch) #####
FROM --platform=$BUILDPLATFORM golang@sha256:c2a1f7b2095d046ae14b286b18413a05bb82c9bca9b25fe7ff5efef0f0826166 AS build
#1.26.2-alpine
WORKDIR /src
ENV GOFLAGS="-mod=readonly" \
GOMODCACHE=/go/pkg/mod \
GOCACHE=/root/.cache/go-build \
CGO_ENABLED=0
RUN apk add --no-cache ca-certificates tzdata
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG TARGETOS
ARG TARGETARCH
ARG TARGETVARIANT
ARG VERSION=0.0.0
ARG BUILD_DATE="2025-01-01T00:00:00Z"
ARG GIT_REVISION="0000000000000000000000000000000000000000"
# Build the main controller binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
set -eux; \
export GOOS="${TARGETOS:-linux}"; \
export GOARCH="${TARGETARCH}"; \
if [ -n "${TARGETVARIANT:-}" ]; then export GOARM="${TARGETVARIANT#v}"; fi; \
go build \
-trimpath \
-ldflags="-s -w \
-X 'pangolin-kube-controller/internal/version.Version=${VERSION}' \
-X 'pangolin-kube-controller/internal/version.Commit=${GIT_REVISION}' \
-X 'pangolin-kube-controller/internal/version.Date=${BUILD_DATE}'" \
-o /out/pangolin-kube-controller \
./cmd/controller; \
go build \
-trimpath \
-o /out/healthcheck \
./cmd/healthcheck
##### Stage 2: Scratch Runtime #####
FROM scratch
ARG VERSION=0.0.0
ARG BUILD_DATE="2025-01-01T00:00:00Z"
ARG GIT_REVISION="0000000000000000000000000000000000000000"
LABEL org.opencontainers.image.title="Pangolin Kubernetes Controller" \
org.opencontainers.image.description="Synchronises Pangolin Traefik configuration into K8S Traefik CRDs" \
org.opencontainers.image.vendor="fosrl" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.source="https://github.com/fosrl/pangolin-kube-controller" \
org.opencontainers.image.licenses="AGPL-3.0-only" \
org.opencontainers.image.revision="${GIT_REVISION}" \
org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.documentation="https://github.com/fosrl/pangolin-kube-controller" \
org.opencontainers.image.authors="fosrl"
WORKDIR /
# Copy runtime dependencies
COPY --from=build /etc/ssl/certs/ /etc/ssl/certs/
COPY --from=build /usr/share/zoneinfo/ /usr/share/zoneinfo/
COPY --from=build /out/pangolin-kube-controller /controller
COPY --from=build /out/healthcheck /healthcheck
# Make healthcheck port and path configurable, with defaults
ENV HEALTHCHECK_PORT=9090 \
HEALTHCHECK_PATH=/health/ready
USER 65532:65532
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD ["/healthcheck"]
ENTRYPOINT ["/controller"]