Skip to content

Commit

Permalink
Dockerfile: Make roughly 43% smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
the-maldridge committed May 29, 2024
1 parent 669ade1 commit c9eb5a9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit c9eb5a9

Please sign in to comment.