From 4e4373e0da88f8f567af4fad71a575ff66661db8 Mon Sep 17 00:00:00 2001 From: Daniel Sullivan Date: Tue, 5 Sep 2023 13:34:26 -0500 Subject: [PATCH 1/3] switched to staged docker build decreases rebuild time and results in smaller image --- Dockerfile | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index b70deeab..8bdc4364 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,23 @@ -FROM alpine:3.16 +# syntax=docker/dockerfile:1 -ENV GOPATH /go +FROM golang:alpine as builder + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/var/cache/apk \ + apk update \ + && apk add git subversion mercurial breezy openssh tini npm rsync build-base COPY . /src -RUN apk update \ - && apk add go git subversion libc-dev mercurial breezy openssh tini build-base npm rsync \ - && cd /src \ +RUN --mount=type=cache,target=/go/pkg/mod \ + cd /src \ && make \ - && cp .build/bin/houndd /bin \ - && rm -r .build \ - && apk del go build-base rsync npm \ - && rm -f /var/cache/apk/* + +FROM alpine:latest +RUN --mount=type=cache,target=/var/cache/apk \ + apk add git subversion mercurial breezy openssh tini + +COPY --from=builder /src/.build/bin/houndd /bin/ VOLUME ["/data"] From 922cb8f74c054b206cc8b1df089e5ac201f06ff4 Mon Sep 17 00:00:00 2001 From: Daniel Sullivan Date: Tue, 5 Sep 2023 14:43:45 -0500 Subject: [PATCH 2/3] fix dockerfile error --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8bdc4364..de545846 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ COPY . /src RUN --mount=type=cache,target=/go/pkg/mod \ cd /src \ - && make \ + && make FROM alpine:latest RUN --mount=type=cache,target=/var/cache/apk \ From f55563a5a4e31cae1125f9a27f1080f89471118c Mon Sep 17 00:00:00 2001 From: Daniel Sullivan Date: Tue, 5 Sep 2023 14:57:06 -0500 Subject: [PATCH 3/3] fix dockerfile buildx problems --- Dockerfile | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index de545846..8550ee00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,10 +2,8 @@ FROM golang:alpine as builder -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/var/cache/apk \ - apk update \ - && apk add git subversion mercurial breezy openssh tini npm rsync build-base +RUN apk update \ + && apk add --no-cache git subversion mercurial breezy openssh tini npm rsync build-base COPY . /src @@ -14,8 +12,7 @@ RUN --mount=type=cache,target=/go/pkg/mod \ && make FROM alpine:latest -RUN --mount=type=cache,target=/var/cache/apk \ - apk add git subversion mercurial breezy openssh tini +RUN apk add --no-cache git subversion mercurial breezy openssh tini COPY --from=builder /src/.build/bin/houndd /bin/