Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 7 additions & 23 deletions dev-docs/gradle-help/docker.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ Solr Distribution: (Either Full or Slim, the solr binary distribution to build t
EnvVar: SOLR_DOCKER_DIST
Gradle Property: -Psolr.docker.dist

Docker Platforms: (Comma-separated list of target platforms)
Default: None (builds for current architecture only)
Docker Platforms: (Comma-separated list of target platforms for dockerPush)
Default: None (pushes image built for current architecture)
EnvVar: SOLR_DOCKER_PLATFORM
Gradle Property: -Psolr.docker.platform
Examples:
- "linux/amd64" (single platform - can be used with dockerBuild)
- "linux/arm64,linux/amd64" (multi-platform - only supported by dockerPush)
- "linux/amd64" (single platform)
- "linux/arm64,linux/amd64" (multi-platform)

Note: Multi-platform builds require Docker Buildx and are ONLY supported
by the dockerPush task. The dockerBuild task does not support multi-platform builds because
Docker cannot load multi-platform images into the local daemon. Use dockerPush to build and push
multi-platform images in a single step. You may need QEMU installed to run multi-platform
builds.
Note: This setting ONLY affects the dockerPush task

Tagging and Pushing
-------
Expand Down Expand Up @@ -78,10 +74,8 @@ Docker Image Name: (Use this to explicitly set a whole image name. If given, the
Multi-Platform Builds
-------

To build a multi-platform Docker image, use the SOLR_DOCKER_PLATFORM environment variable or Gradle property.

IMPORTANT: Multi-platform builds (with multiple platforms) are ONLY supported by dockerPush, not dockerBuild.
This is because Docker cannot load multi-platform images into the local daemon.
Multi-platform Docker builds are ONLY supported by the dockerPush task.
The dockerBuild task always builds for your current local architecture.

Prerequisites:
- Docker Buildx must be installed (included with Docker Desktop and recent Docker Engine versions)
Expand All @@ -98,16 +92,6 @@ Using Gradle property:
The dockerPush task will build and push the multi-platform image in a single step using Docker Buildx.
The task will validate that a suitable builder exists and that it supports all requested platforms before building.

Single-Platform Builds with Explicit Platform
--------------------------------------------------

You can build for a specific platform and load it into your local Docker daemon:

Build for a specific platform:
SOLR_DOCKER_PLATFORM=linux/arm64 ./gradlew dockerBuild

This uses Docker Buildx with --load to make the image available locally for testing.

Testing
-------

Expand Down
5 changes: 5 additions & 0 deletions solr/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ docker buildx build --platform linux/amd64,linux/arm64 -f solr-X.Y.Z/docker/Dock
docker buildx build --platform linux/arm64 -f solr-X.Y.Z/docker/Dockerfile --tag myrepo/solr:X.Y.Z-arm64 --load - < solr-X.Y.Z.tgz
```

**Note**: When building Docker images using Gradle tasks (`./gradlew dockerBuild`, `./gradlew dockerPush`),
the `dockerBuild` task always builds for your current local architecture only. Multi-platform and
single-platform targeting is only supported by the `dockerPush` task via the `SOLR_DOCKER_PLATFORM`
environment variable or property `-Psolr.docker.platform`. See `./gradlew helpDocker` for details.

Official Image Management
----

Expand Down
58 changes: 10 additions & 48 deletions solr/docker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ def getBuildxBuilderInfo = {
return builderCheckOutput.toString()
}

// Helper method to validate Docker Buildx builder is available
def validateBuildxBuilder = {
getBuildxBuilderInfo()
}


task assemblePackaging(type: Sync) {
description = 'Assemble docker scripts and Dockerfile for Solr Packaging'
Expand All @@ -197,65 +192,32 @@ task dockerBuild() {

// Ensure that the docker image is rebuilt on build-arg changes or changes in the docker context
inputs.properties([
baseDockerImage: baseDockerImage,
dockerImagePlatforms: dockerImagePlatforms
baseDockerImage: baseDockerImage
])
var solrTgzConfiguration = getSolrTgzConfiguration()
var solrTgzConfiguration = isImageSlim() ? configurations.solrSlimTgz : configurations.solrFullTgz
inputs.files(solrTgzConfiguration)
inputs.property("isSlimImage", isImageSlim())
inputs.property("isMultiPlatform", isMultiPlatform())
dependsOn(solrTgzConfiguration)

doLast {
def platformValue = inputs.properties.dockerImagePlatforms.toString().trim()
validatePlatformFormat(platformValue)
def useSinglePlatform = !platformValue.isEmpty() && !platformValue.contains(',')

// Multi-platform builds are not supported by dockerBuild, only by dockerPush
if (isMultiPlatform()) {
throw new GradleException("Multi-platform builds (SOLR_DOCKER_PLATFORM with multiple platforms) are not supported by dockerBuild.\n" +
"Please use 'dockerPush' instead, which will build and push the multi-platform image in a single step.\n" +
"Example: SOLR_DOCKER_PLATFORM=linux/arm64,linux/amd64 ./gradlew dockerPush")
}

if (useSinglePlatform) {
// Single-platform build with explicit platform using buildx
validateBuildxBuilder()

exec {
standardInput = solrTgzConfiguration.singleFile.newDataInputStream()
commandLine "docker", "buildx", "build",
"-f", "solr-${ -> project.version }${dockerImageDistSuffix}/docker/Dockerfile",
"--platform", platformValue,
"--build-arg", "BASE_IMAGE=${ -> inputs.properties.baseDockerImage}",
"--iidfile", imageIdFile,
"--load",
"-"
}
} else {
// Standard build for current architecture
exec {
standardInput = solrTgzConfiguration.singleFile.newDataInputStream()
commandLine "docker", "build",
"-f", "solr-${ -> project.version }${dockerImageDistSuffix}/docker/Dockerfile",
"--iidfile", imageIdFile,
"--build-arg", "BASE_IMAGE=${ -> inputs.properties.baseDockerImage}",
"-"
}
exec {
standardInput = solrTgzConfiguration.singleFile.newDataInputStream()
commandLine "docker", "build",
"-f", "solr-${ -> project.version }${dockerImageDistSuffix}/docker/Dockerfile",
"--iidfile", imageIdFile,
"--build-arg", "BASE_IMAGE=${ -> inputs.properties.baseDockerImage}",
"-"
}
}

// Print information on the image after it has been created
doLast {
def dockerImageId = file(imageIdFile).text
project.logger.lifecycle("Solr Docker Image Created")
project.logger.lifecycle("\tID/Ref: \t${ -> dockerImageId }")
project.logger.lifecycle("\tID: \t${ -> dockerImageId }")
project.logger.lifecycle("\tBase Image: \t${ -> baseDockerImage }")
project.logger.lifecycle("\tSolr Version: \t${ -> project.version }")
project.logger.lifecycle("\tSolr Distribution: \t${isImageSlim() ? "Slim" : "Full"}")
if (!dockerImagePlatforms.isEmpty()) {
project.logger.lifecycle("\tPlatforms: \t${ -> dockerImagePlatforms }")
}
}

outputs.files(imageIdFile)
Expand Down
Loading