forked from fnproject/fdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fnproject/master
Origin repo changes sync
- Loading branch information
Showing
30 changed files
with
669 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ target/ | |
logs/ | ||
/headrevtag.txt | ||
*.bak | ||
*.versionsBackup | ||
*.versionsBackup | ||
.gradle | ||
examples/gradle-build/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
api/src/test/java/com/fnproject/fn/api/flow/FlowsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.fnproject.fn.api.flow; | ||
|
||
import java.lang.reflect.Modifier; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
import org.junit.Test; | ||
|
||
public class FlowsTest { | ||
public FlowsTest() { | ||
} | ||
|
||
/** People shall not be allowed to create subclasses of {@code Flow}: | ||
* <pre> | ||
* static class MyFlows extends Flows { | ||
* } | ||
* </pre> | ||
*/ | ||
@Test | ||
public void dontSubclassFlows() { | ||
assertTrue("Flows is final", Modifier.isFinal(Flows.class.getModifiers())); | ||
assertEquals("No visible constructors", 0, Flows.class.getConstructors().length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
#!/bin/bash -ex | ||
|
||
cd /tmp/cache-deps && mvn test package dependency:copy-dependencies -Dmaven.repo.local=/usr/share/maven/ref/repository -Dmdep.prependGroupId=true -DoutputDirectory=target | ||
set -x | ||
set -e | ||
|
||
if [ -n "$FN_REPO_URL" ]; then | ||
REPO_DFN="-Dfn.repo.url=$FN_REPO_URL" | ||
fi | ||
|
||
|
||
cd /tmp/cache-deps && mvn test package dependency:copy-dependencies -Dmaven.repo.local=/usr/share/maven/ref/repository -Dmdep.prependGroupId=true -DoutputDirectory=target $REPO_DFN | ||
cd / && rm -fr /tmp/cache-deps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.gradle | ||
.idea | ||
.git | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM gradle:4.5.1-jdk8 as build-stage | ||
WORKDIR /function | ||
# needed for gradle? | ||
USER root | ||
ENV GRADLE_USER_HOME /function/.gradle | ||
|
||
# Code build | ||
# Copy any build files into the build container and build | ||
COPY *.gradle /function/ | ||
RUN ["gradle", "-s", "--no-daemon","--console","plain","cacheDeps"] | ||
|
||
# Copies build source into build container | ||
COPY src /function/src | ||
|
||
RUN ["gradle", "-s", "--no-daemon","--console","plain","build"] | ||
# Container build | ||
FROM fnproject/fn-java-fdk:1.0.56 | ||
WORKDIR /function | ||
COPY --from=build-stage /function/build/libs/*.jar /function/build/deps/*.jar /function/app/ | ||
CMD ["com.example.fn.HelloFunction::handleRequest"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Fn Gradle + Java fdk example | ||
|
||
Fn uses Maven by default for builds. This is an example that uses Fn's `docker` runtime format to build a Java function using the [Fn Java FDK](https://github.com/fnproject/fdk-java). | ||
|
||
The example consists of a `Dockerfile` that builds the function using gradle and copies the function's dependencies to `build/deps` and a func.yaml that uses that `Dockerfile` to build the function. | ||
|
||
Note that FDK versions are hard-coded in this example, you may need to update them manually to more recent version. | ||
|
||
Key points: | ||
|
||
* [Dockerfile](Dockerfile) - contains the containerised docker build (based on dockerhub library/gradle images) and image build - this includes the gradle invocation | ||
* The `cacheDeps` task in `build.gradle` is invoked within the Dockerfile - The task pulls down dependencies into the container gradle cache to speed up docker builds. | ||
* The `copyDeps` task in `build.gradle` copies the functions compile deps | ||
* This uses JDK 8 by default - you can change this to Java 9 by changing : `FROM gradle:4.5.1-jdk8 as build-stage` to `FROM gradle:4.5.1-jdk9 as build-stage` and `FROM fnproject/fn-java-fdk:1.0.56` to `FROM fnproject/fn-java-fdk:jdk9-1.0.56` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apply plugin: 'java' | ||
|
||
ext { | ||
fdkVersion = '1.0.56' | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven { | ||
url 'https://dl.bintray.com/fnproject/fnproject' | ||
} | ||
} | ||
|
||
dependencies { | ||
runtime "com.fnproject.fn:api:$fdkVersion" | ||
// runtime "com.fnproject.fn:runtime:$fdkVersion" // this is optional and included with its deps in the base image to reduce layer size | ||
|
||
testCompile "junit:junit:4.12" | ||
testCompile "com.fnproject.fn:testing:$fdkVersion" | ||
} | ||
|
||
task cacheDeps(type: Exec) { | ||
configurations.testRuntime.files | ||
commandLine 'echo', 'Downloaded all dependencies' | ||
} | ||
|
||
task copyDeps(type: Copy) { | ||
from configurations.compile | ||
into "${project.buildDir}/deps" | ||
} | ||
|
||
build.dependsOn copyDeps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
name: gradle_build | ||
version: 0.0.3 | ||
runtime: docker | ||
format: http |
10 changes: 10 additions & 0 deletions
10
examples/gradle-build/src/main/java/com/example/fn/HelloFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.fn; | ||
|
||
public class HelloFunction { | ||
|
||
public String handleRequest(String input) { | ||
String name = (input == null || input.isEmpty()) ? "world" : input; | ||
return "Hello, " + name + "!"; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
examples/gradle-build/src/test/java/com/example/fn/HelloFunctionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.fn; | ||
|
||
import com.fnproject.fn.testing.*; | ||
import org.junit.*; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class HelloFunctionTest { | ||
|
||
@Rule | ||
public final FnTestingRule testing = FnTestingRule.createDefault(); | ||
|
||
@Test | ||
public void shouldReturnGreeting() { | ||
testing.givenEvent().enqueue(); | ||
testing.thenRun(HelloFunction.class, "handleRequest"); | ||
|
||
FnResult result = testing.getOnlyResult(); | ||
assertEquals("Hello, world!", result.getBodyAsString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ build: | |
-Dmdep.prependGroupId=true -DoutputDirectory=target | ||
format: http | ||
timeout: 120 | ||
name: test-4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.57 | ||
1.0.60 |