Skip to content

Commit

Permalink
Merge pull request DSpace#9505 from tdonohue/fixes_for_runnable_jar
Browse files Browse the repository at this point in the history
Fix Runnable JAR issues & use it in all Docker images
  • Loading branch information
tdonohue authored May 2, 2024
2 parents 4aefd53 + 58d5005 commit a0b59b7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 52 deletions.
23 changes: 9 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ENV MAVEN_FLAGS="-P-test-environment -Denforcer.skip=true -Dcheckstyle.skip=true
RUN mvn --no-transfer-progress package ${MAVEN_FLAGS} && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Remove the server webapp to keep image small.
RUN rm -rf /install/webapps/server/

# Step 2 - Run Ant Deploy
FROM eclipse-temurin:${JDK_VERSION} as ant_build
Expand All @@ -49,23 +51,16 @@ RUN mkdir $ANT_HOME && \
# Run necessary 'ant' deploy scripts
RUN ant init_installation update_configs update_code update_webapps

# Step 3 - Run tomcat
# Create a new tomcat image that does not retain the the build directory contents
FROM tomcat:10-jdk${JDK_VERSION}
# Step 3 - Start up DSpace via Runnable JAR
FROM eclipse-temurin:${JDK_VERSION}
# NOTE: DSPACE_INSTALL must align with the "dspace.dir" default configuration.
ENV DSPACE_INSTALL=/dspace
# Copy the /dspace directory from 'ant_build' container to /dspace in this container
COPY --from=ant_build /dspace $DSPACE_INSTALL
# Expose Tomcat port and AJP port
EXPOSE 8080 8009
WORKDIR $DSPACE_INSTALL
# Expose Tomcat port
EXPOSE 8080
# Give java extra memory (2GB)
ENV JAVA_OPTS=-Xmx2000m

# Link the DSpace 'server' webapp into Tomcat's webapps directory.
# This ensures that when we start Tomcat, it runs from /server path (e.g. http://localhost:8080/server/)
RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server
# If you wish to run "server" webapp off the ROOT path, then comment out the above RUN, and uncomment the below RUN.
# You also MUST update the 'dspace.server.url' configuration to match.
# Please note that server webapp should only run on one path at a time.
#RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
# ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT
# On startup, run DSpace Runnable JAR
ENTRYPOINT ["java", "-jar", "webapps/server-boot.jar", "--dspace.dir=$DSPACE_INSTALL"]
31 changes: 11 additions & 20 deletions Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ ADD --chown=dspace . /app/
RUN mvn --no-transfer-progress package && \
mv /app/dspace/target/${TARGET_DIR}/* /install && \
mvn clean
# Remove the server webapp to keep image small. Rename runnable JAR to server-boot.jar.
RUN rm -rf /install/webapps/server/

# Step 2 - Run Ant Deploy
FROM eclipse-temurin:${JDK_VERSION} as ant_build
Expand All @@ -48,29 +50,18 @@ RUN mkdir $ANT_HOME && \
# Run necessary 'ant' deploy scripts
RUN ant init_installation update_configs update_code update_webapps

# Step 3 - Run tomcat
# Create a new tomcat image that does not retain the the build directory contents
FROM tomcat:10-jdk${JDK_VERSION}
# Step 3 - Start up DSpace via Runnable JAR
FROM eclipse-temurin:${JDK_VERSION}
# NOTE: DSPACE_INSTALL must align with the "dspace.dir" default configuration.
ENV DSPACE_INSTALL=/dspace
ENV TOMCAT_INSTALL=/usr/local/tomcat
# Copy the /dspace directory from 'ant_build' containger to /dspace in this container
# Copy the /dspace directory from 'ant_build' container to /dspace in this container
COPY --from=ant_build /dspace $DSPACE_INSTALL
# Enable the AJP connector in Tomcat's server.xml
# NOTE: secretRequired="false" should only be used when AJP is NOT accessible from an external network. But, secretRequired="true" isn't supported by mod_proxy_ajp until Apache 2.5
RUN sed -i '/Service name="Catalina".*/a \\n <Connector protocol="AJP/1.3" port="8009" address="0.0.0.0" redirectPort="8443" URIEncoding="UTF-8" secretRequired="false" />' $TOMCAT_INSTALL/conf/server.xml
# Expose Tomcat port and AJP port
EXPOSE 8080 8009 8000
WORKDIR $DSPACE_INSTALL
# Expose Tomcat port and debugging port
EXPOSE 8080 8000
# Give java extra memory (2GB)
ENV JAVA_OPTS=-Xmx2000m
# Set up debugging
ENV CATALINA_OPTS=-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:8000

