From 6412a308e89edd3b02b1764cb70347150fe85f17 Mon Sep 17 00:00:00 2001 From: Tony Grosinger Date: Tue, 6 Dec 2022 08:34:49 -0800 Subject: [PATCH] Add Dockerfile The dockerfile is used both as the dev container as well as the production container. The production container is built with only the executable binary and dependencies. --- Dockerfile | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..678d7c6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM docker.io/library/golang:1.19-bullseye as dev + +FROM dev as intermediate + +COPY . /build +WORKDIR /build +RUN go build -o doddns && \ + ldd doddns | tr -s '[:blank:]' '\n' | grep '^/' | \ + awk '{printf("%s\n", $1); system("readlink -f " $1)}' | \ + xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;' + +FROM scratch as prod + +COPY --from=intermediate /build/deps / +COPY --from=intermediate /build/doddns /doddns +COPY --from=intermediate /etc/ssl/certs/* /etc/ssl/certs/ +COPY --from=intermediate /usr/share/ca-certificates /usr/share/ca-certificates + +WORKDIR / +ENTRYPOINT ["/doddns"]