Reputation: 5231
we need switch our solr to docker container. In data config of our cores we have configuration like this:
<dataSource type="JdbcDataSource"
driver="org.postgresql.Driver"
url="${dataimporter.request.db_url}"
user="${dataimporter.request.db_user}"
password="${dataimporter.request.db_pass}" />
and in solrconfig.xml
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
<str name="db_url">@db.jdbcurl@</str>
<str name="db_user">@db.username@</str>
<str name="db_pass">@db.pass@</str>
</lst>
</requestHandler>
@...@
variables were set from maven properties. Can you tell me how to pass values of @...@
variables in docker compose file?
Thank you.
Upvotes: 4
Views: 2166
Reputation: 6771
You can access JVM system properties in the dataimport config file and the system properties can be set via the environment variable SOLR_OPTS
as descriped here.
Any JVM System properties, usually specified using the
-D
flag when starting the JVM, can be used as variables in any XML configuration file in Solr.
In general, any Java system property that you want to set can be passed through the bin/solr script using the standard
-Dproperty=value
syntax. Alternatively, you can add common system properties to the SOLR_OPTS environment variable defined in the Solr include file (bin/solr.in.sh
orbin/solr.in.cmd
)
So you actually don't need to write your own Dockerfile but just use the solr image and set the environment variable SOLR_OPTS
like this
SOLR_OPTS="-Ddataimporter.request.db_url=$DB_URL -Ddataimporter.request.db_user=$DB_USER -Ddataimporter.request.db_pass=$DB_PASSWORD"
Upvotes: 2
Reputation: 5076
To solve this, I've prepared my own solr image and I added a special append.solr.sh that gets appended to /opt/solr/bin/solr.in.sh
. The cores use the java properties I've defined in the append.solr.sh in the dataSource portion.
I've prepared an append.solr.sh file:
# Our specific configs.
EXTRA_OPTIONS="-Djava.system.database=$DB_TARGET -Djava.system.dbport=$DB_PORT -Djava.system.dbuser=$DB_USERNAME -Djava.system.dbpass=$DB_PASSWORD"
SOLR_OPTS="$SOLR_OPTS $EXTRA_OPTIONS"
FROM solr
EXPOSE 8983
USER root
COPY append.solr.sh /append.solr.sh
RUN cat /append.solr.sh >> /opt/solr/bin/solr.in.sh \
&& rm /append.solr.sh
COPY --chown=solr:solr cores /opt/solr/server/solr/mycores
USER solr
WORKDIR /opt/solr
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["solr-foreground"]
Modified the dataSource for my cores like this:
<dataSource
type="JdbcDataSource"
driver="com.sap.db.jdbc.Driver"
url="jdbc:sap://${java.system.database}:${java.system.dbport}"
user="${java.system.dbuser}"
password="${java.system.dbpass}" />
And changed my docker-compose.yml to look like this:
version: '3.7'
services:
search:
image: mysolr:latest
container_name: mysolr
build:
context: ./search
dockerfile: Dockerfile
environment:
- DB_TARGET
- DB_PORT
- DB_USERNAME
- DB_PASSWORD
Last, I generate a .env
file containing those variables.
EDIT - alternative solution to match your setup:
docker-compose.yml
version: "3.6"
services:
postgres:
image: postgres:11-alpine
ports:
- "5435:5432"
environment:
- POSTGRES_DB=${ENV_DB}
- POSTGRES_USER=${ENV_PASS}
- POSTGRES_PASSWORD=${ENV_USER}
volumes:
- ./etc/db-init/ddl.sql:/docker-entrypoint-initdb.d/1-ddl.sql
- ./etc/db-init/dml.sql:/docker-entrypoint-initdb.d/2-dml.sql
- pg_data:/var/lib/postgresql/data
solr:
build: ./etc/.
ports:
- "8983:8983"
environment:
- db_url=${ENV_JDBC}
- db_user=${ENV_USER}
- db_password=${ENV_PASS}
volumes:
- solr_data:/var/solr/data
depends_on:
- postgres
volumes:
pg_data:
solr_data:
.env
ENV_USER=os
ENV_PASS=heslo
ENV_DB=os
ENV_JDBC=jdbc:postgresql://localhost:5432/os
Dockerfile
FROM solr:8.2
USER root
COPY pgdriver/postgresql-42.2.8.jar /opt/solr/dist/
COPY solr/ /opt/solr/server/solr/
CMD "/opt/solr/bin/solr start -Ddb_url=$db_url -Ddb_user=$db_user -Ddb_password=$db_password -s /opt/solr/server/solr -f -force"
Upvotes: 5