From 108a88ae577906d0af99b686e04235a1a067e0cd Mon Sep 17 00:00:00 2001 From: Anastas Dancha Date: Mon, 16 Nov 2020 17:18:06 +0300 Subject: [PATCH 1/2] improving build caching - adding `Dockerfile` and `.git/` to `.dockeringore` improves caching when building images when these paths have changes unrelated to application functionality Signed-off-by: Anastas Dancha --- .dockerignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index c1f70b21..c7c11b97 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,5 @@ example +Dockerfile .github .idea +.git From 4a84368d2417db0ee598e756e1b1526bd4f3fba5 Mon Sep 17 00:00:00 2001 From: Anastas Dancha Date: Mon, 16 Nov 2020 17:19:12 +0300 Subject: [PATCH 2/2] use COPY instead of ADD, install pkgs then build - using COPY instead of ADD, since working with local paths, and not extracting archived data - installing packages before building application binary improves caching, and avoids installing packages every time the application code changes Signed-off-by: Anastas Dancha --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index d926f7c7..83bb78a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ # Build the go application into a binary FROM golang:alpine as builder -WORKDIR /app -ADD . ./ -RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -installsuffix cgo -o gatus . RUN apk --update add ca-certificates +WORKDIR /app +COPY . ./ +RUN CGO_ENABLED=0 GOOS=linux go build -mod vendor -a -installsuffix cgo -o gatus . # Run Tests inside docker image if you don't have a configured go environment #RUN apk update && apk add --virtual build-dependencies build-base gcc @@ -17,4 +17,4 @@ COPY --from=builder /app/static static/ COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt ENV PORT=8080 EXPOSE ${PORT} -ENTRYPOINT ["/gatus"] \ No newline at end of file +ENTRYPOINT ["/gatus"]