-
Notifications
You must be signed in to change notification settings - Fork 17
/
Dockerfile
60 lines (49 loc) · 1.94 KB
/
Dockerfile
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
# syntax=docker/dockerfile:1.2
FROM --platform=$BUILDPLATFORM docker.io/golang:1.22.4 AS builder
ARG GIT_COMMIT=dev
ARG GIT_BRANCH=dev
WORKDIR $GOPATH/frr-k8s
# Cache the downloads
COPY go.mod go.sum ./
RUN go mod download
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/ internal/
COPY frr-tools/metrics ./frr-tools/metrics/
ARG TARGETARCH
ARG TARGETOS
ARG TARGETPLATFORM
# have to manually convert as building the different arms can cause issues
# Extract variant
RUN case ${TARGETPLATFORM} in \
"linux/arm/v6") export VARIANT="6" ;; \
"linux/arm/v7") export VARIANT="7" ;; \
*) export VARIANT="" ;; \
esac
# Cache builds directory for faster rebuild
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
# build frr metrics
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$VARIANT \
go build -v -o /build/frr-metrics \
-ldflags "-X 'frr-k8s/internal/version.gitCommit=${GIT_COMMIT}' -X 'frr-k8s/metallb/internal/version.gitBranch=${GIT_BRANCH}'" \
frr-tools/metrics/exporter.go \
&& \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=$VARIANT \
go build -v -o /build/frr-k8s \
-ldflags "-X 'frr-k8s/internal/version.gitCommit=${GIT_COMMIT}' -X 'frr-k8s/internal/version.gitBranch=${GIT_BRANCH}'" \
cmd/main.go
FROM docker.io/alpine:latest
COPY --from=builder /build/frr-k8s /frr-k8s
COPY --from=builder /build/frr-metrics /frr-metrics
COPY frr-tools/reloader/frr-reloader.sh /frr-reloader.sh
COPY LICENSE /
LABEL org.opencontainers.image.authors="metallb" \
org.opencontainers.image.url="https://github.com/metallb/frr-k8s" \
org.opencontainers.image.source="https://github.com/metallb/frr-k8s" \
org.opencontainers.image.vendor="metallb" \
org.opencontainers.image.licenses="Apache-2.0" \
org.opencontainers.image.description="FRR-K8s" \
org.opencontainers.image.title="frr-k8s" \
org.opencontainers.image.base.name="docker.io/alpine:latest"
ENTRYPOINT ["/frr-k8s"]