Skip to content

Commit

Permalink
Update Java version to 22 in jvm environments (#386)
Browse files Browse the repository at this point in the history
* Jvm-Jersey environament based on Java 22

Signed-off-by: Md Soharab Ansari <[email protected]>

* Add handle all paths in JVM environment for prefix to work.
Fix indentation in jvm-jersey/pom.xml.

Signed-off-by: Md Soharab Ansari <[email protected]>

---------

Signed-off-by: Md Soharab Ansari <[email protected]>
  • Loading branch information
soharab-ic authored Sep 6, 2024
1 parent e9e8e95 commit e3dfa37
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 159 deletions.
8 changes: 4 additions & 4 deletions jvm-jersey/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM maven:3.5-jdk-8 as BUILD
FROM maven:3.9.9-eclipse-temurin-22-alpine AS build
WORKDIR /usr/src/myapp/

# To reuse the build cache, here we split maven dependency
Expand All @@ -9,7 +9,7 @@ RUN mvn dependency:go-offline
COPY src /usr/src/myapp/src/
RUN mvn package

FROM openjdk:8-jre-alpine
COPY --from=BUILD /usr/src/myapp/target/env-jvm-jersey-0.0.1.jar /app.jar
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar 8888
FROM eclipse-temurin:22-jdk-alpine
COPY --from=build /usr/src/myapp/target/env-jvm-jersey-0.0.1.jar /app.jar
ENTRYPOINT java ${JVM_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /app.jar 8888
EXPOSE 8888
15 changes: 0 additions & 15 deletions jvm-jersey/Dockerfile-11

This file was deleted.

4 changes: 2 additions & 2 deletions jvm-jersey/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-include ../rules.mk

.PHONY: all
all: jvm-jersey-env-11-img
all: jvm-jersey-env-22-img

jvm-jersey-env-11-img: Dockerfile-11
jvm-jersey-env-22-img: Dockerfile
59 changes: 22 additions & 37 deletions jvm-jersey/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,33 @@
## Fission builder base image
ARG BUILDER_IMAGE=fission/builder:latest
FROM ${BUILDER_IMAGE}

## Section copied from the openjdk:8-jdk-alpine Dockerfile - (https://github.com/docker-library/openjdk/blob/47a6539cd18023dafb45db9013455136cc0bca07/8/jdk/alpine/Dockerfile)

ENV LANG C.UTF-8
RUN { \
echo '#!/bin/sh'; \
echo 'set -e'; \
echo; \
echo 'dirname "$(dirname "$(readlink -f "$(which javac || which java)")")"'; \
} > /usr/local/bin/docker-java-home \
&& chmod +x /usr/local/bin/docker-java-home
ENV JAVA_HOME /usr/lib/jvm/java-1.8-openjdk
ENV PATH $PATH:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin

ENV JAVA_VERSION 8u181
## Use "fuzzy" version matching to pin the version to a major/minor release
ENV JAVA_ALPINE_VERSION "~8"

RUN set -x \
&& apk add --no-cache \
openjdk8="$JAVA_ALPINE_VERSION" \
&& [ "$JAVA_HOME" = "$(docker-java-home)" ]
ARG BUILDER_IMAGE=fission/builder
FROM ${BUILDER_IMAGE} AS builder

## From the eclipse-temurin:22-jdk-alpine - (https://github.com/adoptium/containers/blob/07677395574f5d3462c3b6fdf5f6c4a0a350b683/22/jdk/alpine/Dockerfile)

FROM eclipse-temurin:22-jdk-alpine

## Section copied from the Maven Dockerfile

RUN apk add --no-cache curl tar bash procps
RUN apk add --no-cache bash procps curl tar openssh-client

ARG MAVEN_VERSION=3.5.4
ARG USER_HOME_DIR="/root"
ARG SHA=ce50b1c91364cb77efe3776f756a6d92b76d9038b0a0782f7d53acf1e997a14d
ARG BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries
LABEL org.opencontainers.image.title="Apache Maven"
LABEL org.opencontainers.image.source=https://github.com/carlossg/docker-maven
LABEL org.opencontainers.image.url=https://github.com/carlossg/docker-maven
LABEL org.opencontainers.image.description="Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project's build, reporting and documentation from a central piece of information."

RUN mkdir -p /usr/share/maven /usr/share/maven/ref \
&& curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
&& echo "${SHA} /tmp/apache-maven.tar.gz" | sha256sum -c - \
&& tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \
&& rm -f /tmp/apache-maven.tar.gz \
&& ln -s /usr/share/maven/bin/mvn /usr/bin/mvn
ENV MAVEN_HOME=/usr/share/maven

ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2"
COPY --from=maven:3.9.9-eclipse-temurin-11 ${MAVEN_HOME} ${MAVEN_HOME}
COPY --from=maven:3.9.9-eclipse-temurin-11 /usr/local/bin/mvn-entrypoint.sh /usr/local/bin/mvn-entrypoint.sh
COPY --from=maven:3.9.9-eclipse-temurin-11 /usr/share/maven/ref/settings-docker.xml /usr/share/maven/ref/settings-docker.xml

RUN ln -s ${MAVEN_HOME}/bin/mvn /usr/bin/mvn

ARG MAVEN_VERSION=3.9.9
ARG USER_HOME_DIR="/root"
ENV MAVEN_CONFIG="$USER_HOME_DIR/.m2"

## Fission builder specific section
COPY --from=builder /builder /builder
ADD build.sh /usr/local/bin/build
EXPOSE 8001
43 changes: 0 additions & 43 deletions jvm-jersey/builder/Dockerfile-11

This file was deleted.

4 changes: 2 additions & 2 deletions jvm-jersey/builder/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-include ../../rules.mk

.PHONY: all
all: jvm-jersey-builder-11-img
all: jvm-jersey-builder-22-img

jvm-jersey-builder-11-img: Dockerfile-11
jvm-jersey-builder-22-img: Dockerfile
8 changes: 4 additions & 4 deletions jvm-jersey/envconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[
{
"builder": "jvm-jersey-builder-11",
"builder": "jvm-jersey-builder-22",
"examples": "https://github.com/fission/environments/tree/master/jvm-jersey/examples",
"icon": "./logo/Java-Logo.png",
"image": "jvm-jersey-env-11",
"image": "jvm-jersey-env-22",
"keywords": [],
"kind": "environment",
"maintainers": [
Expand All @@ -22,9 +22,9 @@
],
"name": "JVM Environment",
"readme": "https://github.com/fission/environments/tree/master/jvm-jersey",
"runtimeVersion": "11",
"runtimeVersion": "22",
"shortDescription": "JVM environment based on Jersey RESTful Web Services framework",
"status": "Stable",
"version": "1.31.1"
"version": "1.31.2"
}
]
4 changes: 2 additions & 2 deletions jvm-jersey/examples/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>

<dependencies>
Expand Down
35 changes: 20 additions & 15 deletions jvm-jersey/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<version>0.0.1</version>

<properties>
<java.source.level>1.6</java.source.level>
<java.target.level>1.6</java.target.level>
<maven.compiler.release>22</maven.compiler.release>
<jetty.version>9.4.55.v20240627</jetty.version>
<jersey.version>2.41</jersey.version>
</properties>

<dependencies>
Expand All @@ -21,32 +22,37 @@
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.41.v20210516</version>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.40.v20210413</version>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.34</version>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.34</version>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>
</dependencies>

Expand All @@ -55,10 +61,9 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.source.level}</source>
<target>${java.target.level}</target>
<release>${maven.compiler.release}</release>
<encoding>UTF-8</encoding>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.fission;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

@JsonIgnoreProperties(ignoreUnknown = true)
public class FunctionLoadRequest {
Expand Down
28 changes: 13 additions & 15 deletions jvm-jersey/src/main/java/io/fission/JerseyServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
Expand All @@ -11,16 +10,15 @@
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.DELETE;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Context;
import javax.ws.rs.container.ContainerRequestContext;

import io.fission.Function;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;

@Path("/")
public class JerseyServer {
Expand All @@ -29,7 +27,7 @@ public class JerseyServer {

private static final int CLASS_LENGTH = 6;

private static Logger logger = Logger.getGlobal();
private static final Logger logger = Logger.getGlobal();

@GET
public Response home(@Context ContainerRequestContext request) {
Expand Down Expand Up @@ -63,7 +61,7 @@ public Response specialize(FunctionLoadRequest req) {
}

String entryPoint = req.getFunctionName();
logger.log(Level.INFO, "Entrypoint class:" + entryPoint);
logger.log(Level.INFO, "Entrypoint class:{0}", entryPoint);
if (entryPoint == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("Entrypoint class is missing in the JAR or the name is incorrect")
.build();
Expand Down Expand Up @@ -105,35 +103,35 @@ public Response specialize(FunctionLoadRequest req) {
// Instantiate the function class
fn = (Function) cl.loadClass(entryPoint).newInstance();
} catch (MalformedURLException e) {
e.printStackTrace();
e.printStackTrace(System.err);
return Response.status(Response.Status.BAD_REQUEST).entity("Entrypoint class is missing in the function")
.build();
} catch (ClassNotFoundException e) {
e.printStackTrace();
e.printStackTrace(System.err);
return Response.status(Response.Status.BAD_REQUEST).entity("Error loading Function or dependent class")
.build();
} catch (InstantiationException e) {
e.printStackTrace();
e.printStackTrace(System.err);
return Response.status(Response.Status.BAD_REQUEST)
.entity("Error creating a new instance of function class").build();
} catch (IllegalAccessException e) {
e.printStackTrace();
e.printStackTrace(System.err);
return Response.status(Response.Status.BAD_REQUEST)
.entity("Error creating a new instance of function class").build();
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace(System.err);
return Response.status(Response.Status.BAD_REQUEST).entity("Error reading the JAR file").build();
} finally {
try {
jarFile.close();
} catch (IOException e) {
e.printStackTrace();
e.printStackTrace(System.err);
return Response.status(Response.Status.BAD_REQUEST)
.entity("Error closing the file while loading the class").build();
}
}
long elapsedTime = System.nanoTime() - startTime;
logger.log(Level.INFO, "Specialize call done in: " + elapsedTime / 1000000 + " ms");
logger.log(Level.INFO, "Specialize call done in: {0} ms", elapsedTime / 1000000);
return Response.status(Response.Status.OK).entity("Done").build();
}

Expand Down
10 changes: 7 additions & 3 deletions jvm-jersey/src/main/java/io/fission/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Main {

private static final int DEFAULT_PORT = 8888;

private int serverPort;
private final int serverPort;

public Main(int serverPort) throws Exception {
this.serverPort = serverPort;
Expand Down Expand Up @@ -42,9 +42,13 @@ public static void main(String[] args) throws Exception {
try {
serverPort = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
e.printStackTrace();
e.printStackTrace(System.err);
}
}
new Main(serverPort);
try {
Main _ = new Main(serverPort);
} catch (Exception e) {
e.printStackTrace(System.err);
}
}
}
Loading

0 comments on commit e3dfa37

Please sign in to comment.