Skip to content
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

included support of java LTS with maven #238

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ build
.idea
**/bin/**
.settings
target
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This repository contains the Classic OpenFaaS templates, but many more are avail
| python | Python | 2.7 | Alpine Linux | classic | [Python 2.7 template](https://github.com/openfaas/templates/tree/master/template/python)
| 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)
| java11 | Java | 11 | Debian GNU/Linux | of-watchdog | [Java LTS template](https://github.com/openfaas/templates/tree/master/template/java11)
| java11-maven | Java | 11 | Debian GNU/Linux | of-watchdog | [Java Maven LTS template](https://github.com/openfaas/templates/tree/master/template/java11-maven)
| ruby | Ruby | 2.7 | Alpine Linux 3.11 | classic| [Ruby template](https://github.com/openfaas/templates/tree/master/template/ruby)
| php7 | PHP | 7.2 | Alpine Linux | classic | [PHP 7 template](https://github.com/openfaas/templates/tree/master/template/php7)
| csharp | C# | N/A | Debian GNU/Linux 9 | classic | [C# template](https://github.com/openfaas/templates/tree/master/template/csharp)
Expand Down
57 changes: 57 additions & 0 deletions template/java11-maven/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
FROM openjdk:11-jdk-slim as builder

ENV MAVEN_VER=3.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 maven.." \
&& curl -sSfL "https://mirrors.estointernet.in/apache/maven/maven-3/${MAVEN_VER}/binaries/apache-maven-${MAVEN_VER}-bin.zip" -o apache-maven-$MAVEN_VER-bin.zip \
&& unzip apache-maven-$MAVEN_VER-bin.zip -d /opt/ \
&& rm apache-maven-$MAVEN_VER-bin.zip

# Export some environment variables
ENV MAVEN_HOME=/opt/apache-maven-$MAVEN_VER/
ENV PATH=$PATH:$MAVEN_HOME/bin

WORKDIR /home/app

COPY . /home/app/

RUN mvn clean package
RUN find .

FROM openfaas/of-watchdog:0.7.6 as watchdog

FROM openjdk:11-jre-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/target/function-0.1.0-bin.zip ./function-0.1.0.zip
user app
RUN unzip ./function-0.1.0.zip

WORKDIR /home/app/

ENV upstream_url="http://127.0.0.1:8082"
ENV mode="http"
ENV CLASSPATH="/home/app/function-0.1.0/function-0.1.0.jar:/home/app/function-0.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/java11-maven/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Template: java11

The Java11 template uses maven as a build system.

Maven version: 5.5.1

### Structure

There are three projects which make up a single maven 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 ./pom.xml in the normal way using Maven Repository, a local JAR or some other remote repository.

104 changes: 104 additions & 0 deletions template/java11-maven/function/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.openfaas</groupId>
<artifactId>function</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<openfaas.model.version>0.1.1</openfaas.model.version>
<openfaas.entrypoint.version>0.1.0</openfaas.entrypoint.version>
<junit.version>4.13.1</junit.version>
<maven.shade.plugin>3.2.4</maven.shade.plugin>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.assembly.plugin.version>2.5.3</maven.assembly.plugin.version>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/com.openfaas/model -->
<dependency>
<groupId>com.openfaas</groupId>
<artifactId>model</artifactId>
<version>${openfaas.model.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.openfaas/entrypoint -->
<dependency>
<groupId>com.openfaas</groupId>
<artifactId>entrypoint</artifactId>
<version>${openfaas.entrypoint.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.plugin}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.openfaas.function.Handler</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin> -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven.assembly.plugin.version}</version>
<configuration>
<descriptor>src/assembly/dep.xml</descriptor>
</configuration>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
17 changes: 17 additions & 0 deletions template/java11-maven/function/src/assembly/dep.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
<include>lib/</include>
</includes>
</fileSet>
</fileSets>
</assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.openfaas.function;

import com.openfaas.model.IHandler;
import com.openfaas.model.IResponse;
import com.openfaas.model.IRequest;
import com.openfaas.model.Response;

public class Handler extends com.openfaas.model.AbstractHandler {

public IResponse Handle(IRequest req) {
Response res = new Response();
res.setBody("Hello, world!");

return res;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.openfaas.function;

import org.junit.Test;
import static org.junit.Assert.*;

import com.openfaas.function.Handler;
import com.openfaas.model.IHandler;

public class HandlerTest {
@Test public void handlerIsNotNull() {
IHandler handler = new Handler();
assertTrue("Expected handler not to be null", handler != null);
}
}
12 changes: 12 additions & 0 deletions template/java11-maven/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.openfaas</groupId>
<artifactId>java11</artifactId>
<packaging>pom</packaging>
<version>0.1.0</version>
<modules>
<module>function</module>
</modules>
</project>
4 changes: 4 additions & 0 deletions template/java11-maven/template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
language: java11
welcome_message: |
You have created a function using the java11 template which uses an LTS
version of the OpenJDK.