FROM eclipse-temurin:17-jdk

# Environment variables as per the startup script
ENV SOLR_HOME=/opt/infinitysolr
ENV JAVA_HOME=/opt/java/openjdk
ENV JRE_HOME=/opt/java/openjdk/jre
ENV SOLR_JAVA_HOME=/opt/java/openjdk
ENV SOLR_JAVA_MEM="-Xms1024m -Xmx4096m -Xss1664k"
ENV VERSION="1.0.0"

# Create necessary directory for Solr
RUN mkdir -p /opt/infinitysolr

# Install lsof and procps (which includes ps)
RUN apt-get update && \
    apt-get install -y lsof procps && \
    apt-get clean

# Copy your customized Solr executables and scripts into the container
COPY ./solr/ $SOLR_HOME

# Set executable permissions for the Solr scripts
RUN chmod +x $SOLR_HOME/infinitysolr/infinitysolr.sh
RUN chmod +x $SOLR_HOME/infinitysolr/version.sh
RUN chmod +x $SOLR_HOME/bin/solr

# Set Solr home ownership if needed
RUN chown -R root:root $SOLR_HOME

# Declare the "server" folder as a volume for persistent data storage
VOLUME ["$SOLR_HOME/server"]

# Expose Solr's default port
EXPOSE 8983

# Set the default entrypoint to manage the service
ENTRYPOINT ["/opt/infinitysolr/infinitysolr/infinitysolr.sh"]

# To keep the container running, we can start the Solr service
CMD ["start"]
