Skip to content

Fix issues with Spring fat-jars #690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
155 changes: 122 additions & 33 deletions Makefile

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions debug/Base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#
FROM golang:1.16
ARG BASE_IMAGE
FROM $BASE_IMAGE

ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH

RUN go get github.com/go-delve/delve/cmd/dlv
RUN go install github.com/go-delve/delve/cmd/dlv@latest

ENTRYPOINT ["dlv"]
7 changes: 3 additions & 4 deletions debug/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#
ARG BASE_IMAGE=ghcr.io/oracle/coherence-operator:delve
FROM $BASE_IMAGE
FROM ghcr.io/oracle/coherence-operator:delve

ARG target
ARG version
Expand All @@ -19,8 +18,8 @@ ENV COHERENCE_IMAGE=$coherence_image \

WORKDIR /

COPY bin/linux/$target/runner /files/runner
COPY bin/linux/$target/runner-debug /files/runner
COPY java/coherence-operator/target/docker/lib/*.jar /files/lib/
COPY java/coherence-operator/target/docker/logging/logging.properties /files/logging/logging.properties

ENTRYPOINT ["dlv", "--listen=:2345", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/manager", "--"]
ENTRYPOINT ["dlv", "--listen=:2345", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/files/runner", "--"]
56 changes: 49 additions & 7 deletions docs/applications/070_spring.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////////

Copyright (c) 2020, Oracle and/or its affiliates.
Copyright (c) 2020, 2025, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at
http://oss.oracle.com/licenses/upl.

Expand Down Expand Up @@ -67,8 +67,11 @@ like the diagram below; where you can see the `/spring` directory contains the S
└─⊕ var
----

This type of image can be run by the Coherence Operator by specifying an application type of `spring` in the
`spec.application.type` field and by setting the working directory to the exploded directory, for example:
*Spring Boot 2.x or 3.x*
This type of image can be run by the Coherence Operator by specifying an application type of `spring`
for Spring Boot 2.x applications or `spring3` for SpringBoot 3.x applications.
The application type is set in the `spec.application.type` field and by setting the working directory
to the exploded directory, for example:

[source,yaml]
----
Expand All @@ -83,15 +86,39 @@ spec:
workingDir: /spring # <2>
----

<1> The `type` field set to `spring` tells the Operator that this is a Spring Boot application.
<1> The `type` field set to `spring` tells the Operator that this is a Spring Boot 2.x application.
<2> The working directory has been set to the directory containing the exploded Spring Boot application.

[source,yaml]
----
apiVersion: coherence.oracle.com/v1
kind: Coherence
metadata:
name: test
spec:
image: my-spring-app:1.0.0
application:
type: spring3 # <1>
workingDir: /spring # <2>
----

<1> The `type` field set to `spring3` tells the Operator that this is a Spring Boot 3.x application.
<2> The working directory has been set to the directory containing the exploded Spring Boot application.

When the Operator starts the application it will then run a command equivalent to:

*Spring Boot 2.x*
[source,bash]
----
cd /spring && java org.springframework.boot.loader.PropertiesLauncher
----

*Spring Boot 3.x*
[source,bash]
----
cd /spring && java org.springframework.boot.loader.launch.PropertiesLauncher
----


=== Using a Spring Boot Fat Jar

Expand Down Expand Up @@ -127,16 +154,23 @@ spec:
<2> The location of the Spring Boot jar has been set.

When the Operator starts the application it will then run a command equivalent to:

*Spring Boot 2.x*
[source,bash]
----
java -cp /app/libs/catalogue-1.0.0.jar org.springframework.boot.loader.PropertiesLauncher
----

*Spring Boot 3.x*
[source,bash]
----
java -cp /app/libs/catalogue-1.0.0.jar org.springframework.boot.loader.launch.PropertiesLauncher
----

NOTE: The Operator does not run the fat jar using the `java -jar` command because it needs to add various other
JVM arguments and append to the classpath, so it has to run the `org.springframework.boot.loader.PropertiesLauncher`
class as opposed to the `org.springframework.boot.loader.JarLauncher` that `java -jar` would run.


=== Using Could Native Buildpacks

If the Spring Boot Maven or Gradle plugin has been used to produce an image using
Expand Down Expand Up @@ -188,16 +222,24 @@ spec:
type: spring # <1>
----

<1> The application type has been set to `spring` so that the operator knows that this is a Spring Boot application,
and the fact that the image is a Buildpacks image will be auto-discovered.
<1> The application type has been set to `spring` (for Spring Boot 2.x) or `spring3` (for Spring Boot 3.x) so that the
operator knows that this is a Spring Boot application, and the fact that the image is a Buildpacks image will be auto-discovered.

When the Operator starts the application it will then run the buildpacks launcher with a command equivalent
to this:

*Spring Boot 2.x*
[source,bash]
----
/cnb/lifecycle/launcher java @jvm-args-file org.springframework.boot.loader.PropertiesLauncher
----

*Spring Boot 3.x*
[source,bash]
----
/cnb/lifecycle/launcher java @jvm-args-file org.springframework.boot.loader.launch.PropertiesLauncher
----

==== Buildpacks Detection

If for some reason buildpacks auto-detection does not work properly the `Coherence`
Expand Down
7 changes: 7 additions & 0 deletions hack/go-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Copyright (c) 2020, 2025, Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at
# http://oss.oracle.com/licenses/upl.
#

go version | read _ _ v _; echo "${v#go}"
93 changes: 93 additions & 0 deletions java/operator-test-helidon-2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2020, 2025, Oracle and/or its affiliates.
~ Licensed under the Universal Permissive License v 1.0 as shown at
~ http://oss.oracle.com/licenses/upl.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.oracle.coherence.kubernetes</groupId>
<artifactId>operator-parent</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>operator-test-helidon-2</artifactId>

<description>Oracle Coherence Kubernetes Operator Test (Helidon 2.x)</description>
<name>operator-test-helidon-2</name>

<properties>
<version.lib.helidon>2.6.5</version.lib.helidon>
<version.lib.activation-api>2.1.3</version.lib.activation-api>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.helidon</groupId>
<artifactId>helidon-dependencies</artifactId>
<version>${version.lib.helidon}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>${coherence.groupId}</groupId>
<artifactId>coherence</artifactId>
<version>${coherence.version}</version>
</dependency>
<dependency>
<groupId>${coherence.groupId}</groupId>
<artifactId>coherence-cdi-server</artifactId>
<version>${coherence.version}</version>
</dependency>
<dependency>
<groupId>${coherence.groupId}</groupId>
<artifactId>coherence-management</artifactId>
<version>${coherence.version}</version>
</dependency>

<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>${version.lib.activation-api}</version>
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${version.plugin.jib}</version>
<configuration>
<container>
<mainClass>io.helidon.microprofile.cdi.Main</mainClass>
</container>
<!-- MUST use packaged mode for Helidon CDI application -->
<containerizingMode>packaged</containerizingMode>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading
Loading