From db5419ccd584bfbf883e672445f37f4a381f53ef Mon Sep 17 00:00:00 2001 From: Adam Leskis Date: Mon, 30 Jan 2023 22:58:09 +0000 Subject: [PATCH 1/2] perf: use multistage build to slim down backend container --- Dockerfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3e0e7c3..e96ae91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:latest +FROM golang:latest AS builder LABEL app="slo-tracker" LABEL maintainer="roshan.aloor@gmail.com" @@ -8,9 +8,16 @@ LABEL description="slo-tracker : Track your product SLO" WORKDIR /app COPY . . -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o /app/slo-tracker . +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-w -s" -o /app/slo-tracker . +FROM scratch + +# we don't need these certs for local development, but we copy in case you want +# to use this image for a production environment +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /app/slo-tracker /app/slo-tracker + EXPOSE 8080 -CMD /app/slo-tracker \ No newline at end of file +CMD ["/app/slo-tracker"] From 9820d3c6be67042fb627fd7ebdddd5ce0090966a Mon Sep 17 00:00:00 2001 From: Adam Leskis Date: Mon, 30 Jan 2023 23:18:46 +0000 Subject: [PATCH 2/2] perf: add docker ignore to speed up transfer of build context --- .dockerignore | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4a92e55 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# these don't end up in the final image, but no need to consider them in the build context +*.md +LICENSE +images +ui