From 163863ac0b88006639c22790e85fadd047ac55e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=83=C2=83=C3=82=C2=83=C3=83=C2=82=C3=82=C2=A9ment=20M?= =?UTF-8?q?oyroud?= Date: Wed, 8 Mar 2017 19:37:27 -0800 Subject: [PATCH] Allow running on the Openshift platform A few changes are necessary for the best out-of-the-box experience on Docker-based application platforms such as OpenShift: 1. For security purposes, they run the containers as non-root. Before this change, the user was trying to write to the home dir, which is set to /root by default. 2. Deploy time is limited, and the download of dependencies by Jetty at start-up time, while convenient for testing, causes timeouts when deploying. a WAR is now created during Docker image creation, and as a result starting up the container is really fast now. In addition, it is now possible to enable debug logging for Jetty by uncommenting the relevant line in the Dockerfile. --- Dockerfile | 17 +++++++++++++++-- pom.xml | 24 +++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index aa9ffe3..a89fb39 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,20 @@ FROM maven:3-jdk-8 RUN apt-get update && apt-get install -y --no-install-recommends graphviz fonts-wqy-zenhei && rm -rf /var/lib/apt/lists/* -ADD . /app + +COPY pom.xml /app/ +COPY src /app/src/ + +ENV MAVEN_CONFIG=/app/.m2 WORKDIR /app +RUN mvn package + +# chmod required to ensure any user can run the app +RUN mkdir /app/.m2 && chmod -R a+w /app EXPOSE 8080 -CMD ["mvn", "jetty:run"] +ENV HOME /app + +CMD java -Djetty.contextpath=/ -jar target/dependency/jetty-runner.jar target/plantuml.war + +# To run with debugging enabled instead +#CMD java -Dorg.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog -Dorg.eclipse.jetty.LEVEL=DEBUG -Djetty.contextpath=/ -jar target/dependency/jetty-runner.jar target/plantuml.war diff --git a/pom.xml b/pom.xml index 63de1dd..4183d11 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 5 - /plantuml + ${jetty.contextpath} @@ -42,6 +42,27 @@ + + org.apache.maven.plugins + maven-dependency-plugin + 2.3 + + + package + copy + + + + org.mortbay.jetty + jetty-runner + 8.1.9.v20130131 + jetty-runner.jar + + + + + + org.apache.maven.plugins maven-war-plugin @@ -149,6 +170,7 @@ UTF-8 8.0.4.v20111024 8080 + /plantuml yyyyMMdd-HHmm ${maven.build.timestamp}