SOLR-15322: Solr releases now contain everything needed to build runable docker images
Co-authored-by: Houston Putman <houston@apache.org>
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b3aea05..e401423 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -110,6 +110,8 @@
This doesn't work in SolrCloud (but may someday). QEC no longer supports a config file in
the data dir. (David Smiley)
+* SOLR-15322: Solr releases now contain everything needed to build runable docker images (Houston Putman, hossman)
+
Other Changes
----------------------
* SOLR-14656: Autoscaling framework removed (Ishan Chattopadhyaya, noble, Ilan Ginzburg)
diff --git a/solr/docker/Dockerfile b/solr/docker/Dockerfile
index 9d82c36..443a0eb 100644
--- a/solr/docker/Dockerfile
+++ b/solr/docker/Dockerfile
@@ -1,19 +1,35 @@
+# This file can be used to build an (unofficial) Docker image of Apache Solr.
+#
+# The primary purpose of this file, is for use by Solr developers, with a java/gradle development env, who
+# wish to build customized -- or "patched" docker images of Solr. For this type of usecase, this file
+# will be used automatically by gradle to build docker images from your local src.
+# Example:
+# ./gradlew dockerBuild
+#
+# For most Solr users, using this Dockerfile is not recommended: pre-built docker images of Solr are
+# available at https://hub.docker.com/_/solr -- however this file can be used to build docker images from
+# a Solr release artifact -- either from a remote TGZ file, or from an TGZ artifact you have downloaded
+# locally.
+# Example:
+# docker build -f solr-X.Y.Z/docker/Dockerfile https://www.apache.org/dyn/closer.lua/solr/X.Y.Z/solr-X.Y.Z.tgz
+# Example:
+# docker build -f solr-X.Y.Z/docker/Dockerfile - < solr-X.Y.Z.tgz
+
+
ARG BASE_IMAGE=openjdk:11-jre-slim
FROM $BASE_IMAGE as input
-ARG SOLR_VERSION
-# ADD extracts tgz !
-ADD /releases/solr-$SOLR_VERSION.tgz /opt/
-COPY /scripts /scripts
+COPY / /opt/
# remove what we don't want; ensure permissions are right
# TODO; arguably these permissions should have been set correctly previously in the TAR
RUN set -ex; \
- rm -Rf /opt/solr-$SOLR_VERSION/docs /opt/solr-$SOLR_VERSION/dist/{solr-solrj-$SOLR_VERSION.jar,solrj-lib,solr-test-framework-$SOLR_VERSION.jar,test-framework}; \
- find "/opt/solr-$SOLR_VERSION" -type d -print0 | xargs -0 chmod 0755; \
- find "/opt/solr-$SOLR_VERSION" -type f -print0 | xargs -0 chmod 0644; \
- chmod -R 0755 /scripts "/opt/solr-$SOLR_VERSION/bin" "/opt/solr-$SOLR_VERSION/contrib/prometheus-exporter/bin/solr-exporter" "/opt/solr-$SOLR_VERSION/server/scripts/cloud-scripts"
+ (cd /opt; ln -s solr-*/ solr); \
+ rm -Rf /opt/solr/docs /opt/solr/docker/Dockerfile /opt/solr/dist/{solr-solrj-*.jar,solrj-lib,solr-test-framework-*.jar,test-framework}; \
+ find /opt/solr/ -type d -print0 | xargs -0 chmod 0755; \
+ find /opt/solr/ -type f -print0 | xargs -0 chmod 0644; \
+ chmod -R 0755 /opt/solr/docker/scripts /opt/solr/bin /opt/solr/contrib/prometheus-exporter/bin/solr-exporter /opt/solr/server/scripts/cloud-scripts
FROM $BASE_IMAGE
@@ -35,7 +51,7 @@
SOLR_UID="8983" \
SOLR_GROUP="solr" \
SOLR_GID="8983" \
- PATH="/opt/solr/bin:/opt/docker-solr/scripts:/opt/solr/contrib/prometheus-exporter/bin:$PATH" \
+ PATH="/opt/solr/bin:/opt/solr/docker/scripts:/opt/solr/contrib/prometheus-exporter/bin:$PATH" \
SOLR_INCLUDE=/etc/default/solr.in.sh \
SOLR_HOME=/var/solr/data \
SOLR_PID_DIR=/var/solr \
@@ -47,17 +63,9 @@
groupadd -r --gid "$SOLR_GID" "$SOLR_GROUP"; \
useradd -r --uid "$SOLR_UID" --gid "$SOLR_GID" "$SOLR_USER"
-COPY --from=input scripts /opt/docker-solr/scripts
-
-ARG SOLR_VERSION
-
-# Used by solr-fg
-ENV SOLR_VERSION $SOLR_VERSION
-
-COPY --from=input /opt/solr-$SOLR_VERSION /opt/solr-$SOLR_VERSION
+COPY --from=input /opt/ /opt/
RUN set -ex; \
- (cd /opt; ln -s "solr-$SOLR_VERSION" solr); \
mkdir -p /opt/solr/server/solr/lib /docker-entrypoint-initdb.d; \
cp /opt/solr/bin/solr.in.sh /etc/default/solr.in.sh; \
mv /opt/solr/bin/solr.in.sh /opt/solr/bin/solr.in.sh.orig; \
diff --git a/solr/docker/build.gradle b/solr/docker/build.gradle
index 305a50d..4fd9117 100644
--- a/solr/docker/build.gradle
+++ b/solr/docker/build.gradle
@@ -30,64 +30,85 @@
def githubUrlOrMirror = propertyOrEnvOrDefault("solr.docker.githubUrl", "SOLR_DOCKER_GITHUB_URL", 'github.com')
// Build directory locations
-def dockerBuildDistribution = "$buildDir/distributions"
def imageIdFile = "$buildDir/image-id"
configurations {
packaging {
canBeResolved = true
}
+ solrArtifacts {
+ canBeResolved = true
+ }
+ dockerContext {
+ canBeResolved = true
+ }
dockerImage {
canBeResolved = true
}
}
+ext {
+ packagingDir = file("${buildDir}/packaging")
+ dockerContextFile = "context.tgz"
+ dockerContextPath = "${buildDir}/${dockerContextFile}"
+}
+
dependencies {
- packaging project(path: ":solr:packaging", configuration: 'archives')
+ packaging files(packagingDir) {
+ builtBy 'assemblePackaging'
+ }
+
+ solrArtifacts project(path: ":solr:packaging", configuration: 'archives')
+
+ dockerContext files(dockerContextPath) {
+ builtBy 'dockerContext'
+ }
dockerImage files(imageIdFile) {
builtBy 'dockerBuild'
}
}
-task dockerTar(type: Tar) {
- group = 'Docker'
- description = 'Package docker context to prepare for docker build'
+task assemblePackaging(type: Sync) {
+ description = 'Assemble docker scripts and Dockerfile for Solr Packaging'
- dependsOn configurations.packaging
- into('scripts') {
- from file('scripts')
- fileMode 755
- }
- into('releases') {
- from configurations.packaging
- include '*.tgz'
- }
- from file('Dockerfile')
- destinationDirectory = file(dockerBuildDistribution)
- extension 'tgz'
- compression = Compression.GZIP
+ from(projectDir, {
+ include "Dockerfile"
+ include "scripts/**"
+ })
+
+ into packagingDir
}
-task dockerBuild(dependsOn: tasks.dockerTar) {
+task dockerContext(type: Sync) {
+ description = 'Sync Solr tgz to become docker context'
+
+ from(configurations.solrArtifacts, {
+ include "*.tgz"
+ rename { file -> dockerContextFile }
+ })
+
+ into buildDir
+}
+
+task dockerBuild(dependsOn: configurations.dockerContext) {
group = 'Docker'
description = 'Build Solr docker image'
// Ensure that the docker image is rebuilt on build-arg changes or changes in the docker context
inputs.properties([
baseDockerImage: baseDockerImage,
- githubUrlOrMirror: githubUrlOrMirror,
- version: version
+ githubUrlOrMirror: githubUrlOrMirror
])
- inputs.dir(dockerBuildDistribution)
+ inputs.files(dockerContextPath)
doLast {
exec {
- standardInput = tasks.dockerTar.outputs.files.singleFile.newDataInputStream()
+ standardInput = configurations.dockerContext.singleFile.newDataInputStream()
commandLine "docker", "build",
+ "-f", "solr-${version}/docker/Dockerfile",
"--iidfile", imageIdFile,
"--build-arg", "BASE_IMAGE=${inputs.properties.baseDockerImage}",
- "--build-arg", "SOLR_VERSION=${version}",
"--build-arg", "GITHUB_URL=${inputs.properties.githubUrlOrMirror}",
"-"
}
diff --git a/solr/docker/scripts/docker-entrypoint.sh b/solr/docker/scripts/docker-entrypoint.sh
index 69738a9..1a6a3ee 100755
--- a/solr/docker/scripts/docker-entrypoint.sh
+++ b/solr/docker/scripts/docker-entrypoint.sh
@@ -18,7 +18,7 @@
fi
# Essential for running Solr
-/opt/docker-solr/scripts/init-var-solr
+init-var-solr
# when invoked with e.g.: docker run solr -help
if [ "${1:0:1}" == '-' ]; then
@@ -27,7 +27,7 @@
# execute command passed in as arguments.
# The Dockerfile has specified the PATH to include
-# /opt/solr/bin (for Solr) and /opt/docker-solr/scripts (for our scripts
+# /opt/solr/bin (for Solr) and /opt/solr/docker (for docker-specific scripts
# like solr-foreground, solr-create, solr-precreate, solr-demo).
# Note: if you specify "solr", you'll typically want to add -f to run it in
# the foreground.
diff --git a/solr/docker/scripts/solr-create b/solr/docker/scripts/solr-create
index d523ce6..dbd2181 100755
--- a/solr/docker/scripts/solr-create
+++ b/solr/docker/scripts/solr-create
@@ -15,7 +15,7 @@
set -x
fi
-. /opt/docker-solr/scripts/run-initdb
+run-initdb
# solr uses "-c corename". Parse the arguments to determine the core name.
CORE_NAME="$(
diff --git a/solr/docker/scripts/solr-demo b/solr/docker/scripts/solr-demo
index 7d09d39..4217d7d 100755
--- a/solr/docker/scripts/solr-demo
+++ b/solr/docker/scripts/solr-demo
@@ -8,7 +8,7 @@
set -x
fi
-. /opt/docker-solr/scripts/run-initdb
+run-initdb
CORE=demo
diff --git a/solr/docker/scripts/solr-fg b/solr/docker/scripts/solr-fg
index cf43316..13d2623 100755
--- a/solr/docker/scripts/solr-fg
+++ b/solr/docker/scripts/solr-fg
@@ -7,7 +7,7 @@
set -x
fi
-echo "Starting Solr $SOLR_VERSION"
+echo "Starting Solr"
# determine TINI default. If it is already set, assume the user knows what they want
if [[ -z "${TINI:-}" ]]; then
if [[ "$$" == 1 ]]; then
diff --git a/solr/docker/scripts/solr-foreground b/solr/docker/scripts/solr-foreground
index aa9fa68..d91a872 100755
--- a/solr/docker/scripts/solr-foreground
+++ b/solr/docker/scripts/solr-foreground
@@ -7,6 +7,6 @@
set -x
fi
-. /opt/docker-solr/scripts/run-initdb
+run-initdb
exec solr-fg "$@"
diff --git a/solr/docker/scripts/solr-precreate b/solr/docker/scripts/solr-precreate
index 91d0a3d..701dcd1 100755
--- a/solr/docker/scripts/solr-precreate
+++ b/solr/docker/scripts/solr-precreate
@@ -17,8 +17,8 @@
set -x
fi
-. /opt/docker-solr/scripts/run-initdb
+run-initdb
-/opt/docker-solr/scripts/precreate-core "$@"
+precreate-core "$@"
exec solr-fg
diff --git a/solr/docker/scripts/start-local-solr b/solr/docker/scripts/start-local-solr
index 50edf13..309fc94 100755
--- a/solr/docker/scripts/start-local-solr
+++ b/solr/docker/scripts/start-local-solr
@@ -11,7 +11,7 @@
SOLR_OPTS="-Djetty.host=${SOLR_LOCAL_HOST:-localhost}" solr start
max_try=${MAX_TRY:-12}
wait_seconds=${WAIT_SECONDS:-5}
-if ! /opt/docker-solr/scripts/wait-for-solr.sh --max-attempts "$max_try" --wait-seconds "$wait_seconds"; then
+if ! wait-for-solr.sh --max-attempts "$max_try" --wait-seconds "$wait_seconds"; then
echo "Could not start Solr."
if [ -f "/var/solr/logs/solr.log" ]; then
echo "Here is the log:"
diff --git a/solr/docker/tests/shared.sh b/solr/docker/tests/shared.sh
index 6b4e211..49dcdae 100755
--- a/solr/docker/tests/shared.sh
+++ b/solr/docker/tests/shared.sh
@@ -25,7 +25,7 @@
printf '\nWaiting for Solr...\n'
local status
- status=$(docker exec "$container_name" /opt/docker-solr/scripts/wait-for-solr.sh --max-attempts 60 --wait-seconds 1)
+ status=$(docker exec "$container_name" wait-for-solr.sh --max-attempts 60 --wait-seconds 1)
# echo "Got status from Solr: $status"
if ! grep -E -i -q 'Solr is running' <<<"$status"; then
echo "Solr did not start"
diff --git a/solr/packaging/build.gradle b/solr/packaging/build.gradle
index f533b3f..1a15ce4 100644
--- a/solr/packaging/build.gradle
+++ b/solr/packaging/build.gradle
@@ -39,6 +39,7 @@
example
server
docs
+ docker
}
dependencies {
@@ -68,6 +69,8 @@
// Copy files from documentation output
docs project(path: ':solr:documentation', configuration: 'minimalSite')
+
+ docker project(path: ':solr:docker', configuration: 'packaging')
}
distributions {
@@ -84,6 +87,7 @@
"**/bin/solr",
"**/bin/init.d/solr",
"**/bin/solr-exporter",
+ "**/docker/scripts/*",
]) { copy ->
copy.setMode(0755)
}
@@ -129,6 +133,11 @@
from(configurations.docs, {
into "docs"
})
+
+ from(configurations.docker, {
+ into "docker"
+ })
+
}
}
}