SOLR-14949: Ability to customize Solr Docker build (#2020)

Also added a gradlew helpDocker page.
This commit is contained in:
Houston Putman 2020-11-10 10:42:38 -05:00 committed by GitHub
parent 426a9c25c2
commit 212b0f8657
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 81 additions and 48 deletions

View File

@ -17,6 +17,10 @@ jobs:
runs-on: ubuntu-latest
env:
SOLR_DOCKER_IMAGE_REPO: github-pr/solr
SOLR_DOCKER_IMAGE_TAG: ${{github.event.number}}
steps:
# Setup
- uses: actions/checkout@v2

View File

@ -29,6 +29,7 @@ configure(rootProject) {
["Git", "help/git.txt", "Git assistance and guides."],
["ValidateLogCalls", "help/validateLogCalls.txt", "How to use logging calls efficiently."],
["IDEs", "help/IDEs.txt", "IDE support."],
["Docker", "help/docker.txt", "Building Solr Docker images."],
]
helpFiles.each { section, path, sectionInfo ->

53
help/docker.txt Normal file
View File

@ -0,0 +1,53 @@
Docker Images for Solr
======================
Solr docker images are built using Palantir's Docker Gradle plugin, https://github.com/palantir/gradle-docker.
Common Inputs
-------------
The docker image and its tag can be customized via the following options, all accepted via both Environment Variables and Gradle Properties.
Docker Image Repository:
Default: "apache/solr"
EnvVar: SOLR_DOCKER_IMAGE_REPO
Gradle Property: -Psolr.docker.imageRepo
Docker Image Tag:
Default: the Solr version, e.g. "9.0.0-SNAPSHOT"
EnvVar: SOLR_DOCKER_IMAGE_TAG
Gradle Property: -Psolr.docker.imageTag
Docker Image Name: (Use this to explicitly set a whole image name. If given, the image repo and image version options above are ignored.)
Default: {image_repo}/{image_tag} (both options provided above, with defaults)
EnvVar: SOLR_DOCKER_IMAGE_NAME
Gradle Property: -Psolr.docker.imageName
Building
--------
In order to build the Solr Docker image, run:
gradlew docker
The docker build task accepts the following inputs, in addition to the common inputs listed above:
Base Docker Image: (The docker image used for the "FROM" in the Solr Dockerfile)
Default: "openjdk:11-jre-slim"
EnvVar: SOLR_DOCKER_BASE_IMAGE
Gradle Property: -Psolr.docker.baseImage
Testing
-------
To test the docker image, run:
gradlew dockerTest
If a custom docker image name was used, via one of the common inputs described above, then the same input must be used while testing.
You can also specify an explicit list of tests to run, or an explicit list of tests to ignore.
Both inputs are optional, and by default all tests will be run.
gradlew testDocker --tests create_core,demo
gradlew testDocker --ignore demo-tini,initdb

View File

@ -153,6 +153,8 @@ Other Changes
* SOLR-14978: Enable OOM Killer Script in Solr Foreground. Simplify getting heap dumps on OOM. (Mike Drob, Houston Putman)
* SOLR-14949: Ability to customize docker image name/base image (Houston Putman)
Bug Fixes
---------------------
* SOLR-14546: Fix for a relatively hard to hit issue in OverseerTaskProcessor that could lead to out of order execution

View File

@ -15,6 +15,9 @@
* limitations under the License.
*/
import com.google.common.base.Preconditions
import com.google.common.base.Strings
apply plugin: 'base'
apply plugin: 'com.palantir.docker'
@ -31,8 +34,10 @@ dependencies {
docker dockerPackage
}
def dockerImageName = "apache/solr:${version}"
def baseDockerImage = 'openjdk:11-jre-slim'
def dockerImageRepo = propertyOrEnvOrDefault("solr.docker.imageRepo", "SOLR_DOCKER_IMAGE_REPO", "apache/solr")
def dockerImageTag = propertyOrEnvOrDefault("solr.docker.imageTag", "SOLR_DOCKER_IMAGE_TAG", "${version}")
def dockerImageName = propertyOrEnvOrDefault("solr.docker.imageName", "SOLR_DOCKER_IMAGE_NAME", "${dockerImageRepo}:${dockerImageTag}")
def baseDockerImage = propertyOrEnvOrDefault("solr.docker.baseImage", "SOLR_DOCKER_BASE_IMAGE", 'openjdk:11-jre-slim')
docker {
name = dockerImageName
@ -53,12 +58,22 @@ tasks.docker {
}
abstract class DockerTestSuite extends DefaultTask {
private String solrImageName = null;
private List<String> tests = new ArrayList<>();
private List<String> ignore = new ArrayList<>();
@OutputDirectory
abstract DirectoryProperty getOutputDir()
public void setSolrImageName(String solrImageName) {
this.solrImageName = solrImageName
}
public String getSolrImageName() {
Preconditions.checkArgument(!Strings.isNullOrEmpty(solrImageName), "solrImageName is a required dockerTests configuration item.")
return solrImageName
}
@Option(option = "tests", description = "Only run these specified tests, comma separated.")
public void setTests(List<String> tests) {
this.tests = tests;
@ -81,6 +96,8 @@ abstract class DockerTestSuite extends DefaultTask {
@TaskAction
void execute() {
// Print information on the image before it is tested
project.logger.lifecycle("Testing Solr Image: $solrImageName\n")
def sourceDir = project.file("tests/cases")
sourceDir.eachFile { file ->
def testName = file.getName()
@ -92,7 +109,7 @@ abstract class DockerTestSuite extends DefaultTask {
project.exec {
environment "TEST_DIR", "$file"
environment "BUILD_DIR", "$testCaseBuildDir"
commandLine "bash", "$file/test.sh", "apache/solr:${project.version}"
commandLine "bash", "$file/test.sh", solrImageName
}
}
}
@ -101,4 +118,5 @@ abstract class DockerTestSuite extends DefaultTask {
task testDocker(type: DockerTestSuite) {
outputDir = project.file("$buildDir/tmp/tests")
solrImageName = dockerImageName
}

View File

@ -1,45 +0,0 @@
#!/bin/bash
#
set -euo pipefail
TEST_DIR="${TEST_DIR:-$(dirname -- "${BASH_SOURCE[0]}")}"
source "${TEST_DIR}/../../shared.sh"
echo "Running $container_name"
docker run --name "$container_name" -d "$tag"
wait_for_server_started "$container_name"
echo "Checking that the OS matches the tag '$tag'"
if echo "$tag" | grep -q -- -alpine; then
alpine_version=$(docker exec --user=solr "$container_name" cat /etc/alpine-release || true)
if [[ -z $alpine_version ]]; then
echo "Could not get alpine version from container $container_name"
container_cleanup "$container_name"
exit 1
fi
echo "Alpine $alpine_version"
else
debian_version=$(docker exec --user=solr "$container_name" cat /etc/debian_version || true)
if [[ -z $debian_version ]]; then
echo "Could not get debian version from container $container_name"
container_cleanup "$container_name"
exit 1
fi
echo "Debian $debian_version"
fi
# check that the version of Solr matches the tag
changelog_version=$(docker exec --user=solr "$container_name" bash -c "grep -E '^==========* ' /opt/solr/CHANGES.txt | head -n 1 | tr -d '= '")
echo "Solr version $changelog_version"
solr_version_from_tag=$(echo "$tag" | sed -e 's/^.*://' -e 's/-.*//')
if [[ $changelog_version != "$solr_version_from_tag" ]]; then
echo "Solr version mismatch"
container_cleanup "$container_name"
exit 1
fi
container_cleanup "$container_name"
echo "Test $TEST_NAME $tag succeeded"