This is an automated email from the ASF dual-hosted git repository.
HoustonPutman pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr-operator.git
The following commit(s) were added to refs/heads/main by this push:
new b4e74f4 Docker fixes and improvements (#881)
b4e74f4 is described below
commit b4e74f4060560677544b905420b5eafe5d5f1d1c
Author: Houston Putman <[email protected]>
AuthorDate: Thu Nov 5 08:49:36 2026 -0800
Docker fixes and improvements (#881)
* Docker fixes and improvements
* Release wizard fixes
---
.dockerignore | 5 +++--
Makefile | 6 ++++-
build/Dockerfile | 41 +++++++++++++++++++++++++++-------
hack/release/wizard/releaseWizard.yaml | 4 ++--
4 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/.dockerignore b/.dockerignore
index 290ba64..fffd206 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -23,8 +23,9 @@
!go.mod
!go.sum
-# Git metadata and build tooling used during the image build
-!.git
+# Build tooling used during the image build.
+# The .git directory is deliberately excluded: it changes on every commit and
would invalidate the cache of every
+# layer after it. The git SHA is provided through the GIT_SHA build arg
instead.
!build
!hack
!Makefile
diff --git a/Makefile b/Makefile
index 6e62289..c8e9095 100644
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,8 @@ VERSION_SUFFIX = $(shell cat version/version.go | grep -E
'VersionSuffix([[:spac
TMP_VERSION = $(shell cat version/version.go | grep -E
'Version([[:space:]]+)=' | sed 's/.*["'"'"']\(.*\)["'"'"']/\1/g')
VERSION = $(if
$(VERSION_SUFFIX),$(TMP_VERSION)-$(VERSION_SUFFIX),$(TMP_VERSION))
TAG ?= $(VERSION)
+# Docs are only published for released versions, so prerelease builds link to
the latest docs (the Dockerfile default)
+DOCS_VERSION = $(if $(VERSION_SUFFIX),latest,$(shell echo $(TMP_VERSION) | sed
-E 's/^v([0-9]+)\.([0-9]+).*/\1_\2/'))
GIT_SHA = $(shell git rev-parse --short HEAD)
GOOS = $(shell go env GOOS)
ARCH = $(shell go env GOARCH)
@@ -182,9 +184,11 @@ run: manifests generate fmt vet ## Run a controller from
your host
.PHONY: docker-build
docker-build: ## Build the docker image for the Solr Operator
- docker build --build-arg GIT_SHA=$(GIT_SHA) . -t solr-operator -f
./build/Dockerfile
+ DOCKER_BUILDKIT=1 docker build --build-arg GIT_SHA=$(GIT_SHA)
--build-arg VERSION="$(VERSION)" --build-arg DOCS_VERSION=$(DOCS_VERSION) . -t
solr-operator -f ./build/Dockerfile
docker tag solr-operator $(IMG):$(TAG)
docker tag solr-operator $(IMG):latest
+ # Remove the dangling images that previous builds of this image leave
behind (only those built from our Dockerfile)
+ docker image prune -f --filter
"label=org.opencontainers.image.title=Apache Solr Operator" >/dev/null
.PHONY: docker-push
docker-push: ## Push the docker image for the Solr Operator
diff --git a/build/Dockerfile b/build/Dockerfile
index 0284db8..a0ae847 100644
--- a/build/Dockerfile
+++ b/build/Dockerfile
@@ -11,21 +11,31 @@
# limitations under the License.
# Build the manager binary
-FROM golang:1.27 as builder
+FROM golang:1.27 AS builder
WORKDIR /workspace
ARG GO111MODULE=on
+# The Go module and build caches are BuildKit cache mounts (see the RUN
instructions below), so they are reused
+# across builds without being stored in image layers, which would otherwise
pile up for every source change.
+
# Copy the Go Modules manifests
COPY go.mod go.sum ./
# cache deps before building and copying source so that we don't need to
re-download as much
# and so that source changes don't invalidate our downloaded layer
-RUN go mod download
+RUN --mount=type=cache,target=/go/pkg/mod \
+ go mod download
+
+# Download necessary build tools. This only depends on the Makefile (which
pins the tool versions), so
+# the tools are not rebuilt when the source changes.
+COPY Makefile ./
+RUN --mount=type=cache,target=/go/pkg/mod \
+ --mount=type=cache,target=/root/.cache/go-build \
+ make controller-gen go-licenses
# Copy development resources
-COPY .git/ .git/
COPY build/build.sh build/build.sh
-COPY Makefile LICENSE NOTICE build/LICENSE-ADDITION build/NOTICE-ADDITION ./
+COPY LICENSE NOTICE build/LICENSE-ADDITION build/NOTICE-ADDITION ./
# Add additional binary-release-only information to the LICENSE and NOTICES
files
RUN echo "\n\n" >> LICENSE; \
@@ -33,9 +43,6 @@ RUN echo "\n\n" >> LICENSE; \
echo "\n\n" >> NOTICE; \
cat NOTICE-ADDITION >> NOTICE
-# Download necessary libraries
-RUN make controller-gen go-licenses
-
# Copy the go source and utilities
COPY hack/ hack/
COPY main.go ./
@@ -46,7 +53,10 @@ COPY controllers/ controllers/
ARG GIT_SHA
# Build
-RUN CGO_ENABLED=0 GIT_SHA="${GIT_SHA}" make fetch-licenses-full build
+# The git SHA is passed to make explicitly, since the .git directory is not
part of the build context.
+RUN --mount=type=cache,target=/go/pkg/mod \
+ --mount=type=cache,target=/root/.cache/go-build \
+ CGO_ENABLED=0 make GIT_SHA="${GIT_SHA}" fetch-licenses-full build
# =============================================================================
# Copy the controller-manager into a thin image
@@ -58,6 +68,21 @@ RUN CGO_ENABLED=0 GIT_SHA="${GIT_SHA}" make
fetch-licenses-full build
# If there is another way to view these files, we can remove "debug-".
FROM gcr.io/distroless/static:debug-nonroot
+# Build args are scoped to a stage, so the ones used by the labels below must
be declared again here
+ARG GIT_SHA
+ARG VERSION
+ARG DOCS_VERSION=latest
+
+LABEL org.opencontainers.image.title="Apache Solr Operator"
+LABEL org.opencontainers.image.description="The Apache Solr Operator is a
Kubernetes Operator that makes it easy to deploy, manage, and scale Apache Solr
in a cloud-native environment."
+LABEL org.opencontainers.image.authors="The Apache Solr Project"
+LABEL org.opencontainers.image.url="https://solr.apache.org/operator"
+LABEL org.opencontainers.image.source="https://github.com/apache/solr-operator"
+LABEL
org.opencontainers.image.documentation="https://solr.apache.org/guide/operator/${DOCS_VERSION}/"
+LABEL org.opencontainers.image.version="${VERSION}"
+LABEL org.opencontainers.image.revision="${GIT_SHA}"
+LABEL org.opencontainers.image.licenses="Apache-2.0"
+
WORKDIR /
COPY --from=builder workspace/bin/solr-operator .
COPY --from=builder workspace/LICENSE workspace/NOTICE etc/licenses/
diff --git a/hack/release/wizard/releaseWizard.yaml
b/hack/release/wizard/releaseWizard.yaml
index f75fe28..6622c39 100644
--- a/hack/release/wizard/releaseWizard.yaml
+++ b/hack/release/wizard/releaseWizard.yaml
@@ -822,7 +822,7 @@ groups:
cmd: docker buildx create --use
tee: true
- !Command
- cmd: docker buildx build --pull --push --platform
"linux/amd64,linux/arm64" --build-arg GIT_SHA={{ build_rc.git_sha |
default("<git_sha>", True) }} . --tag {{ docker_image }} -f ./build/Dockerfile
+ cmd: docker buildx build --pull --push --platform
"linux/amd64,linux/arm64" --build-arg GIT_SHA={{ build_rc.git_sha |
default("<git_sha>", True) }} --build-arg VERSION={{ release_version }}-rc{{
rc_number }} --build-arg DOCS_VERSION={{ release_version_major }}_{{
release_version_minor }} . --tag {{ docker_image }} -f ./build/Dockerfile
logfile: rc_docker_upload.log
tee: true
- !Todo
@@ -1233,7 +1233,7 @@ groups:
cmd: docker buildx create --use
tee: true
- !Command
- cmd: docker buildx build --pull --push --platform
"linux/amd64,linux/arm64" --build-arg GIT_SHA={{ build_rc.git_sha |
default("<git_sha>", True) }} . --tag apache/solr-operator:{{ release_version
}} -f ./build/Dockerfile
+ cmd: docker buildx build --pull --push --platform
"linux/amd64,linux/arm64" --build-arg GIT_SHA={{ build_rc.git_sha |
default("<git_sha>", True) }} --build-arg VERSION={{ release_version }}
--build-arg DOCS_VERSION={{ release_version_major }}_{{ release_version_minor
}} . --tag apache/solr-operator:{{ release_version }} -f ./build/Dockerfile
tee: true
logfile: docker_upload.log
- !Todo