# Link the DSpace 'server' webapp into Tomcat's webapps directory.
# This ensures that when we start Tomcat, it runs from /server path (e.g. http://localhost:8080/server/)
RUN ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/server
# If you wish to run "server" webapp off the ROOT path, then comment out the above RUN, and uncomment the below RUN.
# You also MUST update the 'dspace.server.url' configuration to match.
# Please note that server webapp should only run on one path at a time.
#RUN mv /usr/local/tomcat/webapps/ROOT /usr/local/tomcat/webapps/ROOT.bk && \
# ln -s $DSPACE_INSTALL/webapps/server /usr/local/tomcat/webapps/ROOT

# On startup, run DSpace Runnable JAR
ENTRYPOINT ["java", "-jar", "webapps/server-boot.jar", "--dspace.dir=$DSPACE_INSTALL"]
6 changes: 2 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ services:
ports:
- published: 8080
target: 8080
- published: 8009
target: 8009
- published: 8000
target: 8000
stdin_open: true
Expand All @@ -54,14 +52,14 @@ services:
# Ensure that the database is ready BEFORE starting tomcat
# 1. While a TCP connection to dspacedb port 5432 is not available, continue to sleep
# 2. Then, run database migration to init database tables
# 3. Finally, start Tomcat
# 3. Finally, start DSpace
entrypoint:
- /bin/bash
- '-c'
- |
while (!</dev/tcp/dspacedb/5432) > /dev/null 2>&1; do sleep 1; done;
/dspace/bin/dspace database migrate
catalina.sh run
java -jar /dspace/webapps/server-boot.jar --dspace.dir=/dspace
# DSpace PostgreSQL database container
dspacedb:
container_name: dspacedb
Expand Down
21 changes: 16 additions & 5 deletions dspace/src/main/assembly/assembly.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@
<directory>bin</directory>
<outputDirectory>bin</outputDirectory>
</fileSet>
<fileSet>
<directory>etc</directory>
<outputDirectory>etc</outputDirectory>
</fileSet>
<fileSet>
<directory>solr</directory>
<outputDirectory>solr</outputDirectory>
Expand Down Expand Up @@ -95,7 +91,7 @@
<includes>
<include>org.dspace.modules:*:jar:*</include>
</includes>
<binaries>
<binaries>
<includeDependencies>true</includeDependencies>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
Expand All @@ -110,6 +106,21 @@
</binaries>
</moduleSet>

<!--
Add server-boot.jar to the 'webapps' directory
-->
<moduleSet>
<includes>
<include>org.dspace:server-boot</include>
</includes>
<binaries>
<includeDependencies>false</includeDependencies>
<outputDirectory>webapps</outputDirectory>
<unpack>false</unpack>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</binaries>
</moduleSet>

<!--
Take all WAR modules (in [src]/dspace/modules/) and unpack them into
'webapps' directory
Expand Down
4 changes: 2 additions & 2 deletions dspace/src/main/docker-compose/db.entities.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ services:
# Ensure that the database is ready BEFORE starting tomcat
# 1. While a TCP connection to dspacedb port 5432 is not available, continue to sleep
# 2. Then, run migration latest version of database tables (run with "ignored" in case this SQL data is outdated)
# 3. Finally, start Tomcat
# 3. Finally, start DSpace
entrypoint:
- /bin/bash
- '-c'
- |
while (!</dev/tcp/dspacedb/5432) > /dev/null 2>&1; do sleep 1; done;
/dspace/bin/dspace database migrate ignored
catalina.sh run
java -jar /dspace/webapps/server-boot.jar --dspace.dir=/dspace
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1091,13 +1091,6 @@
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate.version}</version>
<exclusions>
<!-- Later version provided by Hibernate Core -->
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -1126,6 +1119,13 @@
<version>3.4.3.Final</version>
</dependency>

<!-- Hibernate & Solr disagree on the version of antlr. So, specify the latest version -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.13.1</version>
</dependency>

<!-- Rome is used for RSS / ATOM syndication feeds -->
<dependency>
<groupId>com.rometools</groupId>
Expand Down

0 comments on commit a0b59b7

Please sign in to comment.