From 0d4d6246954f954cf4b37d48e7d094185c13ad70 Mon Sep 17 00:00:00 2001 From: Sean Sylver Date: Thu, 3 Oct 2024 18:37:52 -0700 Subject: [PATCH] Update Dockerfile for wfprev-api --- server/wfprev-api/Dockerfile | 65 +++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 24 deletions(-) diff --git a/server/wfprev-api/Dockerfile b/server/wfprev-api/Dockerfile index 29d9b7dd..5da6838c 100644 --- a/server/wfprev-api/Dockerfile +++ b/server/wfprev-api/Dockerfile @@ -1,26 +1,43 @@ -# Use an official Tomcat image as a base image -FROM tomcat:10.1-jdk17-corretto - -# Remove the default webapps to avoid conflicts -RUN rm -rf /usr/local/tomcat/webapps/* - -# Copy the WAR file to the Tomcat webapps directory -COPY target/wfprev-api-1.0.0-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war - -ENV TOMCAT_HOME=/usr/local/tomcat \ - CATALINA_HOME=/usr/local/tomcat \ - CATALINA_OUT=/usr/local/tomcat/logs \ - TOMCAT_MAJOR=10 \ - JAVA_OPTS="$JAVA_OPTS -Xss200k" - -# Set permissions for logs, work, and temp directories -RUN chmod 766 /usr/local/tomcat/logs && chmod 766 /usr/local/tomcat/work && chmod 766 /usr/local/tomcat/temp - -# Define volumes for logs, work, and temp directories +# Use an official Tomcat image with JDK 9 +FROM tomcat:9.0.91-jdk17 +#Install at very top layer to ease caching issues for devs +RUN apt-get -y update &&\ + apt-get install -y unzip +ARG CONTAINER_NAME=wfprev-api +ENV CATALINA_HOME /usr/local/tomcat +# Define build arguments +ARG WAR_FILE=*.war +ARG CONTAINER_NAME +# Add the application's war to the container and rename it to pub#.war +ADD ${WAR_FILE} . +# Copy the context.xml.template template and other configuration files +# COPY docker-files/server.xml $CATALINA_HOME/conf/ +# Create the tomcat user and group, and set permissions +# TEMPNAME step is to remove "-war" from the path +RUN rm -rf /usr/local/tomcat/webapps/ROOT &&\ + for i in $(ls *.war) ; \ + do \ + export TEMPNAME="$(echo $i | sed 's/(.*)((-api)|(-war))-.*/\1\3/' -r)" &&\ + unzip $i -d /usr/local/tomcat/webapps/pub#$TEMPNAME ; \ + done &&\ + addgroup --system tomcat &&\ + adduser --system --ingroup tomcat tomcat &&\ + chown -R tomcat:tomcat `readlink -f ${CATALINA_HOME}` &&\ + chmod -R 770 `readlink -f ${CATALINA_HOME}` &&\ + chown -h tomcat:tomcat ${CATALINA_HOME} &&\ + mkdir -p /usr/local/tomcat/temp &&\ + mkdir -p /usr/local/tomcat/logs/wfhr &&\ + mkdir -p /${CATALINA_HOME}/webapps/pub#${CONTAINER_NAME} &&\ + chown -R tomcat:tomcat /usr/local/tomcat/logs/wfhr &&\ + chmod 766 /usr/local/tomcat/logs &&\ + chmod 766 /usr/local/tomcat/logs/wfhr &&\ + chmod 766 /usr/local/tomcat/work &&\ + chmod 766 /usr/local/tomcat/temp &&\ + chmod 766 /${CATALINA_HOME}/webapps/pub#${CONTAINER_NAME} &&\ + echo org.apache.tomcat.util.digester.PROPERTY_SOURCE=org.apache.tomcat.util.digester.EnvironmentPropertySource >> /usr/local/tomcat/conf/catalina.properties VOLUME /usr/local/tomcat/logs /usr/local/tomcat/work /usr/local/tomcat/temp - -# Expose the Tomcat port (default is 8080) -EXPOSE 8080 - -# Start Tomcat when the container starts +# Expose the ports +EXPOSE 8080 8000 +USER tomcat +# Run the Tomcat server with JPDA settings for remote debugging CMD ["catalina.sh", "run"] \ No newline at end of file