16 Commits

8 changed files with 133 additions and 43 deletions

View File

@@ -1,25 +1,13 @@
FROM ubuntu:${ubuntu.version} FROM docker.inteligr8.com/inteligr8/jdk-hotswap:${jdk-hotswap.version}
# Configure the Apache Tomcat Catalina script # Configure the Apache Tomcat Catalina script
ENV JAVA_MEMORY_INIT=128m ENV JAVA_MEMORY_INIT=128m
ENV JAVA_MEMORY_MAX=512m ENV JAVA_MEMORY_MAX=512m
ENV JAVA_HOME="/usr/local/lib/jvm/java-openjdk-dcevm"
ENV CATALINA_HOME="/usr/local/share/tomcat" ENV CATALINA_HOME="/usr/local/share/tomcat"
ENV CATALINA_BASE="/var/lib/tomcat" ENV CATALINA_BASE="/var/lib/tomcat"
ENV CATALINA_OPTS= ENV CATALINA_OPTS=
# Install curl
RUN apt update && apt -y install curl
# Download & Install DCEVM Java
RUN mkdir -p /usr/local/lib/jvm && \
curl -L https://github.com/TravaOpenJDK/trava-jdk-${dcevm.majorVersion}-dcevm/releases/download/dcevm-${dcevm.version}/java${dcevm.majorVersion}-openjdk-dcevm-linux.tar.gz -o /usr/local/lib/jvm/java-openjdk-dcevm.tar.gz && \
cd /usr/local/lib/jvm && tar xzvf java-openjdk-dcevm.tar.gz && mv dcevm-${dcevm.version} java-openjdk-dcevm && rm java-openjdk-dcevm.tar.gz
# Download Hotswap Agent
RUN curl -L https://github.com/HotswapProjects/HotswapAgent/releases/download/RELEASE-${hotswap.version}/hotswap-agent-${hotswap.version}.jar -o /usr/local/lib/jvm/hotswap-agent.jar
# Download & Install Apache Tomcat # Download & Install Apache Tomcat
RUN mkdir -p /usr/local/share && \ RUN mkdir -p /usr/local/share && \
curl -L ${tomcat.mirror.baseUrl}/tomcat-${tomcat.majorVersion}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz -o /usr/local/share/apache-tomcat.tar.gz && \ curl -L ${tomcat.mirror.baseUrl}/tomcat-${tomcat.majorVersion}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz -o /usr/local/share/apache-tomcat.tar.gz && \
@@ -34,16 +22,20 @@ RUN cd /usr/local/share/tomcat && \
# Add directories for dynamic injection points # Add directories for dynamic injection points
RUN cd /var/lib/tomcat/dev && \ RUN cd /var/lib/tomcat/dev && \
mkdir classes classes-extra1 classes-extra2 classes-extra3 classes-extra4 classes-extra5 classes-extra6 classes-extra7 && \ mkdir classes classes-extra1 classes-extra2 classes-extra3 classes-extra4 classes-extra5 classes-extra6 classes-extra7 && \
mkdir post-rsrc post-rsrc-extra1 post-rsrc-extra2 post-rsrc-extra3 && \
mkdir lib lib-extra1 lib-extra2 lib-extra3 lib-extra4 lib-extra5 lib-extra6 lib-extra7 && \ mkdir lib lib-extra1 lib-extra2 lib-extra3 lib-extra4 lib-extra5 lib-extra6 lib-extra7 && \
mkdir post-lib post-lib-extra1 post-lib-extra2 post-lib-extra3 && \
mkdir web web-extra1 web-extra2 web-extra3 web-extra4 web-extra5 web-extra6 web-extra7 mkdir web web-extra1 web-extra2 web-extra3 web-extra4 web-extra5 web-extra6 web-extra7
# Add our Docker container initialization script # Add our Docker container initialization script
ADD docker-entrypoint.sh /usr/local/bin ADD maven/target/resources/setenv.sh /usr/local/bin/${namespace.prefix}-setenv.sh
COPY maven/target/resources/docker-entrypoint.sh /usr/local/bin
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh
# Add our Apache Tomcat configuration # Add our Apache Tomcat configuration
# This gives us dynamic injection points into the running webapps # This gives us dynamic injection points into the running webapps
COPY tomcat-context.xml /var/lib/tomcat/conf/context.xml COPY maven/target/resources/tomcat-context.xml /var/lib/tomcat/conf/context.xml
ADD hotswap-agent.properties /var/lib/tomcat/lib ADD maven/target/resources/hotswap-agent.properties /var/lib/tomcat/lib
# Listening for HTTP (not HTTPS) traffic # Listening for HTTP (not HTTPS) traffic
EXPOSE 8080 EXPOSE 8080

43
README.md Normal file
View File

