Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ web_modules/
.yarn-integrity

# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
*.local

# parcel-bundler cache (https://parceljs.org/)
.cache
Expand Down
1 change: 1 addition & 0 deletions celements-webapp/.env
6 changes: 5 additions & 1 deletion celements-webapp/sample.env → celements-webapp/.env.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# docker
COMPOSE_FILE=compose.local.yml
TOMCAT_PORT=2080
JPDA_PORT=2000
DB_HOST_PORT=2306

# database
DB_DRIVER=com.mysql.jdbc.Driver
Expand All @@ -17,9 +20,10 @@ TZ=Europe/Zurich

# tomcat
CATALINA_XMX=2g
# GC_LOG_VERBOSE=1

# celements
APP_NAME=celements
CLUSTER_NAME=local
NODE_NAME=local1
CELEMENTS_DATA=/usr/local/celements
APP_DATA=/usr/local/celements
8 changes: 8 additions & 0 deletions celements-webapp/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@Library('synventis') _

dockerImagePipeline(
org: 'celements',
image: 'celements-webapp',
appDir: 'celements-webapp',
mode: 'mvn'
)
53 changes: 53 additions & 0 deletions celements-webapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Celements Webapp

`celements-webapp` is the WAR application deployed into Tomcat.

## Local Development

Create the local runtime configuration:

```sh
cp .env.sample .env.local && vim .env.local
```

Build the exploded WAR for the local mounted-webapp setup:

```sh
mvn clean install -P local
```

Start the sqlserver first, then the rest:

```sh
docker compose up -d sqlserver
docker compose up -d
```

Open `http://localhost:2080`.

For remote development, forward the Tomcat port:

```sh
ssh -N -L 2080:localhost:2080 myremotehost
```

## Local Image Builds

Local image builds use `compose.build.yml`. The build requires an untracked `mvn-settings.xml` in
this directory with access to private Maven artifacts.

```sh
docker compose -f compose.build.yml build
```

This builds the same image shape as Jenkins: Maven build stage, Tomcat runtime stage, and
the exploded `target/celements-web/` webapp copied into `webapps/ROOT/`.

## Image builds

The image is published by `Jenkinsfile`.

The pipeline extracts the Maven project version from `pom.xml` and publishes:

- `ghcr.io/celements/celements-webapp:<version>`
- `ghcr.io/celements/celements-webapp:<version>-<git-sha>`
14 changes: 14 additions & 0 deletions celements-webapp/compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
webserver:
image: celements-webapp
build:
context: .
dockerfile: docker/Dockerfile
args:
MVN_CACHE_KEY: "${MVN_CACHE_KEY:-none}"
secrets:
- mvnsettings

secrets:
mvnsettings:
file: ./mvn-settings.xml
18 changes: 9 additions & 9 deletions celements-webapp/compose.local.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
name: celements-web
services:

webserver:
webserver:
container_name: celements-web
image: celements-dev:latest
build:
context: .
dockerfile: docker/Dockerfile-local
dockerfile: docker/Dockerfile.local
ports:
- "2080:8080" # tomcat
- "2000:8000" # remote debugging
env_file: ./.env
- "${TOMCAT_PORT:-2080}:8080" # tomcat
- "${JPDA_PORT:-2000}:8000" # remote debugging
env_file: .env
volumes:
- ./target/celements-web:/usr/local/tomcat/webapps/ROOT:ro
- ./docker/tomcat/log4j2.properties:/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.properties:ro
- ./docker/tomcat/conf/log4j2.local.properties:/usr/local/tomcat/webapps/ROOT/WEB-INF/classes/log4j2.properties:ro
restart: unless-stopped
networks:
- celements
Expand All @@ -26,13 +26,13 @@ services:
container_name: celements-db
image: mariadb:10.1
ports:
- "2306:3306" # for direct client access
env_file: ./.env
- "${DB_HOST_PORT:-2306}:3306" # for direct client access
env_file: .env
environment:
- "MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD:?}"
volumes:
- db-data:/var/lib/mysql
- ./docker/sqlserver/celements.cnf:/etc/mysql/conf.d/celements.cnf:ro
- ./docker/sqlserver/mysql.cnf:/etc/mysql/conf.d/mysql.cnf:ro
- ./docker/sqlserver/init:/docker-entrypoint-initdb.d:ro
restart: unless-stopped
networks:
Expand Down
51 changes: 51 additions & 0 deletions celements-webapp/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# syntax=docker/dockerfile:1

FROM maven:3-eclipse-temurin-21 AS build

WORKDIR /app

ARG MVN_CACHE_KEY=none

COPY . .
RUN --mount=type=secret,id=mvnsettings,required=true,target=/root/.m2/settings.xml \
--mount=type=cache,id=mvnrepo,target=/root/.m2/repository,sharing=locked \
echo "MVN_CACHE_KEY: ${MVN_CACHE_KEY}" && \
mvn -B -U \
-s /root/.m2/settings.xml \
-Dmaven.repo.local=/root/.m2/repository \
clean prepare-package war:exploded

FROM tomcat:10-jdk21-temurin AS execute

ARG VERSION
ARG REVISION

LABEL org.opencontainers.image.source="https://github.com/celements/celements-web" \
org.opencontainers.image.description="Celements web application" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${REVISION}"

ENV APP_DATA=/usr/local/celements \
CONF_DIR=/usr/local/conf

COPY docker/tomcat/entrypoint.sh /usr/local/bin/start
COPY docker/tomcat/conf "${CONF_DIR}"

