Skip to content

Commit 5816995

Browse files
committed
Add java17 template
Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
1 parent 680916d commit 5816995

File tree

18 files changed

+902
-1
lines changed

18 files changed

+902
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ See: `faas-cli template store list` to see which templates are both: recommended
2626
| python3-debian | Python | 3 | Debian Linux | classic | [Legacy Python 3 Debian template](https://github.com/openfaas/templates/tree/master/template/python3-debian)
2727
| python27 | Python | 2.7.18 | Alpine Linux | classic | [Python 2.7 template (deprecated)](https://github.com/openfaas/templates/tree/master/template/python27)
2828
| 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)
29-
| java11 | Java | 11 | Debian GNU/Linux | of-watchdog | [Java LTS template](https://github.com/openfaas/templates/tree/master/template/java11)
29+
| java11 | Java | 11 | Debian GNU/Linux | of-watchdog | [Deprecated Java template](https://github.com/openfaas/templates/tree/master/template/java11)
30+
| java17 | Java | 11 | Debian GNU/Linux | of-watchdog | [Java LTS template](https://github.com/openfaas/templates/tree/master/template/java17)
3031
| ruby | Ruby | 3.3 | Alpine Linux | classic| [Ruby template](https://github.com/openfaas/templates/tree/master/template/ruby)
3132
| php7 | PHP | 7.4 | Alpine Linux | classic | [PHP 7 template](https://github.com/openfaas/templates/tree/master/template/php7)
3233
| php8 | PHP | 8.2 | Alpine Linux | classic | [PHP 8 template](https://github.com/openfaas/templates/tree/master/template/php8)

template/java17/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
FROM openjdk:17-jdk-slim AS builder
2+
3+
ENV GRADLE_VER=7.6.3
4+
5+
RUN apt-get update -qqy \
6+
&& apt-get install -qqy \
7+
--no-install-recommends \
8+
curl \
9+
ca-certificates \
10+
unzip
11+
12+
RUN mkdir -p /opt/ && cd /opt/ \
13+
&& echo "Downloading gradle.." \
14+
&& curl -sSfL "https://services.gradle.org/distributions/gradle-${GRADLE_VER}-bin.zip" -o gradle-$GRADLE_VER-bin.zip \
15+
&& unzip gradle-$GRADLE_VER-bin.zip -d /opt/ \
16+
&& rm gradle-$GRADLE_VER-bin.zip
17+
18+
# Export some environment variables
19+
ENV GRADLE_HOME=/opt/gradle-$GRADLE_VER/
20+
ENV PATH=$PATH:$GRADLE_HOME/bin
21+
22+
RUN mkdir -p /home/app/libs
23+
24+
ENV GRADLE_OPTS="-Dorg.gradle.daemon=false"
25+
WORKDIR /home/app
26+
27+
COPY . /home/app/
28+
29+
RUN gradle build --debug
30+
RUN find .
31+
32+
FROM ghcr.io/openfaas/of-watchdog:0.10.6 AS watchdog
33+
34+
FROM openjdk:17-slim AS ship
35+
RUN apt-get update -qqy \
36+
&& apt-get install -qqy \
37+
--no-install-recommends \
38+
unzip
39+
RUN addgroup --system app \
40+
&& adduser --system --ingroup app app
41+
42+
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
43+
RUN chmod +x /usr/bin/fwatchdog
44+
45+
WORKDIR /home/app
46+
COPY --from=builder /home/app/function/build/distributions/function-1.0.zip ./function-1.0.zip
47+
USER app
48+
RUN unzip ./function-1.0.zip
49+
50+
WORKDIR /home/app/
51+
52+
ENV upstream_url="http://127.0.0.1:8082"
53+
ENV mode="http"
54+
ENV CLASSPATH="/home/app/function-1.0/function-1.0.jar:/home/app/function-1.0/lib/*"
55+
56+
ENV fprocess="java -XX:+UseContainerSupport com.openfaas.entrypoint.App"
57+
EXPOSE 8080
58+
59+
HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1
60+
61+
CMD ["fwatchdog"]

template/java17/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Template: java24
2+
3+
The Java11 template uses gradle as a build system.
4+
5+
Gradle version: 5.5.1
6+
7+
### Structure
8+
9+
There are three projects which make up a single gradle build:
10+
11+
- model - (Library) classes for parsing request/response
12+
- function - (Library) your function code as a developer, you will only ever see this folder
13+
- entrypoint - (App) HTTP server for re-using the JVM between requests
14+
15+
### Handler
16+
17+
The handler is written in the `./src/main/Handler.java` folder
18+
19+
Tests are supported with junit via files in `./src/test`
20+
21+
### External dependencies
22+
23+
External dependencies can be specified in ./build.gradle in the normal way using jcenter, a local JAR or some other remote repository.
24+

template/java17/build.gradle

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
allprojects {
2+
repositories {
3+
jcenter()
4+
}
5+
}
6+
7+
subprojects {
8+
version = '1.0'
9+
}
10+
11+
repositories {
12+
jcenter()
13+
14+
flatDir {
15+
dirs 'libs'
16+
}
17+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
plugins {
2+
id 'java-library'
3+
id 'distribution'
4+
id 'maven-publish'
5+
}
6+
7+
dependencies {
8+
api 'org.apache.commons:commons-math3:3.6.1'
9+
implementation 'com.google.guava:guava:23.0'
10+
testImplementation 'junit:junit:4.12'
11+
implementation 'com.openfaas:model:0.1.1'
12+
implementation 'com.openfaas:entrypoint:0.1.0'
13+
}
14+
15+
repositories {
16+
mavenCentral()
17+
18+
flatDir {
19+
dirs '../libs'
20+
}
21+
}
22+
23+
jar {
24+
manifest {
25+
attributes 'Implementation-Title': 'OpenFaaS Function',
26+
'Implementation-Version': '1.0'
27+
}
28+
}
29+
30+
distributions {
31+
main {
32+
contents {
33+
from jar
34+
into('lib') {
35+
from(project.configurations.runtimeClasspath)
36+
}
37+
}
38+
}
39+
}
40+
41+
// Configure publishing with the maven-publish plugin
42+
publishing {
43+
publications {
44+
mavenJava(MavenPublication) {
45+
from components.java
46+
artifact jar
47+
48+
pom {
49+
name.set('OpenFaaS Function')
50+
description.set('An OpenFaaS function implementation.')
51+
url.set('https://www.openfaas.com/')
52+
licenses {
53+
license {
54+
name.set('MIT')
55+
url.set('https://opensource.org/licenses/MIT')
56+
}
57+
}
58+
developers {
59+
developer {
60+
id.set('openfaas')
61+
name.set('OpenFaaS Ltd')
62+
email.set('[email protected]')
63+
}
64+
}
65+
scm {
66+
connection.set('scm:git:https://github.com/openfaas/templates.git')
67+
developerConnection.set('scm:git:https://github.com/openfaas/templates.git')
68+
url.set('https://github.com/openfaas/templates')
69+
}
70+
}
71+
}
72+
}
73+
74+
repositories {
75+
flatDir {
76+
dirs 'repos'
77+
}
78+
}
79+
}
60.2 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-bin.zip
4+
networkTimeout=10000
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)