From 221af78afc562075785a35dab639569b3863123a Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 11 Oct 2021 17:33:30 +0200 Subject: [PATCH] improve docker handling --- Dockerfile | 20 -------------------- Dockerfile.jetty | 27 +++++++++++++++++---------- Dockerfile.tomcat | 43 +++++++++++++++---------------------------- README.md | 40 ++++++++++++++++++++-------------------- docker-compose.yml | 8 ++++---- docker-entrypoint.sh | 17 +++++++++++++++++ 6 files changed, 73 insertions(+), 82 deletions(-) delete mode 100644 Dockerfile create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 4043565..0000000 --- a/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -FROM maven:3-jdk-11 - -RUN apt-get update && apt-get install -y --no-install-recommends graphviz fonts-wqy-zenhei && rm -rf /var/lib/apt/lists/* - -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 -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/Dockerfile.jetty b/Dockerfile.jetty index 0f5a822..ef3f0d3 100644 --- a/Dockerfile.jetty +++ b/Dockerfile.jetty @@ -1,26 +1,33 @@ -FROM maven:3-jdk-11 AS builderjetty +FROM maven:3-jdk-11-slim AS builder COPY pom.xml /app/ -COPY src /app/src/ +COPY src/main /app/src/main/ WORKDIR /app RUN mvn --batch-mode --define java.net.useSystemProxies=true package ######################################################################################## -FROM jetty:9.4-jre11 -MAINTAINER D.Ducatel +FROM jetty:9.4-jre11-slim USER root - RUN apt-get update && \ - apt-get install -y --no-install-recommends graphviz fonts-noto-cjk && \ - rm -rf /var/lib/apt/lists/* \ + apt-get install -y --no-install-recommends \ + fonts-noto-cjk \ + graphviz \ + && \ + rm -rf /var/lib/apt/lists/* && \ /generate-jetty-start.sh +COPY docker-entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + USER jetty -ENV GRAPHVIZ_DOT=/usr/bin/dot +ENV BASE_URL=ROOT \ + WEBAPP_PATH=$JETTY_BASE/webapps +RUN rm -rf $WEBAPP_PATH && \ + mkdir -p $WEBAPP_PATH +COPY --from=builder /app/target/plantuml.war $WEBAPP_PATH/ROOT.war -ARG BASE_URL=ROOT -COPY --from=builderjetty /app/target/plantuml.war /var/lib/jetty/webapps/$BASE_URL.war +ENTRYPOINT ["/entrypoint.sh"] diff --git a/Dockerfile.tomcat b/Dockerfile.tomcat index a816a3c..fcfb6cd 100644 --- a/Dockerfile.tomcat +++ b/Dockerfile.tomcat @@ -1,43 +1,30 @@ -FROM maven:3-jdk-11 AS buildertomcat +FROM maven:3-jdk-11-slim AS builder COPY pom.xml /app/ -COPY src /app/src/ +COPY src/main /app/src/main/ WORKDIR /app RUN mvn --batch-mode --define java.net.useSystemProxies=true package ######################################################################################## -FROM tomcat:9.0-jdk11-openjdk-slim as graphviz - -RUN apt-get update && \ - apt-get install -y wget binutils gcc make ghostscript groff g++ fontconfig fontconfig-config fonts-dejavu-core fonts-noto-cjk file libexpat1-dev libcairo2-dev libpango1.0-dev - -RUN mkdir /root/build && \ - cd /root/build && \ - wget -O - https://www2.graphviz.org/Packages/stable/portable_source/graphviz-2.44.1.tar.gz | gzip -d | tar xvf - && \ - cd graphviz-2.44.1 && \ - ./configure --prefix /usr && \ - make -j 4 && \ - make DESTDIR=/root/install/ install-strip - -######################################################################################## - FROM tomcat:9.0-jdk11-openjdk-slim -MAINTAINER D.Ducatel RUN apt-get update && \ - apt-get install -y --no-install-recommends fonts-noto-cjk libexpat1 libcairo2 libpango1.0 libpangoft2-1.0 libpangocairo-1.0 && \ + apt-get install -y --no-install-recommends \ + fonts-noto-cjk \ + graphviz \ + && \ rm -rf /var/lib/apt/lists/* -ENV GRAPHVIZ_DOT=/usr/bin/dot +COPY docker-entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh -ARG BASE_URL=ROOT -RUN rm -rf /usr/local/tomcat/webapps/$BASE_URL -COPY --from=buildertomcat /app/target/plantuml.war /usr/local/tomcat/webapps/$BASE_URL.war - -COPY --from=graphviz /root/install/usr/bin/dot /usr/bin/ -COPY --from=graphviz /root/install/usr/lib/ /usr/lib/ - -RUN dot -c +ENV BASE_URL=ROOT \ + WEBAPP_PATH=$CATALINA_HOME/webapps +RUN rm -rf $WEBAPP_PATH && \ + mkdir -p $WEBAPP_PATH +COPY --from=builder /app/target/plantuml.war $WEBAPP_PATH/ROOT.war +ENTRYPOINT ["/entrypoint.sh"] +CMD ["catalina.sh", "run"] diff --git a/README.md b/README.md index ecec56b..2104673 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,12 @@ This makes the container compatible with more restricted environment such as Ope ## Change base URL To run plantuml using different base url, change the `docker-compose.yml` file: -~~~ -args: - BASE_URL: plantuml -~~~ +```yaml +environment: + - BASE_URL=plantuml +``` -And run `docker-compose up --build`. This will build a modified version of the image using +And run `docker-compose up`. This will start a modified version of the image using the base url `/plantuml`, e.g. http://localhost/plantuml How to set PlantUML options @@ -86,21 +86,21 @@ docker run -d -p 8080:8080 -e THE_ENV_VARIABLE=THE_ENV_VALUE plantuml/plantuml-s You can set all the following variables: -* `PLANTUML_LIMIT_SIZE` - * Limits image width and height - * Default value: `4096` -* `GRAPHVIZ_DOT` - * Link to 'dot' executable - * Default value: `/usr/local/bin/dot` or `/usr/bin/dot` -* `PLANTUML_STATS` - * Set it to `on` to enable [statistics report](http://plantuml.com/statistics-report) - * Default value: `off` -* `HTTP_AUTHORIZATION` - * when calling the `proxy` endpoint, the value of `HTTP_AUTHORIZATION` will be used to set the HTTP Authorization header - * Default value: `null` -* `ALLOW_PLANTUML_INCLUDE` - * Enables `!include` processing which can read files from the server into diagrams. Files are read relative to the current working directory. - * Default value: `false` +- `BASE_URL` + * PlantUML base url + * Default value: `ROOT` +- `PLANTUML_LIMIT_SIZE` + * Limits image width and height + * Default value: `4096` +- `PLANTUML_STATS` + * Set it to `on` to enable [statistics report](http://plantuml.com/statistics-report) + * Default value: `off` +- `HTTP_AUTHORIZATION` + * when calling the `proxy` endpoint, the value of `HTTP_AUTHORIZATION` will be used to set the HTTP Authorization header + * Default value: `null` +- `ALLOW_PLANTUML_INCLUDE` + * Enables `!include` processing which can read files from the server into diagrams. Files are read relative to the current working directory. + * Default value: `false` Alternate: How to build your docker image ====================================================== diff --git a/docker-compose.yml b/docker-compose.yml index 628a638..52ae7fb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,9 @@ services: build: context: . dockerfile: Dockerfile.jetty - args: - BASE_URL: plantuml - image: plantuml/plantuml-server:local + image: plantuml/plantuml-server:jetty-local container_name: plantuml-server ports: - - 8080:8080 \ No newline at end of file + - 8080:8080 + environment: + - BASE_URL=plantuml diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..6a4e5c0 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# cspell:words mkdir +# cspell:enableCompoundWords +########################################################### + +# use environment variables +if [ "$BASE_URL" != "ROOT" ]; then + mkdir -p "$(dirname "$WEBAPP_PATH/$BASE_URL")" + mv "$WEBAPP_PATH/ROOT.war" "$WEBAPP_PATH/$BASE_URL.war" +fi + +# base image entrypoint +if [ -x /docker-entrypoint.sh ]; then + /docker-entrypoint.sh "$@" +else + exec "$@" +fi