@@ -0,0 +1,43 @@
# Apache Tomcat Application Container Image with Hot-Reloading
This project creates a Docker image that has uses the [Java Hotswap Docker Image](/inteligr8/jdk-hotswap-docker) to support hot-reloading for the enablement of rapid application development. As a Docker image, containers can be started to facilitate development without requiring complicated installations on developer workstations.
It is expected that containers are configured in Maven using the Fabric8 or Spotify Docker plugins. These configurations should expose the 8080 (HTTP) and 8000 (debugger) ports and any other port that the application may open. Most importantly, it should mount/bind the source code to the following possible paths.
| Directory | Type | Hot-Reloaded | When |
| -------------------------------------- |:---------:|:------------:|:----:|
| `/var/lib/tomcat/dev/classes` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra1` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra2` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra3` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra4` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra5` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra6` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/classes-extra7` | Classpath | Yes | Before WAR |
| `/var/lib/tomcat/dev/post-rsrc` | Classpath | Yes | After WAR |
| `/var/lib/tomcat/dev/post-rsrc-extra1` | Classpath | Yes | After WAR |
| `/var/lib/tomcat/dev/post-rsrc-extra2` | Classpath | Yes | After WAR |
| `/var/lib/tomcat/dev/post-rsrc-extra3` | Classpath | Yes | After WAR |
| `/var/lib/tomcat/dev/lib` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra1` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra2` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra3` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra4` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra5` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra6` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/lib-extra7` | JARs | No | Before WAR |
| `/var/lib/tomcat/dev/post-lib` | JARs | No | After WAR |
| `/var/lib/tomcat/dev/post-lib-extra1` | JARs | No | After WAR |
| `/var/lib/tomcat/dev/post-lib-extra2` | JARs | No | After WAR |
| `/var/lib/tomcat/dev/post-lib-extra3` | JARs | No | After WAR |
| `/var/lib/tomcat/dev/web` | Web | Yes | Before WAR |
| `/var/lib/tomcat/dev/web-extra1` | Web | No | Before WAR |
| `/var/lib/tomcat/dev/web-extra2` | Web | NO | Before WAR |
| `/var/lib/tomcat/dev/web-extra3` | Web | NO | Before WAR |
| `/var/lib/tomcat/dev/web-extra4` | Web | No | Before WAR |
| `/var/lib/tomcat/dev/web-extra5` | Web | No | Before WAR |
| `/var/lib/tomcat/dev/web-extra6` | Web | No | Before WAR |
| `/var/lib/tomcat/dev/web-extra7` | Web | No | Before WAR |
You may include your own `hotswap-agent.properties` in any of the `classes` folders. The one loaded by default is usually sufficient. It most notably disables the Hotswap Agent Hibernate plugin.

View File

@@ -1,4 +0,0 @@
#!/bin/bash
CATALINA_OPTS="-Xms${JAVA_MEMORY_INIT} -Xmx${JAVA_MEMORY_MAX} -XX:HotswapAgent=external -javaagent:/usr/local/lib/jvm/hotswap-agent.jar -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n $CATALINA_OPTS"
exec "$@"

54
pom.xml
View File

