Skip to content

Commit b79c88c

Browse files
Migrate RefImpl CM to slim container with embedded Jetty 12 and JLink
- Replaced WAR packaging with JAR and embedded Jetty 12 (EE10). - Updated Dockerfile to use multi-stage build with jlink for a minimal runtime. - Migrated dependencies to use Jetty BOM and eliminated conflicts. - Removed dependency on JSP and oauth-webapp (as per requirements). - Configured SessionHandler and ResourceServlet in Main.java. - Replaced index.jsp with static index.html.
1 parent 324316e commit b79c88c

File tree

5 files changed

+342
-111
lines changed

5 files changed

+342
-111
lines changed

src/server-cm/Dockerfile

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ COPY server-cm/ server-cm/
1818
# Build only the specific module and its dependencies
1919
RUN mvn -B --no-transfer-progress -DskipTests clean package -pl server-cm -am
2020

21-
FROM docker.io/library/jetty:12-jre21-eclipse-temurin
21+
# Create a custom Java runtime
22+
RUN $JAVA_HOME/bin/jlink \
23+
--add-modules java.base,java.compiler,java.desktop,java.management,java.naming,java.net.http,java.scripting,java.security.jgss,java.security.sasl,java.sql,java.xml.crypto,jdk.unsupported,java.xml,jdk.zipfs,java.instrument \
24+
--strip-debug \
25+
--no-man-pages \
26+
--no-header-files \
27+
--compress=2 \
28+
--output /javaruntime
2229

23-
# Add metadata
24-
LABEL org.opencontainers.image.title="OSLC RefImpl CM Server"
25-
LABEL org.opencontainers.image.description="OSLC Change Management Reference Implementation"
26-
LABEL org.opencontainers.image.source="https://github.com/oslc-op/refimpl"
27-
LABEL org.opencontainers.image.vendor="OSLC Open Project"
28-
LABEL org.opencontainers.image.licenses="EPL-2.0"
30+
FROM alpine:latest
2931

30-
# WARNING DO NOT CHANGE WORKDIR or set it back to what it was before
31-
# $JETTY_BASE must be correct before starting Jetty
32+
ENV JAVA_HOME=/opt/java/openjdk
33+
ENV PATH="${JAVA_HOME}/bin:${PATH}"
34+
COPY --from=build /javaruntime $JAVA_HOME
3235

