FROM solr:9
ENV SOLR_PORT=8983
EXPOSE ${SOLR_PORT}
ARG CKAN_BRANCH="dev-v2.10"
ENV SOLR_INSTALL="/opt/solr"
ENV SOLR_CONFIG_DIR="$SOLR_INSTALL/server/solr/configsets"
ENV SOLR_SCHEMA_FILE="$SOLR_CONFIG_DIR/ckan/conf/managed-schema"
ARG JTS_VERSION="1.19.0"
ARG JTS_JAR_FILE="$SOLR_INSTALL/server/solr-webapp/webapp/WEB-INF/lib/jts-core-$JTS_VERSION.jar"
USER root
# Create a CKAN configset by copying the default one
RUN cp -R $SOLR_CONFIG_DIR/_default $SOLR_CONFIG_DIR/ckan
# Update the schema
ADD https://raw.githubusercontent.com/ckan/ckan/$CKAN_BRANCH/ckan/config/solr/schema.xml $SOLR_SCHEMA_FILE
# Install JTS JAR file
ADD https://repo1.maven.org/maven2/org/locationtech/jts/jts-core/$JTS_VERSION/jts-core-$JTS_VERSION.jar \
$JTS_JAR_FILE
RUN chmod 644 $JTS_JAR_FILE
# Add the spatial field type definitions and fields
## RPT
ENV SOLR_RPT_FIELD_DEFINITION ''
ENV SOLR_RPT_FIELD ''
RUN sed -i "//a $SOLR_RPT_FIELD_DEFINITION" $SOLR_SCHEMA_FILE
RUN sed -i "//a $SOLR_RPT_FIELD" $SOLR_SCHEMA_FILE
## BBox
ENV SOLR_BBOX_FIELDS ' \
\
\
\
\
\
\
\
\
\
\
\
\
\
'
RUN sed -i "//a $SOLR_BBOX_FIELDS" $SOLR_SCHEMA_FILE
RUN chmod 644 $SOLR_SCHEMA_FILE
USER solr
CMD ["sh", "-c", "solr-precreate ckan $SOLR_CONFIG_DIR/ckan"]