@@ -3,30 +3,22 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.inteligr8</groupId> <groupId>com.inteligr8</groupId>
<artifactId>tomcat-rad</artifactId> <artifactId>tomcat-rad</artifactId>
<version>9-1.2</version> <version>9-2.2</version>
<name>Apache Tomcat for Rapid Application Development</name> <name>Apache Tomcat for Rapid Application Development</name>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<!-- The release version of Ubuntu to use as the base --> <!-- The release version of the Java Hotswap Docker image -->
<!-- See: https://hub.docker.com/_/ubuntu --> <!-- See: https://bitbucket.org/inteligr8/jdk-hotswap-docker -->
<!-- This has very little impact and may be replaced --> <jdk-hotswap.version>2.0.1-jbr-17.0.12</jdk-hotswap.version>
<ubuntu.version>20.04</ubuntu.version>
<!-- The version of Java DCEVM to use for executing Apache Tomcat --> <namespace.prefix>tomcat-rad</namespace.prefix>
<!-- See: https://github.com/TravaOpenJDK/trava-jdk-11-dcevm/releases -->
<dcevm.version>11.0.10+4</dcevm.version>
<dcevm.majorVersion>11</dcevm.majorVersion>
<!-- The version of Apache Tomcat to serve as the basis of this Docker image --> <!-- The version of Apache Tomcat to serve as the basis of this Docker image -->
<!-- See: https://tomcat.apache.org/download-90.cgi --> <!-- See: https://tomcat.apache.org/download-90.cgi -->
<tomcat.version>9.0.44</tomcat.version> <tomcat.version>9.0.98</tomcat.version>
<tomcat.majorVersion>9</tomcat.majorVersion> <tomcat.majorVersion>9</tomcat.majorVersion>
<tomcat.mirror.baseUrl>https://apache.osuosl.org/tomcat</tomcat.mirror.baseUrl> <tomcat.mirror.baseUrl>https://archive.apache.org/dist/tomcat</tomcat.mirror.baseUrl>
<!-- The version of the Hotswap Agent to use -->
<!-- See: https://github.com/HotswapProjects/HotswapAgent/releases -->
<hotswap.version>1.4.1</hotswap.version>
<!-- The Docker image meta-data for pushing the build --> <!-- The Docker image meta-data for pushing the build -->
<image.name>inteligr8/${project.artifactId}</image.name> <image.name>inteligr8/${project.artifactId}</image.name>
@@ -35,12 +27,34 @@
</properties> </properties>
<build> <build>
<resources>
<resource>
<directory>src/main/docker</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/resources</targetPath>
</resource>
</resources>
<plugins> <plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-resources</phase>
<goals><goal>resources</goal></goals>
<configuration>
<encoding>utf-8</encoding>
<propertiesEncoding>utf-8</propertiesEncoding>
</configuration>
</execution>
</executions>
</plugin>
<!-- This plugin build and pushes the Docker image --> <!-- This plugin build and pushes the Docker image -->
<plugin> <plugin>
<groupId>io.fabric8</groupId> <groupId>org.eclipse.jkube</groupId>
<artifactId>fabric8-maven-plugin</artifactId> <artifactId>kubernetes-maven-plugin</artifactId>
<version>4.4.0</version> <version>1.16.2</version>
<configuration> <configuration>
<images> <images>
<image> <image>
@@ -48,7 +62,7 @@
<registry>${image.registry}</registry> <registry>${image.registry}</registry>
</image> </image>
</images> </images>
<contextDir>${basedir}</contextDir> <contextDir>${project.build.directory}/resources</contextDir>
<buildStrategy>docker</buildStrategy> <buildStrategy>docker</buildStrategy>
<verbose>true</verbose> <verbose>true</verbose>
</configuration> </configuration>
@@ -70,7 +84,7 @@
<!-- This plugin prevents the project from deploying to the Maven Repository, as it is pointless --> <!-- This plugin prevents the project from deploying to the Maven Repository, as it is pointless -->
<plugin> <plugin>
<artifactId>maven-deploy-plugin</artifactId> <artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version> <version>3.1.3</version>
<configuration> <configuration>
<skip>true</skip> <skip>true</skip>
</configuration> </configuration>

View File

@@ -0,0 +1,5 @@
#!/bin/sh
. /usr/local/bin/jdk-hotswap-setenv.sh
. /usr/local/bin/${namespace.prefix}-setenv.sh
exec "$@"

View File

