Skip to content

Commit 7680363

Browse files
committed
Merge pull request uselagoon#552 from amazeeio/537-solr-lockfile
uselagoon#537 - change solr to no lock
2 parents d621823 + 1364290 commit 7680363

File tree

9 files changed

+187
-14
lines changed

9 files changed

+187
-14
lines changed

docs/using_lagoon/drupal/services/solr.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,25 @@ FROM amazeeio/solr:6.6
2222
2323
COPY .lagoon/solr /solr-conf/conf
2424
25-
CMD ["solr-precreate", "drupal", "/solr-conf"]
25+
RUN precreate-core drupal /solr-conf
26+
27+
CMD ["solr-foreground"]
2628
```
2729

2830
The goal is to have your solr configuration files exist at `/solr-conf/conf` in the image you are building.
2931

3032
## Multiple cores
3133

32-
To implement multiple cores, you will also need to ship your own solr schema as above, the only change needed is to the `CMD` of the Dockerfile, repeat the pattern of `precreate corename /solr-conf/ ;` for each core you require.
34+
To implement multiple cores, you will also need to ship your own solr schema as above, the only change needed is to the `CMD` of the Dockerfile, repeat the pattern of `precreate-core corename /solr-conf/ ;` for each core you require.
3335

3436
```
35-
CMD ["sh", "-c", "precreate-core drupal /solr-conf/ ; precreate-core core1 /solr-conf/ ; precreate-core core2 /solr-conf/ ; precreate-core core3 /solr-conf/ ; solr start -f"]
37+
38+
FROM amazeeio/solr:6.6-drupal
39+
40+
RUN precreate-core drupal-index1 /solr-conf && \
41+
precreate-core drupal-index2 /solr-conf && \
42+
precreate-core drupal-index3 /solr-conf
43+
44+
CMD ["solr-foreground"]
45+
3646
```

images/oc-build-deploy-dind/openshift-templates/solr/deployment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ objects:
103103
value: ${CRONJOBS}
104104
volumeMounts:
105105
- name: ${SERVICE_NAME}
106-
mountPath: /opt/solr/server/solr/mycores
106+
mountPath: /var/solr
107107
resources:
108108
requests:
109109
cpu: 10m

images/solr-drupal/Dockerfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ ARG SOLR_MAJ_MIN_VERSION
55

66
COPY solr${SOLR_MAJ_MIN_VERSION} /solr-conf
77

8-
CMD ["solr-precreate", "drupal", "/solr-conf"]
8+
RUN precreate-core drupal /solr-conf
9+
10+
CMD ["solr-foreground"]

images/solr-drupal/solr5.5/conf/solrconfig.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
replication is in use, this should match the replication
111111
configuration.
112112
-->
113-
<dataDir>${solr.data.dir:}</dataDir>
113+
<dataDir>/var/solr/${solr.core.name}</dataDir>
114114

115115
<!-- The DirectoryFactory to use for indexes.
116116
@@ -256,7 +256,7 @@
256256
More details on the nuances of each LockFactory...
257257
http://wiki.apache.org/lucene-java/AvailableLockFactories
258258
-->
259-
<lockType>${solr.lock.type:native}</lockType>
259+
<lockType>${solr.lock.type:none}</lockType>
260260

261261
<!-- Expert: Controls how often Lucene loads terms into memory
262262
Default is 128 and is likely good for most everyone.

images/solr-drupal/solr6.6/conf/solrconfig.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
replication is in use, this should match the replication
114114
configuration.
115115
-->
116-
<dataDir>${solr.data.dir:}</dataDir>
116+
<dataDir>/var/solr/${solr.core.name}</dataDir>
117117

118118

119119
<!-- The DirectoryFactory to use for indexes.
@@ -246,7 +246,7 @@
246246
More details on the nuances of each LockFactory...
247247
http://wiki.apache.org/lucene-java/AvailableLockFactories
248248
-->
249-
<lockType>${solr.lock.type:native}</lockType>
249+
<lockType>${solr.lock.type:none}</lockType>
250250

251251
<!-- Commit Deletion Policy
252252
Custom deletion policies can be specified here. The class must

images/solr/20-solr-datadir.sh

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/bin/sh
2+
set -eo pipefail
3+
4+
# Previously the Solr Config and Solr Data Dir was both kept in the persistent volume:
5+
# - Solr data: /opt/solr/server/solr/mycores/${corename}/data
6+
# - Solr config: /opt/solr/server/solr/mycores/${corename}/config
7+
# - Persistent Volume: /opt/solr/server/solr/mycores/
8+
# The Solr Config was copied from the Docker Image into the Solr Config directory on the very first time solr started.
9+
# This had the problem that if a new Solr Config was shipped in a new Docker Iamage the config was not copied again.
10+
# Therefore there was no possibility to ship with updated configs and also the system does not follow any other
11+
# services like nginx or php which have their configs not existing in persistent volumes and insted in Docker Images.
12+
# The following script migrates from to the new directory structure:
13+
# - Solr data: /var/solr/${corename}
14+
# - Solr config: /opt/solr/server/solr/mycores/${corename}/config
15+
# - Persistent Volume: /var/solr/
16+
# It does:
17+
# 1. Move folders from /var/solr/${corename}/data to /var/solr/${corename} - this is needed if the existing persistent volume is
18+
# mounted now to /var/solr/ but the data is still within data/
19+
# 2. Create the folder /opt/solr/server/solr/mycores/${corename} if not existing (because there is no persistent volume mounted anymore)
20+
# and copy the config from the persistent storage to that folder.
21+
22+
# It then also tries to update existing non-compatible configs inside solrconfig.xml:
23+
# - dataDir now needs to be `<dataDir>/var/solr/${solr.core.name}</dataDir>` to point to the new persistent Volume
24+
# - lockType needs to be `<lockType>${solr.lock.type:none}</lockType>` to prevent issues with the default file based Lock system which
25+
# can cause issues if the solr is not stopped correctly
26+
# The script does that for existing configs in `/opt/solr/server/solr/mycores/${corename}/config` if that folder exists which can be on two cases:
27+
# 1. During a docker build the solr core has already been created via `precreate-core` (which should be used now all the time)
28+
# 2. The first part of the script has copied the config from the previous persistent volume into these folders
29+
# If `/opt/solr/server/solr/mycores` is empty, this means the container has never been started, had no previous persistent volume and also did not
30+
# run `precreate-core` yet, it checks if the common used folder `/solr-conf/conf/` has a config in it and tries to adapt it.
31+
# This probably fails because of permissions issues, it will throw an error and exit.
32+
33+
if [ ! -n "$(ls /opt/solr/server/solr/mycores)" ]; then
34+
echo 'No pre-created Solr Cores found in `/opt/solr/server/solr/mycores` this probably means that your Dockerfile does not run'
35+
echo ' RUN precreate-core corename /solr-conf'
36+
echo 'within Dockerfile and instead uses'
37+
echo ' CMD ["solr-precreate", "corename", "/solr-conf"]'
38+
echo 'Please update your Dockerfile to:'
39+
echo ' RUN precreate-core corename /solr-conf'
40+
echo ' CMD ["solr-foreground"]'
41+
printf "\n\n"
42+
fi
43+
44+
if [ -n "$(ls /var/solr)" ]; then
45+
# Iterate through all existing solr cores
46+
for solrcorepath in $(ls -d /var/solr/*) ; do
47+
corename=$(basename $solrcorepath)
48+
if [ -d ${solrcorepath}/data ]; then
49+
echo "${solrcorepath} has it's data in deprecated location ${solrcorepath}/data, moving to ${solrcorepath}."
50+
# moving the contents of /var/solr/${corename}/data to /var/solr/${corename}
51+
# the datadir now has the layout that a newly created core would.
52+
mv ${solrcorepath}/data/* ${solrcorepath}/
53+
# remove empty directory
54+
rm -Rf ${solrcorepath}/data || mv ${solrcorepath}/data ${solrcorepath}/data-delete
55+
fi
56+
57+
# If the core has no files in /opt/solr/server/solr/mycores/${corename} this means:
58+
# The Docker Image did not run `precreate-core corename /solr-conf` during the Dockerfile
59+
# and instead is running `solr-precreate corname solr-conf` as CMD of the container.
60+
# But we already have an existing solr config from the persistent storage, we copy that over
61+
if [ ! -d /opt/solr/server/solr/mycores/${corename} ]; then
62+
mkdir -p /opt/solr/server/solr/mycores/${corename}
63+
# Copy the solr config from the persistent volume in the solr home config directory
64+
cp -R ${solrcorepath}/conf /opt/solr/server/solr/mycores/${corename}/
65+
echo "copied pre-existing solr config from '${solrcorepath}/conf' to '/opt/solr/server/solr/mycores/${corename}/conf'"
66+
printf "\n\n"
67+
# there must be a core.properties to be recognized as a core
68+
touch /opt/solr/server/solr/mycores/${corename}/core.properties
69+
fi
70+
done
71+
fi
72+
73+
function fixConfig {
74+
fail=0
75+
if cat $1/solrconfig.xml | grep dataDir | grep -qv '<dataDir>/var/solr/${solr.core.name}</dataDir>'; then
76+
echo "Found old non lagoon compatible dataDir config in solrconfig.xml:"
77+
cat $1/solrconfig.xml | grep dataDir
78+
if [ -w $1/ ]; then
79+
sed -ibak 's/<dataDir>.*/<dataDir>\/var\/solr\/${solr.core.name}<\/dataDir>/' $1/solrconfig.xml
80+
echo "automagically updated to compatible config: "
81+
echo ' <dataDir>/var/solr/${solr.core.name}</dataDir>'
82+
echo "Please update your solrconfig.xml to make this persistent."
83+
else
84+
echo "but no write permission to automagically change to compatible config: "
85+
echo ' <dataDir>/var/solr/${solr.core.name}</dataDir>'
86+
echo "Please update your solrconfig.xml and commit again."
87+
fail=1
88+
fi
89+
printf "\n\n"
90+
fi
91+
# change lockType to none
92+
if cat $1/solrconfig.xml | grep lockType | grep -qv '<lockType>${solr.lock.type:none}</lockType>'; then
93+
echo "Found old non lagoon compatible lockType config in solrconfig.xml:"
94+
cat $1/solrconfig.xml | grep lockType
95+
if [ -w $1/ ]; then
96+
sed -ibak 's/<lockType>\${solr\.lock\.type:native}<\/lockType>/<lockType>${solr.lock.type:none}<\/lockType>/' $1/solrconfig.xml
97+
echo "automagically updated to compatible config: "
98+
echo ' <lockType>${solr.lock.type:none}</lockType>'
99+
echo "Please update your solrconfig.xml to make this persistent."
100+
else
101+
echo "but no write permission to automagically change to compatible config: "
102+
echo ' <lockType>${solr.lock.type:none}</lockType>'
103+
echo "Please update your solrconfig.xml and commit again."
104+
fail=1
105+
fi
106+
printf "\n\n"
107+
fi
108+
if [ "$fail" == "1" ]; then
109+
exit 1;
110+
fi
111+
}
112+
113+
# check if `/opt/solr/server/solr/mycores` has cores, which means that `precreate-core` has already be called so we check the configs there
114+
if [ -n "$(ls /opt/solr/server/solr/mycores)" ]; then
115+
# Iterate through all solr cores
116+
for solrcorepath in $(ls -d /opt/solr/server/solr/mycores/*) ; do
117+
corename=$(basename $solrcorepath)
118+
# Check and Update the solr config with lagoon compatible config
119+
if [ -f /opt/solr/server/solr/mycores/${corename}/conf/solrconfig.xml ]; then
120+
fixConfig /opt/solr/server/solr/mycores/${corename}/conf
121+
fi
122+
done
123+
else
124+
# `/opt/solr/server/solr/mycores` is empty, meaning that no `precreate-core` has been called and probably this container is started via `solr-precreate
125+
# We try to update the solr configs within `/solr-conf/conf` to the new lagoon default config as this one will most probably be used to create a new core
126+
if [ -f /solr-conf/conf/solrconfig.xml ]; then
127+
fixConfig /solr-conf/conf
128+
else
129+
echo "No config found in '/solr-conf/conf' and was not able to automatically update solr config to newest lagoon compatible version."
130+
echo "Cannot guarantee if this Solr config will work!"
131+
fi
132+
fi
133+

