From ac44eac03a48a95ee1d5545111047b6783e5b76e Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Tue, 12 Aug 2025 13:37:10 -0500 Subject: [PATCH 1/2] Cache Go modules in development builds --- Dockerfile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6fed212c29..b53f2c0716 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,15 @@ COPY hack/tools/queries /opt/crunchy/conf WORKDIR /usr/src/app COPY . . -ENV GOCACHE=/var/cache/go -# Build the operator and assemble the licenses -RUN --mount=type=cache,target=/var/cache/go go build ./cmd/postgres-operator -RUN go run ./hack/extract-licenses.go licenses postgres-operator +ENV GOCACHE=/var/cache/go +ENV GOMODCACHE=/var/cache/gomod +RUN --mount=type=cache,target=/var/cache \ +<<-SHELL +set -e +go build ./cmd/postgres-operator +go run ./hack/extract-licenses.go licenses postgres-operator +SHELL FROM docker.io/library/debian:bookworm From edcd8a480393a6f581a762e46675a6e65a07df19 Mon Sep 17 00:00:00 2001 From: Chris Bandy Date: Thu, 2 Oct 2025 18:05:54 -0500 Subject: [PATCH 2/2] Prepare file permissions in the build stage Some files and directories were not readable by the image user. Issue: PGO-2695 --- Dockerfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index b53f2c0716..f6d60b699a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,9 +4,6 @@ FROM docker.io/library/golang:bookworm AS build -COPY licenses /licenses -COPY hack/tools/queries /opt/crunchy/conf - WORKDIR /usr/src/app COPY . . @@ -17,12 +14,15 @@ RUN --mount=type=cache,target=/var/cache \ set -e go build ./cmd/postgres-operator go run ./hack/extract-licenses.go licenses postgres-operator + +find ./hack/tools/queries '(' -type d -exec chmod 0555 '{}' + ')' -o '(' -type f -exec chmod 0444 '{}' + ')' +find ./licenses '(' -type d -exec chmod 0555 '{}' + ')' -o '(' -type f -exec chmod 0444 '{}' + ')' SHELL FROM docker.io/library/debian:bookworm -COPY --from=build --chmod=0444 /usr/src/app/licenses /licenses -COPY --from=build --chmod=0444 /opt/crunchy/conf /opt/crunchy/conf +COPY --from=build /usr/src/app/licenses /licenses +COPY --from=build /usr/src/app/hack/tools/queries /opt/crunchy/conf COPY --from=build /usr/src/app/postgres-operator /usr/local/bin USER 2