From b78f694ca055674199e4320c60042bd5faa9a9b7 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Thu, 3 Mar 2022 18:39:30 +0000 Subject: [PATCH] Update to use a shadow jar Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- template/java11-vert-x/Dockerfile | 14 +++----- .../java11-vert-x/entrypoint/build.gradle | 32 +++++++++++-------- template/java11-vert-x/function/build.gradle | 2 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/template/java11-vert-x/Dockerfile b/template/java11-vert-x/Dockerfile index 7d2d139d..b2c45a98 100644 --- a/template/java11-vert-x/Dockerfile +++ b/template/java11-vert-x/Dockerfile @@ -1,6 +1,5 @@ FROM openjdk:11-jdk-slim as builder -ENV GRADLE_VER=6.1.1 RUN apt-get update -qqy \ && apt-get install -qqy \ --no-install-recommends \ @@ -8,6 +7,7 @@ RUN apt-get update -qqy \ ca-certificates \ unzip +ENV GRADLE_VER=7.3.3 RUN mkdir -p /opt/ && cd /opt/ \ && echo "Downloading gradle.." \ && curl -sSfL "https://services.gradle.org/distributions/gradle-${GRADLE_VER}-bin.zip" -o gradle-$GRADLE_VER-bin.zip \ @@ -26,21 +26,15 @@ WORKDIR /home/app COPY . /home/app/ RUN gradle build -RUN find . FROM ghcr.io/openfaas/of-watchdog:0.9.3 as watchdog FROM openjdk:11-jre-slim as ship -RUN apt-get update -qqy \ - && apt-get install -qqy \ - --no-install-recommends \ - unzip COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog RUN chmod +x /usr/bin/fwatchdog WORKDIR /home/app -COPY --from=builder /home/app/entrypoint/build/distributions/entrypoint-1.0.zip ./entrypoint-1.0.zip -RUN unzip ./entrypoint-1.0.zip +COPY --from=builder /home/app/entrypoint/build/libs/app.jar ./app.jar RUN addgroup --system app \ && adduser --system --ingroup app app @@ -52,9 +46,9 @@ USER app ENV upstream_url="http://127.0.0.1:8082" ENV mode="http" -ENV CLASSPATH="/home/app/entrypoint-1.0/lib/*" +# ENV CLASSPATH="/home/app/entrypoint-1.0/lib/*" -ENV fprocess="java -XX:+UseContainerSupport -Dvertx.cacheDirBase=/tmp/.vertx-cache com.openfaas.entrypoint.App" +ENV fprocess="java -XX:+UseContainerSupport -Dvertx.cacheDirBase=/tmp/.vertx-cache -jar app.jar" EXPOSE 8080 HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1 diff --git a/template/java11-vert-x/entrypoint/build.gradle b/template/java11-vert-x/entrypoint/build.gradle index e4514524..024a4891 100644 --- a/template/java11-vert-x/entrypoint/build.gradle +++ b/template/java11-vert-x/entrypoint/build.gradle @@ -13,26 +13,30 @@ plugins { // Apply the application plugin to add support for building an application id 'application' + id 'com.github.johnrengelman.shadow' version '7.1.2' + } // Define the main class for the application -mainClassName = 'App' +mainClassName = 'com.openfaas.entrypoint.App' dependencies { // Vert.x project - compile 'io.vertx:vertx-web:3.5.4' + implementation 'io.vertx:vertx-web:3.5.4' // Use JUnit test framework - testCompile 'junit:junit:4.12' + testImplementation 'junit:junit:4.12' - compile project(':function') + implementation project(':function') } -jar { +shadowJar { manifest { attributes 'Implementation-Title': 'OpenFaaS Function', - 'Implementation-Version': version + 'Implementation-Version': version, + 'Main-Class': mainClassName } + archiveFileName.set('app.jar') } // In this section you declare where to find the dependencies of your project @@ -42,10 +46,12 @@ repositories { jcenter() } -uploadArchives { - repositories { - flatDir { - dirs 'repos' - } - } -} +// uploadArchives { +// repositories { +// flatDir { +// dirs 'repos' +// } +// } +// } + +assemble.dependsOn(shadowJar) diff --git a/template/java11-vert-x/function/build.gradle b/template/java11-vert-x/function/build.gradle index 2e8b4339..0e048303 100644 --- a/template/java11-vert-x/function/build.gradle +++ b/template/java11-vert-x/function/build.gradle @@ -13,7 +13,7 @@ plugins { dependencies { // Vert.x project - compile 'io.vertx:vertx-web:3.5.4' + implementation 'io.vertx:vertx-web:3.5.4' // Use JUnit test framework testImplementation 'junit:junit:4.12'