RUN apt-get update \
&& apt-get --no-install-recommends -y install \
gettext-base \
&& rm -rf /var/lib/apt/lists/* "${CATALINA_HOME}/webapps/"* \
&& mkdir -p \
"${APP_DATA}" \
"${CATALINA_HOME}/temp" \
"${CATALINA_HOME}/conf/Catalina/localhost" \
&& cp "${CONF_DIR}/setenv.sh" "${CATALINA_HOME}/bin/" \
&& cp "${CONF_DIR}/jakarta.converter.xml" "${CATALINA_HOME}/conf/Catalina/localhost/ROOT.xml" \
&& chmod +x /usr/local/bin/start

COPY --from=build /app/target/celements-web/ "${CATALINA_HOME}/webapps/ROOT/"

EXPOSE 8080 9090

ENTRYPOINT ["start"]
CMD ["catalina.sh", "run"]
12 changes: 12 additions & 0 deletions celements-webapp/docker/Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.env
*.local
.git
.gitignore
.settings
.vscode
compose.local.yml
compose.build.yml
docker/sqlserver
docker/Dockerfile.local
node_modules
target
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ FROM tomcat:10-jdk21-temurin

# environment variables, may be overridden from the .env file
# celements
ENV CELEMENTS_DATA=/usr/local/celements
ENV APP_DATA=/usr/local/celements
ENV CONF_DIR=/usr/local/conf
# tomcat
ENV CATALINA_XMX="2g"
# tomcat jpda debugging
ENV JPDA_ADDRESS="8000"
ENV JPDA_TRANSPORT="dt_socket"

# copy configurations / scripts
COPY docker/tomcat ${CONF_DIR}
# copy configurations
COPY docker/tomcat/conf ${CONF_DIR}

# installs and setup
RUN mkdir -p \
${CELEMENTS_DATA} \
${APP_DATA} \
${CATALINA_HOME}/temp \
${CATALINA_HOME}/conf/Catalina/localhost \
&& cp ${CONF_DIR}/setenv.sh ${CATALINA_HOME}/bin/ \
Expand Down
1 change: 1 addition & 0 deletions celements-webapp/docker/Dockerfile.local.dockerignore
55 changes: 55 additions & 0 deletions celements-webapp/docker/tomcat/conf/server.template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<Service name="Catalina">
<Connector port="8080"
protocol="HTTP/1.1"
enableLookups="false"
connectionTimeout="20000"
compression="on"
URIEncoding="UTF-8" />
<Connector port="9090"
protocol="HTTP/1.1"
enableLookups="false"
connectionTimeout="4000"
keepAliveTimeout="1000"
maxThreads="5"
minSpareThreads="1"
maxConnections="10"
acceptCount="5"
compression="off"
URIEncoding="UTF-8" />

<Engine name="Catalina" defaultHost="localhost" jvmRoute="${NODE_NAME}">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>

<Host name="localhost" appBase="webapps"
unpackWARs="false" autoDeploy="true">
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies=".*"/>
<Valve className="org.apache.catalina.valves.HealthCheckValve"/>
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs"
prefix="access_log."
suffix=".txt"
pattern='%v: %h %l %u %t "%r" %s %b "%{Referer}i" "%{User-agent}i"'/>
</Host>
</Engine>
</Service>
</Server>
34 changes: 34 additions & 0 deletions celements-webapp/docker/tomcat/conf/setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# CATALINA_XMX=1200m
## TODO Cgroup-aware memory detection for container environments
Comment thread
msladek marked this conversation as resolved.
if [ -z "$CATALINA_XMX" ]; then
total_memory_kb=$(grep -i 'memtotal' /proc/meminfo | grep -o '[[:digit:]]*')
xmx_kb=$((total_memory_kb * 80 / 100)) # use 80% of memory
xmx_kb_max=$((total_memory_kb - 716800)) # make sure at least 700m left
[ $xmx_kb -gt $xmx_kb_max ] && xmx_kb=$xmx_kb_max
Comment thread
msladek marked this conversation as resolved.
xmx_kb_min=$((1024 * 1024)) # minimum 1GB heap
[ $xmx_kb -lt $xmx_kb_min ] && echo "ERROR: at least 1GB heap required" >&2 && exit 1
CATALINA_XMX="$((xmx_kb / 1024))m"
fi

CATALINA_OPTS="${CATALINA_OPTS}\
-server\
-Xms${CATALINA_XMS:-${CATALINA_XMX}}\
-Xmx${CATALINA_XMX}\
-Xss1m\
-XX:+UseShenandoahGC\
-XX:+UseStringDeduplication\
-Djava.awt.headless=true\
-Dorg.apache.activeio.journal.active.DisableLocking=true\
-Dfile.encoding=UTF-8\
-Djava.net.preferIPv4Stack=true\
"

if [ -n "$GC_LOG_VERBOSE" ]; then
CATALINA_OPTS="${CATALINA_OPTS}\
-Xlog:gc*,safepoint:file=${CATALINA_HOME}/logs/gc.log:time,uptime,level,tags:filecount=5,filesize=10M\
-Xlog:class+unload=trace\
-Xlog:stringdedup*=debug\
"
fi
14 changes: 14 additions & 0 deletions celements-webapp/docker/tomcat/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail

: "${CATALINA_HOME:?CATALINA_HOME not set}"
: "${CONF_DIR:?CONF_DIR not set}"
: "${NODE_NAME:?NODE_NAME not set}"

echo "**entrypoint** applying server.xml"
envsubst \
< "${CONF_DIR}/server.template.xml" \
> "${CATALINA_HOME}/conf/server.xml"

echo "**entrypoint** executing: $*"
exec "$@"
16 changes: 0 additions & 16 deletions celements-webapp/docker/tomcat/setenv.sh

This file was deleted.

Loading