33-
COPY --from=build /src/server-cm/target/*.war /var/lib/jetty/webapps/ROOT.war
36+
WORKDIR /app
3437

35-
RUN java -jar "$JETTY_HOME/start.jar" --add-modules=ee9-deploy,ee9-jsp,ee9-jstl
38+
COPY --from=build /src/server-cm/target/lib/ ./lib/
39+
COPY --from=build /src/server-cm/target/server-cm.jar ./server-cm.jar
3640

3741
EXPOSE 8080
42+
43+
ENTRYPOINT ["java", "-jar", "server-cm.jar"]

src/server-cm/pom.xml

Lines changed: 72 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<groupId>co.oslc.refimpl</groupId>
1818
<artifactId>server-cm</artifactId>
1919
<version>0.3.0-SNAPSHOT</version>
20-
<packaging>war</packaging>
20+
<packaging>jar</packaging>
2121
<name>CM</name>
2222
<properties>
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -28,6 +28,7 @@
2828
<servlet.port>8801</servlet.port>
2929
<application.contextpath>/</application.contextpath>
3030
<application.filename>server-cm</application.filename>
31+
<jetty.version>12.0.16</jetty.version>
3132

3233
<!-- Start of user code properties
3334
-->
@@ -116,27 +117,6 @@
116117
</profile>
117118
<!-- End of user code
118119
-->
119-
<profile>
120-
<!-- some servlet containers (Tomcat) does not ship with a JSTL impl
121-
In such cases, run with this profile-->
122-
<id>with-jstl-impl</id>
123-
<dependencies>
124-
<!-- Start of user code profile_dependencies
125-
-->
126-
<!-- TODO: Add additional dependencies to this profile here to avoid them be overridden upon future re-generation -->
127-
<!-- End of user code
128-
-->
129-
<dependency>
130-
<groupId>jakarta.servlet.jsp.jstl</groupId>
131-
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
132-
</dependency>
133-
<dependency>
134-
<groupId>org.glassfish.web</groupId>
135-
<artifactId>jakarta.servlet.jsp.jstl</artifactId>
136-
</dependency>
137-
</dependencies>
138-
</profile>
139-
140120
</profiles>
141121
<!-- Start of user code pre_dependencies
142122
-->
@@ -151,6 +131,13 @@
151131
<scope>import</scope>
152132
<type>pom</type>
153133
</dependency>
134+
<dependency>
135+
<groupId>org.eclipse.jetty</groupId>
136+
<artifactId>jetty-bom</artifactId>
137+
<version>${jetty.version}</version>
138+
<type>pom</type>
139+
<scope>import</scope>
140+
</dependency>
154141
</dependencies>
155142
</dependencyManagement>
156143
<dependencies>
@@ -163,25 +150,21 @@
163150
</dependency>
164151
<!-- End of user code
165152
-->
153+
<!-- Embedded Jetty 12 (EE10) -->
154+
<dependency>
155+
<groupId>org.eclipse.jetty.ee10</groupId>
156+
<artifactId>jetty-ee10-servlet</artifactId>
157+
</dependency>
158+
166159
<!-- General dependencies -->
167160
<dependency>
168161
<groupId>org.slf4j</groupId>
169162
<artifactId>slf4j-simple</artifactId>
170-
<scope>runtime</scope>
171163
</dependency>
172164
<!-- Servlet dependencies -->
173165
<dependency>
174166
<groupId>jakarta.servlet</groupId>
175167
<artifactId>jakarta.servlet-api</artifactId>
176-
<scope>provided</scope>
177-
</dependency>
178-
<dependency>
179-
<groupId>jakarta.servlet.jsp.jstl</groupId>
180-
<artifactId>jakarta.servlet.jsp.jstl-api</artifactId>
181-
<!--When running with the jetty-maven-plugin, you
182-
get warnings about jsp classes being scanned from multiple locations.
183-
adding the "provided" scope avoids these warnings.-->
184-
<scope>provided</scope>
185168
</dependency>
186169
<dependency>
187170
<groupId>org.glassfish.jersey.core</groupId>
@@ -245,11 +228,9 @@
245228
<groupId>org.eclipse.lyo.server</groupId>
246229
<artifactId>oauth-consumer-store</artifactId>
247230
</dependency>
248-
<dependency>
249-
<groupId>org.eclipse.lyo.server</groupId>
250-
<artifactId>oauth-webapp</artifactId>
251-
<type>war</type>
252-
</dependency>
231+
<!-- Removed oauth-webapp war dependency as we are not using war overlay anymore
232+
and avoiding JSP. If needed, we would need to manually handle it. -->
233+
253234
<dependency>
254235
<groupId>org.eclipse.lyo</groupId>
255236
<artifactId>oslc-domains</artifactId>
@@ -308,63 +289,15 @@
308289
</compilerArgument>
309290
</configuration>
310291
</plugin>
311-
<plugin>
312-
<groupId>org.eclipse.jetty</groupId>
313-
<artifactId>jetty-maven-plugin</artifactId>
314-
<version>11.0.20</version>
315-
<configuration>
316-
<webApp>
317-
<contextPath>${application.contextpath}</contextPath>
318-
<_initParams>
319-
<org.eclipse.jetty.servlet.Default.useFileMappedBuffer>false</org.eclipse.jetty.servlet.Default.useFileMappedBuffer>
320-
</_initParams>
321-
</webApp>
322-
<httpConnector>
323-
<port>${servlet.port}</port>
324-
</httpConnector>
325-
<scan>5</scan>
326-
</configuration>
327-
</plugin>
328-
<plugin>
329-
<groupId>org.codehaus.cargo</groupId>
330-
<artifactId>cargo-maven3-plugin</artifactId>
331-
<version>1.10.25</version>
332-
<configuration>
333-
<!--This plugins supports the following containers-->
334-
<container>
335-
<!--These containers are know to work-->
336-
<containerId>tomcat10x</containerId>
337-
<containerId>jetty12x</containerId>
338-
<!-- <containerId>payara</containerId> -->
339-
<!-- <containerId>wildfly26x</containerId> -->
340-
<!--These containers are know to fail-->
341-
<!-- Context Root Not Found -->
342-
<!-- <containerId>liberty</containerId> -->
343-
</container>
344-
<configuration>
345-
<properties>
346-
<cargo.servlet.port>${servlet.port}</cargo.servlet.port>
347-
</properties>
348-
</configuration>
349-
<deployables>
350-
<deployable>
351-
<type>war</type>
352-
<location>${project.build.directory}/${project.build.finalName}.war</location>
353-
<properties>
354-
<context>${application.contextpath}</context>
355-
</properties>
356-
</deployable>
357-
</deployables>
358-
</configuration>
359-
</plugin>
360-
<!-- Swagger-ui -->
292+
361293
<plugin>
362294
<!-- Download Swagger UI webjar. -->
363295
<groupId>org.apache.maven.plugins</groupId>
364296
<artifactId>maven-dependency-plugin</artifactId>
365297
<version>3.9.0</version>
366298
<executions>
367299
<execution>
300+
<id>unpack-swagger-ui</id>
368301
<phase>prepare-package</phase>
369302
<goals>
370303
<goal>unpack</goal>
@@ -377,29 +310,68 @@
377310
<version>${swagger-ui.version}</version>
378311
</artifactItem>
379312
</artifactItems>
380-
<outputDirectory>${project.build.directory}/swagger-ui</outputDirectory>
313+
<!-- Unpack to classes so it is included in the jar -->
314+
<outputDirectory>${project.build.outputDirectory}/static/swagger-ui</outputDirectory>
315+
<includes>**/*.*</includes>
316+
</configuration>
317+
</execution>
318+
<execution>
319+
<id>copy-dependencies</id>
320+
<phase>package</phase>
321+
<goals>
322+
<goal>copy-dependencies</goal>
323+
</goals>
324+
<configuration>
325+
<outputDirectory>${project.build.directory}/lib</outputDirectory>
326+
<includeScope>runtime</includeScope>
327+
<useBaseVersion>true</useBaseVersion>
381328
</configuration>
382329
</execution>
383330
</executions>
384331
</plugin>
332+
385333
<plugin>
386-
<!-- Add Swagger UI resources to the war file. -->
387334
<groupId>org.apache.maven.plugins</groupId>
388-
<artifactId>maven-war-plugin</artifactId>
389-
<version>3.5.1</version>
335+
<artifactId>maven-jar-plugin</artifactId>
336+
<version>3.4.2</version>
390337
<configuration>
391-
<webResources combine.children="append">
392-
<resource>
393-
<directory>${project.build.directory}/swagger-ui/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}</directory>
394-
<includes>
395-
<include>**/*.*</include>
396-
</includes>
397-
<targetPath>/swagger-ui/dist</targetPath>
398-
</resource>
399-
</webResources>
338+
<archive>
339+
<manifest>
340+
<addClasspath>true</addClasspath>
341+
<classpathPrefix>lib/</classpathPrefix>
342+
<mainClass>co.oslc.refimpl.cm.Main</mainClass>
343+
<useUniqueVersions>false</useUniqueVersions>
344+
</manifest>
345+
</archive>
400346
</configuration>
401347
</plugin>
402348

349+
<!-- We also need to move the unpacked swagger-ui files to the right place.
350+
The unpack above puts them in static/swagger-ui/META-INF/resources/webjars/swagger-ui/${version}/
351+
We want them in static/swagger-ui/dist/
352+
-->
353+
<plugin>
354+
<artifactId>maven-resources-plugin</artifactId>
355+
<version>3.3.1</version>
356+
<executions>
357+
<execution>
358+
<id>copy-swagger-ui-dist</id>
359+
<phase>prepare-package</phase>
360+
<goals>
361+
<goal>copy-resources</goal>
362+
</goals>
363+
<configuration>
364+
<outputDirectory>${project.build.outputDirectory}/static/swagger-ui/dist</outputDirectory>
365+
<resources>
366+
<resource>
367+
<directory>${project.build.outputDirectory}/static/swagger-ui/META-INF/resources/webjars/swagger-ui/${swagger-ui.version}</directory>
368+
</resource>
369+
</resources>
370+
</configuration>
371+
</execution>
372+
</executions>
373+
</plugin>
374+
403375
<!-- Start of user code plugins
404376
-->
405377
<!-- End of user code

0 commit comments

Comments
 (0)