images/solr/Dockerfile

+10-4
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@ ENV TMPDIR=/tmp \
2323
# we need root for the fix-permissions to work
2424
USER root
2525

26-
RUN fix-permissions /opt/solr/server/solr/mycores/ \
27-
&& fix-permissions /opt/solr/server/logs
26+
RUN mkdir -p /var/solr
27+
RUN fix-permissions /var/solr \
28+
&& chown solr:solr /var/solr \
29+
&& fix-permissions /opt/solr/server/logs \
30+
&& fix-permissions /opt/solr/server/solr
31+
2832

2933
# solr really doesn't like to be run as root, so we define the default user agin
3034
USER solr
3135

3236
COPY 10-solr-port.sh /lagoon/entrypoints/
37+
COPY 20-solr-datadir.sh /lagoon/entrypoints/
38+
3339

3440
# Define Volume so locally we get persistent cores
35-
VOLUME /opt/solr/server/solr/mycores/
41+
VOLUME /var/solr
3642

3743
ENTRYPOINT ["/sbin/tini", "--", "/lagoon/entrypoints.sh"]
3844

39-
CMD ["solr-precreate", "mycore"]
45+
CMD ["solr-precreate", "mycore"]

local-dev/api-data/01-populate-api-data.gql

+21
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,27 @@ mutation PopulateApi {
636636
id
637637
}
638638

639+
CiSolr: addProject(
640+
input: {
641+
id: 20
642+
name: "ci-solr"
643+
customer: 3
644+
openshift: 2
645+
gitUrl: "ssh://[email protected]:2222/git/solr.git"
646+
}
647+
) {
648+
id
649+
}
650+
CiSolrRocketChat: addNotificationToProject(
651+
input: {
652+
project: "ci-solr"
653+
notificationType: ROCKETCHAT
654+
notificationName: "amazeeio--lagoon-local-ci"
655+
}
656+
) {
657+
id
658+
}
659+
639660
#### Lagoon Kickstart Objects
640661
# Customer with a private key that has access to the local-git server.
641662
KickstartCustomer: addCustomer(

local-dev/git/Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ RUN mkdir -m 700 /git/.ssh && \
2525
git --bare init /git/nginx.git && \
2626
git --bare init /git/features.git && \
2727
git --bare init /git/features-subfolder.git && \
28-
git --bare init /git/elasticsearch.git
28+
git --bare init /git/elasticsearch.git && \
29+
git --bare init /git/solr.git
2930

3031
USER root
3132

0 commit comments

Comments
 (0)