From c9eb5a91659bbe64e9335d220576c68be3736bab Mon Sep 17 00:00:00 2001 From: Michael Aldridge Date: Wed, 29 May 2024 01:08:02 -0500 Subject: [PATCH] Dockerfile: Make roughly 43% smaller --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index cbfcb9c..1c9368e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,23 @@ FROM golang:alpine as gobuild -RUN apk add --no-cache libpcap-dev git gcc libc-dev libcap-utils +RUN apk add --no-cache libpcap-dev git gcc libc-dev libcap-utils upx WORKDIR github.com/nberlee/bonjour-reflector COPY go.* . COPY *.go . RUN GOOS=linux go build -ldflags="-s -w" +RUN upx bonjour-reflector RUN setcap cap_net_raw+ep bonjour-reflector FROM alpine as rootfs RUN apk --no-cache add libpcap -COPY --from=gobuild /go/github.com/nberlee/bonjour-reflector/bonjour-reflector / -RUN find /usr/bin /usr/sbin /sbin /bin -type l -delete && busybox grep -v libpcap /etc/apk/world | busybox xargs apk del +FROM scratch as intermediate +COPY --from=rootfs /lib/*musl* /lib/ +COPY --from=rootfs /usr/lib/*pcap* /usr/lib/ +COPY --from=gobuild /go/github.com/nberlee/bonjour-reflector/bonjour-reflector /bonjour-reflector + FROM scratch -COPY --from=rootfs / / +COPY --from=intermediate / / CMD ["/bonjour-reflector"]