Skip to content

Commit 5ba73ef

Browse files
authored
GH-5064: added docker makefile for Jetty 9 (#5078)
2 parents f7d69a1 + f7566d0 commit 5ba73ef

12 files changed

Lines changed: 130 additions & 59 deletions

File tree

docker/Dockerfile-jetty

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Temp to reduce image size
2+
FROM ubuntu:jammy AS temp
3+
4+
RUN apt-get clean && apt-get update && apt-get install -y unzip
5+
6+
7+
COPY ignore/rdf4j.zip /tmp/rdf4j.zip
8+
9+
WORKDIR /tmp
10+
11+
RUN unzip -q /tmp/rdf4j.zip
12+
13+
# Final workbench
14+
FROM jetty:9-jre17-eclipse-temurin
15+
LABEL org.opencontainers.image.authors="Bart Hanssens (bart.hanssens@bosa.fgov.be)"
16+
17+
USER root
18+
19+
ENV JAVA_OPTIONS="-Dorg.eclipse.rdf4j.appdata.basedir=/var/rdf4j -Dorg.eclipse.rdf4j.rio.jsonld_secure_mode=false"
20+
ENV JETTY_MODULES="server,bytebufferpool,threadpool,security,servlet,webapp,ext,plus,deploy,annotations,http,jsp,jstl"
21+
22+
COPY --from=temp /tmp/eclipse-rdf4j*/war/*.war /var/lib/jetty/webapps/
23+
24+
# mimic Tomcat directories for data and logs
25+
26+
RUN ln -s /usr/local/jetty/logs /var/lib/jetty/logs && \
27+
mkdir -p /usr/local/jetty/logs /var/rdf4j && \
28+
chown -R jetty:jetty /usr/local/jetty/logs && \
29+
chown -R jetty:jetty /var/rdf4j && \
30+
chown -R jetty:jetty /var/lib/jetty/webapps && \
31+
java -jar $JETTY_HOME/start.jar --add-to-start=$JETTY_MODULES --approve-all-licenses
32+
33+
USER jetty
34+
35+
EXPOSE 8080
36+
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ WORKDIR /tmp
1111
RUN unzip -q /tmp/rdf4j.zip
1212

1313
# Final workbench
14-
FROM tomcat:8.5-jre11-temurin
14+
FROM tomcat:9-jre17-temurin-jammy
1515
MAINTAINER Bart Hanssens (bart.hanssens@bosa.fgov.be)
1616

1717
RUN apt-get clean && apt-get update && apt-get upgrade -y && apt-get clean
@@ -28,7 +28,7 @@ RUN rm -rf /usr/local/tomcat/webapps/* && \
2828

2929
COPY --from=temp /tmp/eclipse-rdf4j*/war/*.war /usr/local/tomcat/webapps/
3030

31-
COPY web.xml /usr/local/tomcat/conf/web.xml
31+
COPY tomcat/web.xml /usr/local/tomcat/conf/web.xml
3232

3333
USER tomcat
3434

docker/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Eclipse RDF4J server and workbench
22

3-
Docker image for RDF4J server and workbench, based on the Tomcat 8.5 (JRE 11) image.
3+
Docker image for RDF4J server and workbench, based on a Tomcat 9.0 or Jetty 9.4 (JRE 17) image.
44

5-
A slightly modified web.mxl is used to fix a known UTF-8 issue
5+
A slightly modified web.mxl is used for Tomcat to fix a known UTF-8 issue
66
(see also http://docs.rdf4j.org/server-workbench-console)
77

88
## Port
@@ -12,29 +12,31 @@ By default port 8080 is exposed.
1212
## Volumes
1313

1414
* RDF4J data will be stored in `/var/rdf4j`
15-
* Tomcat server logs in `/usr/local/tomcat/logs`
15+
* Server logs go to `/usr/local/tomcat/logs` or `/usr/local/jetty/logs`
1616

1717
## Running the docker container
1818

1919
The default java runtime options (-Xmx2g) can be changed by setting the
2020
`JAVA_OPTS` environment variable.
2121

2222
To avoid data loss between restarts of the docker container,
23-
the exposed volumes can be mapped to existing directories on the host.
23+
the exposed volumes can be mapped to existing (and writable) directories on the host.
2424

2525
Example:
2626
```
2727
docker run -d -p 127.0.0.1:8080:8080 -e JAVA_OPTS="-Xms1g -Xmx4g" \
28-
-v data:/var/rdf4j -v logs:/usr/local/tomcat/logs eclipse/rdf4j
28+
-v /home/rdf4j/data:/var/rdf4j -v /home/rdf4j/logs:/usr/local/tomcat/logs \
29+
eclipse/rdf4j-workbench
2930
```
3031

31-
To access your server from another machine you will need to bind to `0.0.0.0`
32-
instead of `127.0.0.1`.
33-
3432
The workbench will be accessible via http://localhost:8080/rdf4j-workbench
3533

3634
The server will be accessible via http://localhost:8080/rdf4j-server
3735

36+
37+
In order to access the workbench and server from another machine,
38+
you will need to bind the docker container to `0.0.0.0` instead of `127.0.0.1`.
39+
3840
## Security
3941

4042
Please note that the RDF4J server in the docker container is not

docker/build.sh

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,48 @@ set -e
55
CURRENT=$(pwd)
66
cd ..
77
PROJECT_ROOT=$(pwd)
8+
MVN_VERSION=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" pom.xml)
9+
810
cd "$CURRENT"
911

10-
# clean "ignore" directory
11-
cd ignore
12-
rm -f *.zip
12+
if [ -z ${SKIP_BUILD+x} ]; then
13+
# clean "ignore" directory
14+
cd ignore
15+
rm -f *.zip
1316

14-
cd "$PROJECT_ROOT"
17+
cd "$PROJECT_ROOT"
1518

16-
# remove assembly/target since this is not removed by mvn clean
17-
rm -rf assembly/target/
19+
# remove assembly/target since this is not removed by mvn clean
20+
rm -rf assembly/target/
1821

19-
MVN_VERSION=$(xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" pom.xml)
22+
#Clean, format and package
23+
echo "Building with Maven"
24+
mvn clean
25+
mvn -T 2C formatter:format impsort:sort && mvn xml-format:xml-format
26+
mvn install -DskipTests
27+
mvn -Passembly package -DskipTests -Dmaven.javadoc.skip=true -Dformatter.skip=true -Dimpsort.skip=true -Dxml-format.skip=true -Djapicmp.skip -Denforcer.skip=true -Dbuildnumber.plugin.phase=none -Danimal.sniffer.skip=true
2028

21-
#Clean, format and package
22-
echo "Building with Maven"
23-
mvn clean
24-
mvn -T 2C formatter:format impsort:sort && mvn xml-format:xml-format
25-
mvn install -DskipTests
26-
mvn -Passembly package -DskipTests -Dmaven.javadoc.skip=true -Dformatter.skip=true -Dimpsort.skip=true -Dxml-format.skip=true -Djapicmp.skip -Denforcer.skip=true -Dbuildnumber.plugin.phase=none -Danimal.sniffer.skip=true
29+
# find .zip file
30+
ZIP=$(find assembly/target/*.zip)
31+
echo "$ZIP"
2732

28-
# find .zip file
29-
ZIP=$(find assembly/target/*.zip)
30-
echo "$ZIP"
33+
# copy zip file into rdf4j.zip
34+
cp "$ZIP" "${CURRENT}/ignore/rdf4j.zip"
3135

32-
# copy zip file into rdf4j.zip
33-
cp "$ZIP" "${CURRENT}/ignore/rdf4j.zip"
34-
35-
cd "$CURRENT"
36+
cd "$CURRENT"
37+
fi
3638

3739
# build
38-
echo "Building docker image"
39-
docker compose build --pull --no-cache
40+
APP_SERVER=${APP_SERVER:-tomcat}
41+
echo "Building docker image for ${APP_SERVER}"
4042

41-
docker tag docker-rdf4j:latest eclipse/rdf4j-workbench:${MVN_VERSION}
43+
docker compose build --pull --no-cache
44+
docker tag docker-rdf4j:latest eclipse/rdf4j-workbench-${APP_SERVER}:${MVN_VERSION}
4245

4346
echo "
4447
Docker image tagged as:
45-
docker-rdf4j:latest
46-
eclipse/rdf4j-workbench:${MVN_VERSION}
48+
docker-rdf4j:latest
49+
eclipse/rdf4j-workbench-${APP_SERVER}:${MVN_VERSION}
4750
4851
To start the workbench and server:
4952
docker compose up -d

docker/docker-compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ services:
33
rdf4j:
44
environment:
55
- APP_LOGGING_LEVEL=${APP_LOGGING_LEVEL}
6+
- APP_SERVER=${APP_SERVER:-tomcat}
67
ports:
78
- 127.0.0.1:8080:8080
8-
build: .
9+
build:
10+
context: .
11+
dockerfile: Dockerfile-${APP_SERVER:-tomcat}
912
restart: always
1013
volumes:
1114
- rdf4j_data:/var/rdf4j
12-
- rdf4j_logs:/usr/local/tomcat/logs
15+
- rdf4j_logs:/usr/local/${APP_SERVER:-tomcat}/logs
1316

1417
volumes:
1518
rdf4j_data:
16-
rdf4j_logs:
19+
rdf4j_logs:

docker/run.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
set -e
33
./build.sh
44

5-
echo "Starting the docker container"
5+
echo "Starting the docker container for ${APP_SERVER}"
66
docker compose up --force-recreate -d
77

88
# Wait for the server to be ready. Server is ready when the log contains something like "org.apache.catalina.startup.Catalina.start Server startup in 3400 ms".
99
printf '%s' "Waiting for container to be ready"
10-
while ! docker compose logs rdf4j | grep -q "Server startup in"; do
10+
while ! docker compose logs rdf4j | grep -q -e "Server startup in" -e "Started ServerConnector"; do
1111
printf '%s' "."
1212
# Exit with error if we have looped 30 times (e.g. 30 seconds)
1313
((c++)) && ((c == 30)) && echo "" && docker compose logs | tee && echo "" && docker ps -a | tee && printf '\n%s\n' "Timed out while waiting!" >&2 && exit 1

docker/shutdown.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
echo "Stopping the docker container for ${APP_SERVER}"
5+
docker compose down --rmi all -v
6+
File renamed without changes.

e2e/run.sh

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,43 @@
1212

1313
set -e
1414

15-
cd ..
16-
cd docker
17-
./run.sh
18-
./waitForDocker.sh
19-
cd ..
20-
cd e2e
15+
for APP_SERVER in tomcat jetty; do
16+
export APP_SERVER
17+
18+
cd ..
19+
cd docker
20+
./run.sh
21+
./waitForDocker.sh
22+
cd ..
23+
cd e2e
2124

22-
sleep 10
25+
sleep 10
2326

24-
if [ ! -d 'node_modules' ]; then
25-
echo "npm ci"
26-
npm ci
27-
fi
27+
if [ ! -d 'node_modules' ]; then
28+
echo "npm ci"
29+
npm ci
30+
fi
2831

29-
docker ps
32+
docker ps
3033

31-
npx playwright install --with-deps # install browsers
32-
npx playwright test
33-
exit $?
34+
npx playwright install --with-deps # install browsers
35+
npx playwright test
36+
37+
status_npx=$?
38+
39+
cd ..
40+
cd docker
41+
./shutdown.sh
42+
43+
# test for error code
44+
if [ $status_npx -ne 0 ] ; then
45+
echo "Error in E2E test for $APP_SERVER"
46+
exit $status_npx
47+
fi
48+
49+
echo "E2E test for $APP_SERVER OK"
50+
51+
# don't redo the whole build process just for making another docker image
52+
export SKIP_BUILD="skip"
53+
done
3454

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@
374374
<spring.version>5.3.37</spring.version>
375375
<guava.version>32.1.3-jre</guava.version>
376376
<jmhVersion>1.37</jmhVersion>
377-
<servlet.version>3.1.0</servlet.version>
377+
<servlet.version>4.0.0</servlet.version>
378378
<junit.version>5.9.3</junit.version>
379379
<jetty.version>9.4.54.v20240208</jetty.version>
380380
<netty.version>4.1.111.Final</netty.version>

0 commit comments

Comments
 (0)