Skip to content

Commit 5a0085c

Browse files
authored
Merge pull request #7 from be185057/master
Use distroless docker base image for dnsmasq-controller
2 parents 0f11683 + f80e605 commit 5a0085c

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

Dockerfile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the dnsmasq-controller binary
2-
FROM golang:1.20 as builder
2+
FROM golang:1.22 as builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests
@@ -16,10 +16,27 @@ COPY controllers/ controllers/
1616
COPY pkg/ pkg/
1717

1818
# Build
19-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o dnsmasq-controller main.go
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o dnsmasq-controller
2020

21-
FROM alpine:3.17
21+
22+
# Load distroless base to get initial passwd/group files
23+
FROM gcr.io/distroless/static-debian12:latest as app
24+
25+
# Install dnsmasq
26+
FROM alpine:3.19.1 as dnsmasq
27+
# Use distroless passwd/group
28+
COPY --from=app /etc/passwd /etc/passwd
29+
COPY --from=app /etc/group /etc/group
2230
RUN apk add --no-cache dnsmasq
31+
32+
# Copy dnsmasq and altered passwd/group to distroless image
33+
FROM app
34+
35+
COPY --from=dnsmasq /usr/sbin/dnsmasq /usr/sbin/dnsmasq
36+
COPY --from=dnsmasq /lib/ld-musl-x86_64.so.1 /lib/
37+
COPY --from=dnsmasq /lib/libc.musl-x86_64.so.1 /lib/
38+
COPY --from=dnsmasq /etc/passwd /etc/passwd
39+
COPY --from=dnsmasq /etc/group /etc/group
2340
COPY --from=builder /workspace/dnsmasq-controller /dnsmasq-controller
2441

2542
ENTRYPOINT ["/dnsmasq-controller"]

0 commit comments

Comments
 (0)