-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDockerfile
58 lines (41 loc) · 1.69 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
FROM --platform=$BUILDPLATFORM golang:1.23-bullseye AS builder
ARG GOARCH=''
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY plugins/ plugins/
COPY internal/ internal/
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GO111MODULE=on go build -ldflags="-s -w" -a -o fedhcp main.go
FROM debian:stable AS installer
RUN apt-get update \
&& apt-get -y install --no-install-recommends libcap2-bin \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
FROM gcr.io/distroless/base-debian12 AS distroless-base
FROM distroless-base AS distroless-amd64
ENV LIB_DIR_PREFIX=x86_64
ENV LINKER=ld-linux-x86-64.so.2
FROM distroless-base AS distroless-arm64
ENV LIB_DIR_PREFIX=aarch64
ENV LINKER=ld-linux-aarch64.so.1
FROM distroless-$TARGETARCH AS output-image
WORKDIR /
COPY --from=builder /workspace/fedhcp .
COPY --from=installer /sbin/setcap /sbin/setcap
COPY --from=installer /lib/${LIB_DIR_PREFIX}-linux-gnu/libcap.so.2 /lib/${LIB_DIR_PREFIX}-linux-gnu/libcap.so.2
COPY --from=installer /lib/${LIB_DIR_PREFIX}-linux-gnu/libc.so.6 /lib/${LIB_DIR_PREFIX}-linux-gnu/libc.so.6
COPY --from=installer /lib/${LIB_DIR_PREFIX}-linux-gnu/${LINKER} /lib/${LIB_DIR_PREFIX}-linux-gnu/${LINKER}
COPY --from=installer /bin/sh /bin/sh
RUN /sbin/setcap 'cap_net_bind_service,cap_net_raw=+ep' /fedhcp
USER 65532:65532
ENTRYPOINT ["/fedhcp"]