Skip to content

Commit

Permalink
Add java17 template
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Dec 9, 2024
1 parent 680916d commit 5816995
Show file tree
Hide file tree
Showing 18 changed files with 902 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ See: `faas-cli template store list` to see which templates are both: recommended
| python3-debian | Python | 3 | Debian Linux | classic | [Legacy Python 3 Debian template](https://github.com/openfaas/templates/tree/master/template/python3-debian)
| python27 | Python | 2.7.18 | Alpine Linux | classic | [Python 2.7 template (deprecated)](https://github.com/openfaas/templates/tree/master/template/python27)
| java11-vert-x | Java and [Vert.x](https://vertx.io/) | 11 | Debian GNU/Linux | of-watchdog | [Java LTS template](https://github.com/openfaas/templates/tree/master/template/java11-vert-x)
| java11 | Java | 11 | Debian GNU/Linux | of-watchdog | [Java LTS template](https://github.com/openfaas/templates/tree/master/template/java11)
| java11 | Java | 11 | Debian GNU/Linux | of-watchdog | [Deprecated Java template](https://github.com/openfaas/templates/tree/master/template/java11)
| java17 | Java | 11 | Debian GNU/Linux | of-watchdog | [Java LTS template](https://github.com/openfaas/templates/tree/master/template/java17)
| ruby | Ruby | 3.3 | Alpine Linux | classic| [Ruby template](https://github.com/openfaas/templates/tree/master/template/ruby)
| php7 | PHP | 7.4 | Alpine Linux | classic | [PHP 7 template](https://github.com/openfaas/templates/tree/master/template/php7)
| php8 | PHP | 8.2 | Alpine Linux | classic | [PHP 8 template](https://github.com/openfaas/templates/tree/master/template/php8)
Expand Down
61 changes: 61 additions & 0 deletions template/java17/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
FROM openjdk:17-jdk-slim AS builder

ENV GRADLE_VER=7.6.3

RUN apt-get update -qqy \
&& apt-get install -qqy \
--no-install-recommends \
curl \
ca-certificates \
unzip

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 \
&& unzip gradle-$GRADLE_VER-bin.zip -d /opt/ \
&& rm gradle-$GRADLE_VER-bin.zip

# Export some environment variables
ENV GRADLE_HOME=/opt/gradle-$GRADLE_VER/
ENV PATH=$PATH:$GRADLE_HOME/bin

RUN mkdir -p /home/app/libs

ENV GRADLE_OPTS="-Dorg.gradle.daemon=false"
WORKDIR /home/app

COPY . /home/app/

RUN gradle build --debug
RUN find .

FROM ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog

FROM openjdk:17-slim AS ship
RUN apt-get update -qqy \
&& apt-get install -qqy \
--no-install-recommends \
unzip
RUN addgroup --system app \
&& adduser --system --ingroup app app

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog

WORKDIR /home/app
COPY --from=builder /home/app/function/build/distributions/function-1.0.zip ./function-1.0.zip
USER app
RUN unzip ./function-1.0.zip

WORKDIR /home/app/

ENV upstream_url="http://127.0.0.1:8082"
ENV mode="http"
ENV CLASSPATH="/home/app/function-1.0/function-1.0.jar:/home/app/function-1.0/lib/*"

ENV fprocess="java -XX:+UseContainerSupport com.openfaas.entrypoint.App"
EXPOSE 8080

HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1

CMD ["fwatchdog"]
24 changes: 24 additions & 0 deletions template/java17/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Template: java24

The Java11 template uses gradle as a build system.

Gradle version: 5.5.1

### Structure

There are three projects which make up a single gradle build:

- model - (Library) classes for parsing request/response
- function - (Library) your function code as a developer, you will only ever see this folder
- entrypoint - (App) HTTP server for re-using the JVM between requests

### Handler

The handler is written in the `./src/main/Handler.java` folder

Tests are supported with junit via files in `./src/test`

### External dependencies

External dependencies can be specified in ./build.gradle in the normal way using jcenter, a local JAR or some other remote repository.

17 changes: 17 additions & 0 deletions template/java17/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
allprojects {
repositories {
jcenter()
}
}

subprojects {
version = '1.0'
}

repositories {
jcenter()

flatDir {
dirs 'libs'
}
}
79 changes: 79 additions & 0 deletions template/java17/function/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
plugins {
id 'java-library'
id 'distribution'
id 'maven-publish'
}

dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:23.0'
testImplementation 'junit:junit:4.12'
implementation 'com.openfaas:model:0.1.1'
implementation 'com.openfaas:entrypoint:0.1.0'
}

repositories {
mavenCentral()

flatDir {
dirs '../libs'
}
}

jar {
manifest {
attributes 'Implementation-Title': 'OpenFaaS Function',
'Implementation-Version': '1.0'
}
}

distributions {
main {
contents {
from jar
into('lib') {
from(project.configurations.runtimeClasspath)
}
}
}
}

// Configure publishing with the maven-publish plugin
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact jar

pom {
name.set('OpenFaaS Function')
description.set('An OpenFaaS function implementation.')
url.set('https://www.openfaas.com/')
licenses {
license {
name.set('MIT')
url.set('https://opensource.org/licenses/MIT')
}
}
developers {
developer {
id.set('openfaas')
name.set('OpenFaaS Ltd')
email.set('info@openfaas.com')
}
}
scm {
connection.set('scm:git:https://github.com/openfaas/templates.git')
developerConnection.set('scm:git:https://github.com/openfaas/templates.git')
url.set('https://github.com/openfaas/templates')
}
}
}
}

repositories {
flatDir {
dirs 'repos'
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 5816995

Please sign in to comment.