Skip to content

Commit 2b8d7bc

Browse files
SOLR-15075: Solr docker gradle improvements (#2197)
* Removed docker plugin from gradle builds. * Removed package docker image. * Tasks now have correct inputs/outputs/dependencies. * Move gradle help text to docker folder. * Reduce duplicated Docker layer by doing file removal and chmod in another stage. Co-authored-by: David Smiley <[email protected]>
1 parent 6c72e2e commit 2b8d7bc

26 files changed

+252
-254
lines changed

.github/workflows/docker-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
restore-keys: |
3939
${{ runner.os }}-gradle-docker-
4040
${{ runner.os }}-gradle-
41+
- name: Initialize gradle settings
42+
run: ./gradlew localSettings
4143
- name: Build Docker image with Gradle
4244
run: ./gradlew solr:docker:docker
4345
- name: Run tests on Docker image

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ plugins {
2525
id 'de.thetaphi.forbiddenapis' version '3.1' apply false
2626
id "de.undercouch.download" version "4.0.2" apply false
2727
id "net.ltgt.errorprone" version "1.2.1" apply false
28-
id "com.palantir.docker" version "0.25.0" apply false
2928
id 'com.diffplug.spotless' version "5.8.2" apply false
3029
}
3130

gradle/help.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ configure(rootProject) {
3030
["Git", "help/git.txt", "Git assistance and guides."],
3131
["ValidateLogCalls", "help/validateLogCalls.txt", "How to use logging calls efficiently."],
3232
["IDEs", "help/IDEs.txt", "IDE support."],
33-
["Docker", "help/docker.txt", "Building Solr Docker images."],
33+
["Docker", "solr/docker/gradle-help.txt", "Building Solr Docker images."],
3434
]
3535

3636
helpFiles.each { section, path, sectionInfo ->

help/docker.txt

Lines changed: 0 additions & 58 deletions
This file was deleted.

settings.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,3 @@ include "solr:example"
7474
include "solr:documentation"
7575
include "solr:packaging"
7676
include "solr:docker"
77-
include "solr:docker:package"

solr/docker/Dockerfile

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
ARG SOLR_PACKAGE_IMAGE
21
ARG BASE_IMAGE=openjdk:11-jre-slim
32

4-
FROM $SOLR_PACKAGE_IMAGE as solr_package
3+
FROM $BASE_IMAGE as input
4+
ARG SOLR_VERSION
5+
6+
# ADD extracts tgz !
7+
ADD /releases/solr-$SOLR_VERSION.tgz /opt/
8+
COPY /scripts /scripts
9+
10+
# remove what we don't want; ensure permissions are right
11+
# TODO; arguably these permissions should have been set correctly previously in the TAR
12+
RUN set -ex; \
13+
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}; \
14+
find "/opt/solr-$SOLR_VERSION" -type d -print0 | xargs -0 chmod 0755; \
15+
find "/opt/solr-$SOLR_VERSION" -type f -print0 | xargs -0 chmod 0644; \
16+
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"
517

6-
FROM $BASE_IMAGE as runtime
18+
FROM $BASE_IMAGE
719

820
LABEL maintainer="The Apache Lucene/Solr Project"
921
LABEL repository="https://github.com/apache/lucene-solr"
@@ -13,7 +25,7 @@ ARG GITHUB_URL=github.com
1325

1426
RUN set -ex; \
1527
apt-get update; \
16-
apt-get -y install acl dirmngr gpg lsof procps wget netcat gosu tini; \
28+
apt-get -y install acl dirmngr lsof procps wget netcat gosu tini; \
1729
rm -rf /var/lib/apt/lists/*; \
1830
cd /usr/local/bin; wget -nv https://${GITHUB_URL}/apangin/jattach/releases/download/v1.5/jattach; chmod 755 jattach; \
1931
echo >jattach.sha512 "d8eedbb3e192a8596c08efedff99b9acf1075331e1747107c07cdb1718db2abe259ef168109e46bd4cf80d47d43028ff469f95e6ddcbdda4d7ffa73a20e852f9 jattach"; \
@@ -35,34 +47,25 @@ RUN set -ex; \
3547
groupadd -r --gid "$SOLR_GID" "$SOLR_GROUP"; \
3648
useradd -r --uid "$SOLR_UID" --gid "$SOLR_GID" "$SOLR_USER"
3749

38-
COPY --chown=0:0 scripts /opt/docker-solr/scripts
50+
COPY --from=input scripts /opt/docker-solr/scripts
3951

4052
ARG SOLR_VERSION
4153

4254
# Used by solr-fg
4355
ENV SOLR_VERSION $SOLR_VERSION
4456

45-
COPY --from=solr_package "/opt/solr-$SOLR_VERSION.tgz" "/opt/solr-$SOLR_VERSION.tgz"
57+
COPY --from=input /opt/solr-$SOLR_VERSION /opt/solr-$SOLR_VERSION
4658

4759
RUN set -ex; \
48-
tar -C /opt --extract --file "/opt/solr-$SOLR_VERSION.tgz" && \
49-
rm "/opt/solr-$SOLR_VERSION.tgz"; \
5060
(cd /opt; ln -s "solr-$SOLR_VERSION" solr); \
51-
rm -Rf /opt/solr/docs/ /opt/solr/dist/{solr-solrj-$SOLR_VERSION.jar,solrj-lib,solr-test-framework-$SOLR_VERSION.jar,test-framework}; \
52-
mkdir -p /opt/solr/server/solr/lib /docker-entrypoint-initdb.d /opt/docker-solr; \
53-
chown -R 0:0 "/opt/solr-$SOLR_VERSION"; \
54-
find "/opt/solr-$SOLR_VERSION" -type d -print0 | xargs -0 chmod 0755; \
55-
find "/opt/solr-$SOLR_VERSION" -type f -print0 | xargs -0 chmod 0644; \
56-
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; \
61+
mkdir -p /opt/solr/server/solr/lib /docker-entrypoint-initdb.d; \
5762
cp /opt/solr/bin/solr.in.sh /etc/default/solr.in.sh; \
5863
mv /opt/solr/bin/solr.in.sh /opt/solr/bin/solr.in.sh.orig; \
5964
mv /opt/solr/bin/solr.in.cmd /opt/solr/bin/solr.in.cmd.orig; \
60-
chown root:0 /etc/default/solr.in.sh; \
6165
chmod 0664 /etc/default/solr.in.sh; \
6266
mkdir -p -m0770 /var/solr; \
6367
sed -i -e "s/\"\$(whoami)\" == \"root\"/\$(id -u) == 0/" /opt/solr/bin/solr; \
6468
sed -i -e 's/lsof -PniTCP:/lsof -t -PniTCP:/' /opt/solr/bin/solr; \
65-
chown -R "0:0" /opt/solr-$SOLR_VERSION /docker-entrypoint-initdb.d /opt/docker-solr; \
6669
chown -R "$SOLR_USER:0" /var/solr;
6770

6871
VOLUME /var/solr

solr/docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ If you want to persist the data, mount a volume or directory on `/var/solr`.
7676
Solr expects some files and directories in `/var/solr`; if you use your own directory or volume you can either pre-populate them, or let Solr docker copy them for you. See [init-var-solr](scripts/init-var-solr).
7777
If you want to use custom configuration, mount it in the appropriate place. See below for examples.
7878

79-
The Solr docker distribution adds [scripts](include/scripts) in `/opt/docker-solr/scripts` to make it easier to use under Docker, for example to create cores on container startup.
79+
The Solr docker distribution adds [scripts](scripts) in `/opt/docker-solr/scripts` to make it easier to use under Docker, for example to create cores on container startup.
8080

8181
## Creating cores
8282

0 commit comments

Comments
 (0)