@@ -7,7 +7,18 @@
# This may be useful for example in multi module maven project to load class changes from upstream project # This may be useful for example in multi module maven project to load class changes from upstream project
# classes. Set extraClasspath to upstream project compiler output and .class file will have precedence to # classes. Set extraClasspath to upstream project compiler output and .class file will have precedence to
# classes from built JAR file. # classes from built JAR file.
extraClasspath=/var/lib/tomcat/dev/classes extraClasspath=/var/lib/tomcat/dev/classes; \
/var/lib/tomcat/dev/classes-extra1; \
/var/lib/tomcat/dev/classes-extra2; \
/var/lib/tomcat/dev/classes-extra3; \
/var/lib/tomcat/dev/classes-extra4; \
/var/lib/tomcat/dev/classes-extra5; \
/var/lib/tomcat/dev/classes-extra6; \
/var/lib/tomcat/dev/classes-extra7; \
/var/lib/tomcat/dev/post-rsrc; \
/var/lib/tomcat/dev/post-rsrc-extra1; \
/var/lib/tomcat/dev/post-rsrc-extra2; \
/var/lib/tomcat/dev/post-rsrc-extra3
# Watch for changes in a directory (resources only). If not set, changes of resources won't be observed. # Watch for changes in a directory (resources only). If not set, changes of resources won't be observed.
# #
@@ -19,7 +30,18 @@ extraClasspath=/var/lib/tomcat/dev/classes
# replacements of resources in a building step (maven filtering resource option). # replacements of resources in a building step (maven filtering resource option).
# This setting will leave i.e. src/target/classes as default source for resources, but after the resource is modified # This setting will leave i.e. src/target/classes as default source for resources, but after the resource is modified
# in src/main/resources, the new changed resource is served instead. # in src/main/resources, the new changed resource is served instead.
watchResources=/var/lib/tomcat/dev/classes watchResources=/var/lib/tomcat/dev/classes; \
/var/lib/tomcat/dev/classes-extra1; \
/var/lib/tomcat/dev/classes-extra2; \
/var/lib/tomcat/dev/classes-extra3; \
/var/lib/tomcat/dev/classes-extra4; \
/var/lib/tomcat/dev/classes-extra5; \
/var/lib/tomcat/dev/classes-extra6; \
/var/lib/tomcat/dev/classes-extra7; \
/var/lib/tomcat/dev/post-rsrc; \
/var/lib/tomcat/dev/post-rsrc-extra1; \
/var/lib/tomcat/dev/post-rsrc-extra2; \
/var/lib/tomcat/dev/post-rsrc-extra3
# Load static web resources from different directory. # Load static web resources from different directory.
# #
@@ -27,11 +49,18 @@ watchResources=/var/lib/tomcat/dev/classes
# Jboss and Glassfish are not yet supported. # Jboss and Glassfish are not yet supported.
# Use this setting to set to serve resources from source directory directly (e.g. src/main/webapp). # Use this setting to set to serve resources from source directory directly (e.g. src/main/webapp).
webappDir=/var/lib/tomcat/dev/web webappDir=/var/lib/tomcat/dev/web
#/var/lib/tomcat/dev/web-extra1; \
#/var/lib/tomcat/dev/web-extra2; \
#/var/lib/tomcat/dev/web-extra3; \
#/var/lib/tomcat/dev/web-extra4; \
#/var/lib/tomcat/dev/web-extra5; \
#/var/lib/tomcat/dev/web-extra6; \
#/var/lib/tomcat/dev/web-extra7
# Comma separated list of disabled plugins # Comma separated list of disabled plugins
# Use plugin name - e.g. Hibernate, Spring, ZK, Hotswapper, AnonymousClassPatch, Tomcat, Logback .... # Use plugin name - e.g. Hibernate, Spring, ZK, Hotswapper, AnonymousClassPatch, Tomcat, Logback ....
disabledPlugins=Hibernate disabledPlugins=${hotswap.disablePlugins}
# Watch for changed class files on watchResources path and reload class definition in the running application. # Watch for changed class files on watchResources path and reload class definition in the running application.
# #

View File

@@ -0,0 +1,3 @@
#!/bin/sh
CATALINA_OPTS="${JAVA_OPTS} ${CATALINA_OPTS}"
JAVA_OPTS=""

View File

@@ -40,6 +40,10 @@
<PreResources base="/var/lib/tomcat/dev/classes-extra5" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" /> <PreResources base="/var/lib/tomcat/dev/classes-extra5" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<PreResources base="/var/lib/tomcat/dev/classes-extra6" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" /> <PreResources base="/var/lib/tomcat/dev/classes-extra6" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<PreResources base="/var/lib/tomcat/dev/classes-extra7" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" /> <PreResources base="/var/lib/tomcat/dev/classes-extra7" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<PostResources base="/var/lib/tomcat/dev/post-rsrc" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<PostResources base="/var/lib/tomcat/dev/post-rsrc-extra1" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<PostResources base="/var/lib/tomcat/dev/post-rsrc-extra2" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<PostResources base="/var/lib/tomcat/dev/post-rsrc-extra3" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/classes" />
<!-- Injection point for JARs --> <!-- Injection point for JARs -->
<PreResources base="/var/lib/tomcat/dev/lib" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" /> <PreResources base="/var/lib/tomcat/dev/lib" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PreResources base="/var/lib/tomcat/dev/lib-extra1" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" /> <PreResources base="/var/lib/tomcat/dev/lib-extra1" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
@@ -49,6 +53,10 @@
<PreResources base="/var/lib/tomcat/dev/lib-extra5" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" /> <PreResources base="/var/lib/tomcat/dev/lib-extra5" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PreResources base="/var/lib/tomcat/dev/lib-extra6" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" /> <PreResources base="/var/lib/tomcat/dev/lib-extra6" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PreResources base="/var/lib/tomcat/dev/lib-extra7" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" /> <PreResources base="/var/lib/tomcat/dev/lib-extra7" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PostResources base="/var/lib/tomcat/dev/post-lib" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PostResources base="/var/lib/tomcat/dev/post-lib-extra1" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PostResources base="/var/lib/tomcat/dev/post-lib-extra2" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<PostResources base="/var/lib/tomcat/dev/post-lib-extra3" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/WEB-INF/lib" />
<!-- Injection points for web --> <!-- Injection points for web -->
<PreResources base="/var/lib/tomcat/dev/web" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/" /> <PreResources base="/var/lib/tomcat/dev/web" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/" />
<PreResources base="/var/lib/tomcat/dev/web-extra1" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/" /> <PreResources base="/var/lib/tomcat/dev/web-extra1" className="org.apache.catalina.webresources.DirResourceSet" webAppMount="/" />