From da9e670284cee3e12a3c6ac2139ffd194b549c7a Mon Sep 17 00:00:00 2001 From: peefy Date: Wed, 4 Sep 2024 16:10:51 +0800 Subject: [PATCH] fix: dockerfiles Signed-off-by: peefy --- docker/amd64/Dockerfile.init | 8 +++++++- docker/amd64/Dockerfile.server | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docker/amd64/Dockerfile.init b/docker/amd64/Dockerfile.init index 770c1db..6687182 100644 --- a/docker/amd64/Dockerfile.init +++ b/docker/amd64/Dockerfile.init @@ -14,7 +14,13 @@ WORKDIR / COPY . . -RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook-init cmd/wehbook-init +# We run go mod download in a separate step so that we can cache its results. +# This lets us avoid re-downloading modules if we don't need to. The type=target +# mount tells Docker to mount the current directory read-only in the WORKDIR. +# The type=cache mount tells Docker to cache the Go modules cache across builds. +RUN --mount=target=. --mount=type=cache,target=/go/pkg/mod go mod download + +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook-init cmd/wehbook-init/main.go FROM kcllang/kcl diff --git a/docker/amd64/Dockerfile.server b/docker/amd64/Dockerfile.server index cb56f98..7d384ca 100644 --- a/docker/amd64/Dockerfile.server +++ b/docker/amd64/Dockerfile.server @@ -14,7 +14,15 @@ WORKDIR / COPY . . -RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook-server cmd/wehbook-server +ENV CGO_ENABLED=0 + +# We run go mod download in a separate step so that we can cache its results. +# This lets us avoid re-downloading modules if we don't need to. The type=target +# mount tells Docker to mount the current directory read-only in the WORKDIR. +# The type=cache mount tells Docker to cache the Go modules cache across builds. +RUN --mount=target=. --mount=type=cache,target=/go/pkg/mod go mod download + +RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o webhook-server cmd/wehbook-server/main.go FROM kcllang/kcl