This repository has been archived by the owner on Aug 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,658 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
|
||
FROM openjdk:11-jre | ||
|
||
LABEL maintainer="The Apache Lucene/Solr Project" | ||
LABEL repository="https://github.com/docker-solr/docker-solr" | ||
|
||
ARG SOLR_VERSION="8.6.0" | ||
ARG SOLR_SHA512="6b0d618069e37215f305d9a61a3e65be2b9cfc32a3689ea6a25be2f220b1ecc96a644ecc31c81e335a2dfa0bc8b7d0f2881ca192c36fd435cdd832fd309a9ddb" | ||
ARG SOLR_KEYS="38DA0C3CE8181703A08E4D57377C3BA26AD29C0A" | ||
# If specified, this will override SOLR_DOWNLOAD_SERVER and all ASF mirrors. Typically used downstream for custom builds | ||
ARG SOLR_DOWNLOAD_URL | ||
|
||
# Override the solr download location with e.g.: | ||
# docker build -t mine --build-arg SOLR_DOWNLOAD_SERVER=http://www-eu.apache.org/dist/lucene/solr . | ||
ARG SOLR_DOWNLOAD_SERVER | ||
|
||
RUN set -ex; \ | ||
apt-get update; \ | ||
apt-get -y install acl dirmngr gpg lsof procps wget netcat gosu tini; \ | ||
rm -rf /var/lib/apt/lists/*; \ | ||
cd /usr/local/bin; wget -nv https://github.com/apangin/jattach/releases/download/v1.5/jattach; chmod 755 jattach; \ | ||
echo >jattach.sha512 "d8eedbb3e192a8596c08efedff99b9acf1075331e1747107c07cdb1718db2abe259ef168109e46bd4cf80d47d43028ff469f95e6ddcbdda4d7ffa73a20e852f9 jattach"; \ | ||
sha512sum -c jattach.sha512; rm jattach.sha512 | ||
|
||
ENV SOLR_USER="solr" \ | ||
SOLR_UID="8983" \ | ||
SOLR_GROUP="solr" \ | ||
SOLR_GID="8983" \ | ||
SOLR_CLOSER_URL="http://www.apache.org/dyn/closer.lua?filename=lucene/solr/$SOLR_VERSION/solr-$SOLR_VERSION.tgz&action=download" \ | ||
SOLR_DIST_URL="https://www.apache.org/dist/lucene/solr/$SOLR_VERSION/solr-$SOLR_VERSION.tgz" \ | ||
SOLR_ARCHIVE_URL="https://archive.apache.org/dist/lucene/solr/$SOLR_VERSION/solr-$SOLR_VERSION.tgz" \ | ||
PATH="/opt/solr/bin:/opt/docker-solr/scripts:$PATH" \ | ||
SOLR_INCLUDE=/etc/default/solr.in.sh \ | ||
SOLR_HOME=/var/solr/data \ | ||
SOLR_PID_DIR=/var/solr \ | ||
SOLR_LOGS_DIR=/var/solr/logs \ | ||
LOG4J_PROPS=/var/solr/log4j2.xml | ||
|
||
RUN set -ex; \ | ||
groupadd -r --gid "$SOLR_GID" "$SOLR_GROUP"; \ | ||
useradd -r --uid "$SOLR_UID" --gid "$SOLR_GID" "$SOLR_USER" | ||
|
||
RUN set -ex; \ | ||
export GNUPGHOME="/tmp/gnupg_home"; \ | ||
mkdir -p "$GNUPGHOME"; \ | ||
chmod 700 "$GNUPGHOME"; \ | ||
echo "disable-ipv6" >> "$GNUPGHOME/dirmngr.conf"; \ | ||
for key in $SOLR_KEYS; do \ | ||
found=''; \ | ||
for server in \ | ||
ha.pool.sks-keyservers.net \ | ||
hkp://keyserver.ubuntu.com:80 \ | ||
hkp://p80.pool.sks-keyservers.net:80 \ | ||
pgp.mit.edu \ | ||
; do \ | ||
echo " trying $server for $key"; \ | ||
gpg --batch --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$key" && found=yes && break; \ | ||
gpg --batch --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$key" && found=yes && break; \ | ||
done; \ | ||
test -z "$found" && echo >&2 "error: failed to fetch $key from several disparate servers -- network issues?" && exit 1; \ | ||
done; \ | ||
exit 0 | ||
|
||
RUN set -ex; \ | ||
export GNUPGHOME="/tmp/gnupg_home"; \ | ||
MAX_REDIRECTS=1; \ | ||
if [ -n "$SOLR_DOWNLOAD_URL" ]; then \ | ||
# If a custom URL is defined, we download from non-ASF mirror URL and allow more redirects and skip GPG step | ||
# This takes effect only if the SOLR_DOWNLOAD_URL build-arg is specified, typically in downstream Dockerfiles | ||
MAX_REDIRECTS=4; \ | ||
SKIP_GPG_CHECK=true; \ | ||
elif [ -n "$SOLR_DOWNLOAD_SERVER" ]; then \ | ||
SOLR_DOWNLOAD_URL="$SOLR_DOWNLOAD_SERVER/$SOLR_VERSION/solr-$SOLR_VERSION.tgz"; \ | ||
fi; \ | ||
for url in $SOLR_DOWNLOAD_URL $SOLR_CLOSER_URL $SOLR_DIST_URL $SOLR_ARCHIVE_URL; do \ | ||
if [ -f "/opt/solr-$SOLR_VERSION.tgz" ]; then break; fi; \ | ||
echo "downloading $url"; \ | ||
if wget -t 10 --max-redirect $MAX_REDIRECTS --retry-connrefused -nv "$url" -O "/opt/solr-$SOLR_VERSION.tgz"; then break; else rm -f "/opt/solr-$SOLR_VERSION.tgz"; fi; \ | ||
done; \ | ||
if [ ! -f "/opt/solr-$SOLR_VERSION.tgz" ]; then echo "failed all download attempts for solr-$SOLR_VERSION.tgz"; exit 1; fi; \ | ||
if [ -z "$SKIP_GPG_CHECK" ]; then \ | ||
echo "downloading $SOLR_ARCHIVE_URL.asc"; \ | ||
wget -nv "$SOLR_ARCHIVE_URL.asc" -O "/opt/solr-$SOLR_VERSION.tgz.asc"; \ | ||
echo "$SOLR_SHA512 */opt/solr-$SOLR_VERSION.tgz" | sha512sum -c -; \ | ||
(>&2 ls -l "/opt/solr-$SOLR_VERSION.tgz" "/opt/solr-$SOLR_VERSION.tgz.asc"); \ | ||
gpg --batch --verify "/opt/solr-$SOLR_VERSION.tgz.asc" "/opt/solr-$SOLR_VERSION.tgz"; \ | ||
else \ | ||
echo "Skipping GPG validation due to non-Apache build"; \ | ||
fi; \ | ||
tar -C /opt --extract --file "/opt/solr-$SOLR_VERSION.tgz"; \ | ||
(cd /opt; ln -s "solr-$SOLR_VERSION" solr); \ | ||
rm "/opt/solr-$SOLR_VERSION.tgz"*; \ | ||
rm -Rf /opt/solr/docs/ /opt/solr/dist/{solr-core-$SOLR_VERSION.jar,solr-solrj-$SOLR_VERSION.jar,solrj-lib,solr-test-framework-$SOLR_VERSION.jar,test-framework}; \ | ||
mkdir -p /opt/solr/server/solr/lib /docker-entrypoint-initdb.d /opt/docker-solr; \ | ||
chown -R 0:0 "/opt/solr-$SOLR_VERSION"; \ | ||
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 "/opt/solr-$SOLR_VERSION/bin" "/opt/solr-$SOLR_VERSION/contrib/prometheus-exporter/bin/solr-exporter" /opt/solr-$SOLR_VERSION/server/scripts/cloud-scripts; \ | ||
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; \ | ||
mv /opt/solr/bin/solr.in.cmd /opt/solr/bin/solr.in.cmd.orig; \ | ||
chown root:0 /etc/default/solr.in.sh; \ | ||
chmod 0664 /etc/default/solr.in.sh; \ | ||
mkdir -p /var/solr/data /var/solr/logs; \ | ||
(cd /opt/solr/server/solr; cp solr.xml zoo.cfg /var/solr/data/); \ | ||
cp /opt/solr/server/resources/log4j2.xml /var/solr/log4j2.xml; \ | ||
find /var/solr -type d -print0 | xargs -0 chmod 0770; \ | ||
find /var/solr -type f -print0 | xargs -0 chmod 0660; \ | ||
sed -i -e "s/\"\$(whoami)\" == \"root\"/\$(id -u) == 0/" /opt/solr/bin/solr; \ | ||
sed -i -e 's/lsof -PniTCP:/lsof -t -PniTCP:/' /opt/solr/bin/solr; \ | ||
chown -R "0:0" /opt/solr-$SOLR_VERSION /docker-entrypoint-initdb.d /opt/docker-solr; \ | ||
chown -R "$SOLR_USER:0" /var/solr; \ | ||
{ command -v gpgconf; gpgconf --kill all || :; }; \ | ||
rm -r "$GNUPGHOME" | ||
|
||
COPY --chown=0:0 scripts /opt/docker-solr/scripts | ||
|
||
VOLUME /var/solr | ||
EXPOSE 8983 | ||
WORKDIR /opt/solr | ||
USER $SOLR_USER | ||
|
||
ENTRYPOINT ["docker-entrypoint.sh"] | ||
CMD ["solr-foreground"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/bash | ||
# | ||
# docker-entrypoint for docker-solr | ||
|
||
set -e | ||
|
||
# Clear some variables that we don't want runtime | ||
unset SOLR_USER SOLR_UID SOLR_GROUP SOLR_GID \ | ||
SOLR_CLOSER_URL SOLR_DIST_URL SOLR_ARCHIVE_URL SOLR_DOWNLOAD_URL SOLR_DOWNLOAD_SERVER SOLR_KEYS SOLR_SHA512 | ||
|
||
if [[ "$VERBOSE" == "yes" ]]; then | ||
set -x | ||
fi | ||
|
||
if [[ -v SOLR_PORT ]] && ! grep -E -q '^[0-9]+$' <<<"${SOLR_PORT:-}"; then | ||
SOLR_PORT=8983 | ||
export SOLR_PORT | ||
fi | ||
|
||
# when invoked with e.g.: docker run solr -help | ||
if [ "${1:0:1}" == '-' ]; then | ||
set -- solr-foreground "$@" | ||
fi | ||
|
||
# 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 | ||
# 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. | ||
exec "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/bin/bash | ||
# | ||
# A helper script to initialise an empty $DIR | ||
# If you use volumes then Docker will copy the $DIR content from the container to the volume. | ||
# If you use bind mounts, that does not happen, so we do it here. | ||
|
||
set -e | ||
|
||
if [[ "$VERBOSE" == "yes" ]]; then | ||
set -x | ||
fi | ||
|
||
if [[ -n "${NO_INIT_VAR_SOLR:-}" ]]; then | ||
exit 0 | ||
fi | ||
|
||
DIR=${1:-/var/solr} | ||
|
||
if [ ! -d "$DIR" ]; then | ||
echo "Missing $DIR" | ||
exit 1 | ||
fi | ||
|
||
function check_dir_writability { | ||
local dir="$1" | ||
if [ ! -w "$dir" ]; then | ||
echo "Cannot write to $dir as $(id -u):$(id -g)" | ||
ls -ld "$dir" | ||
exit 1 | ||
fi | ||
} | ||
|
||
if [ ! -d "$DIR/data" ]; then | ||
echo "Creating $DIR/data" | ||
check_dir_writability "$DIR" | ||
mkdir "$DIR/data" | ||
chmod 0770 "$DIR/data" | ||
fi | ||
|
||
if [ ! -d "$DIR/logs" ]; then | ||
echo "Creating $DIR/logs" | ||
check_dir_writability "$DIR" | ||
mkdir "$DIR/logs" | ||
chmod 0770 "$DIR/logs" | ||
fi | ||
|
||
if [ ! -f "$DIR/data/solr.xml" ]; then | ||
echo "Copying solr.xml" | ||
cp -a /opt/solr/server/solr/solr.xml "$DIR/data/solr.xml" | ||
fi | ||
|
||
if [ ! -f "$DIR/data/zoo.cfg" ]; then | ||
echo "Copying zoo.cfg" | ||
cp -a /opt/solr/server/solr/zoo.cfg "$DIR/data/zoo.cfg" | ||
fi | ||
|
||
if [ ! -f "$DIR/log4j2.xml" ]; then | ||
echo "Copying log4j2.xml" | ||
cp -a /opt/solr/server/resources/log4j2.xml "$DIR/log4j2.xml" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/bin/bash | ||
|
||
# Custom oom handler loosely based on | ||
# https://github.com/apache/lucene-solr/blob/master/solr/bin/oom_solr.sh | ||
# See solr-forgeground for how to configure OOM behaviour | ||
|
||
if [[ -z "${SOLR_LOGS_DIR:-}" ]]; then | ||
if [ -d /var/solr/logs ]; then | ||
SOLR_LOGS_DIR=/var/solr/logs | ||
elif [ -d /opt/solr/server/logs ]; then | ||
SOLR_LOGS_DIR=/opt/solr/server/logs | ||
else | ||
echo "Cannot determine SOLR_LOGS_DIR!" | ||
exit 1 | ||
fi | ||
fi | ||
SOLR_PID=$(pgrep -f start.jar) | ||
if [[ -z "$SOLR_PID" ]]; then | ||
echo "Couldn't find Solr process running!" | ||
exit | ||
fi | ||
|
||
NOW=$(date +"%F_%H_%M_%S") | ||
( | ||
echo "Running OOM killer script for Solr process $SOLR_PID" | ||
if [[ "$SOLR_PID" == 1 ]]; then | ||
# under Docker, when running as pid 1, a SIGKILL is ignored, | ||
# so use the default SIGTERM | ||
kill "$SOLR_PID" | ||
sleep 2 | ||
# if that hasn't worked, send SIGKILL | ||
kill -SIGILL "$SOLR_PID" | ||
else | ||
# if we're running with `--init` or under tini or similar, | ||
# follow the upstream behaviour | ||
kill -9 "$SOLR_PID" | ||
fi | ||
) | tee "$SOLR_LOGS_DIR/solr_oom_killer-$SOLR_PORT-$NOW.log" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# | ||
# Create a core on disk | ||
# arguments are: corename configdir | ||
|
||
set -e | ||
|
||
echo "Executing $0" "$@" | ||
|
||
if [[ "${VERBOSE:-}" == "yes" ]]; then | ||
set -x | ||
fi | ||
|
||
CORE=${1:-gettingstarted} | ||
CONFIG_SOURCE="${2:-}" | ||
if [[ -z "$CONFIG_SOURCE" ]]; then | ||
DEFAULT_CONFIGS=(_default data_driven_schema_configs) | ||
for config_dir in "${DEFAULT_CONFIGS[@]}"; do | ||
config_dir="/opt/solr/server/solr/configsets/$config_dir" | ||
if [ -d "$config_dir" ]; then | ||
CONFIG_SOURCE="$config_dir" | ||
break | ||
fi | ||
done | ||
if [[ -z $CONFIG_SOURCE ]]; then | ||
echo "Cannot find default config" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
coresdir=/var/solr/data | ||
|
||
coredir="$coresdir/$CORE" | ||
if [[ ! -d $coredir ]]; then | ||
cp -r "$CONFIG_SOURCE/" "$coredir" | ||
touch "$coredir/core.properties" | ||
echo "Created $CORE" | ||
else | ||
echo "Core $CORE already exists" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# | ||
# Run the init-solr-home script and source any '.sh' scripts in | ||
# /docker-entrypoint-initdb.d. | ||
# This script is sourced by some of the solr-* commands, so that | ||
# you can run eg: | ||
# | ||
# mkdir initdb; echo "echo hi" > initdb/hi.sh | ||
# docker run -v $PWD/initdb:/docker-entrypoint-initdb.d solr | ||
# | ||
# and have your script execute before Solr starts. | ||
# | ||
# Note: scripts can modify the environment, which will affect | ||
# subsequent scripts and ultimately Solr. That allows you to set | ||
# environment variables from your scripts (though you usually just | ||
# use "docker run -e"). If this is undesirable in your use-case, | ||
# have your scripts execute a sub-shell. | ||
|
||
set -e | ||
|
||
# execute files in /docker-entrypoint-initdb.d before starting solr | ||
while read -r f; do | ||
case "$f" in | ||
*.sh) echo "$0: running $f"; . "$f" ;; | ||
*) echo "$0: ignoring $f" ;; | ||
esac | ||
echo | ||
done < <(find /docker-entrypoint-initdb.d/ -mindepth 1 -type f | sort -n) |
Oops, something went wrong.