Merge pull request #479 from meltsufin/gcp-sample-doc

Adds Readme to GCP sample app
This commit is contained in:
Oleg Zhurakousky
2020-04-06 09:20:21 +02:00
committed by GitHub
8 changed files with 70 additions and 6 deletions

View File

@@ -130,3 +130,7 @@ Invoke the HTTP function:
----
curl https://REGION-PROJECT_ID.cloudfunctions.net/function-sample-gcp -d "hello"
----
==== Sample Function
Go to the link:../../spring-cloud-function-samples/function-sample-gcp/[function-sample-gcp] to try out a sample function that you can test locally or deploy to GCP.

View File

@@ -0,0 +1,3 @@
*{spring-cloud-function-version}*
include::adapters/gcp-intro.adoc[]

View File

@@ -11,6 +11,7 @@ The reference documentation consists of the following sections:
<<spring-cloud-function.adoc#,Reference Guide>> :: Spring Cloud Function Reference
<<aws.adoc#,AWS Adapter>> :: AWS Adapter Reference
<<azure.adoc#, Azure Adapter>> :: Azure Adapter Reference
<<gcp.adoc#, GCP Adapter>> :: GCP Adapter Reference
<<openwhisk.adoc#, Apache OpenWhisk Adapter>> :: Apache OpenWhisk Adapter Reference

View File

@@ -585,4 +585,5 @@ Invoker] acts natively is an adapter for Spring Cloud Function jars.
include::adapters/aws-intro.adoc[]
include::adapters/azure-intro.adoc[]
include::adapters/gcp-intro.adoc[]

View File

@@ -17,14 +17,15 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<google.cloud.functions.version>1.0.0-alpha-2-rc3</google.cloud.functions.version>
<google.cloud.functions.api.version>1.0.0-alpha-2-rc3</google.cloud.functions.api.version>
<google.cloud.functions.invoker.version>1.0.0-alpha-2-rc4</google.cloud.functions.invoker.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>${google.cloud.functions.version}</version>
<version>${google.cloud.functions.api.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -44,7 +45,7 @@
<dependency>
<groupId>com.google.cloud.functions.invoker</groupId>
<artifactId>java-function-invoker</artifactId>
<version>${google.cloud.functions.version}</version>
<version>${google.cloud.functions.invoker.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -46,13 +46,18 @@ public class FunctionInvoker
public FunctionInvoker() {
super();
init();
}
public FunctionInvoker(Class<?> configurationClass) {
super(configurationClass);
init();
}
private void init() {
System.setProperty("spring.http.converters.preferred-json-mapper", "gson");
Thread.currentThread() //TODO investigate if it is necessary
.setContextClassLoader(FunctionInvoker.class.getClassLoader());
Thread.currentThread() // TODO: remove after upgrading to 1.0.0-alpha-2-rc5
.setContextClassLoader(FunctionInvoker.class.getClassLoader());
initialize(null);
}

View File

@@ -0,0 +1,49 @@
:branch: master
=== Google Cloud Functions Sample Application
===== Test locally
Run the function:
----
mvn function:run
----
Invoke the HTTP function:
----
curl http://localhost:8080/ -d "hello"
----
===== Deploy to GCP
As of March 2020, Google Cloud Functions for Java is in Alpha.
You can get on the https://docs.google.com/forms/d/e/1FAIpQLScC98jGi7CfG0n3UYlj7Xad8XScvZC8-BBOg7Pk3uSZx_2cdQ/viewform[whitelist] to try it out.
Package the application.
----
mvn package
----
You should see the fat jar in the `deploy` directory.
Make sure that you have the https://cloud.google.com/sdk/install[Cloud SDK CLI] installed.
Run the following command from the project root to deploy.
----
gcloud alpha functions deploy function-sample-gcp \
--entry-point org.springframework.cloud.function.adapter.gcloud.FunctionInvoker \
--runtime java11 \
--trigger-http \
--source deploy \
--memory 512MB
----
Invoke the HTTP function:
----
curl https://REGION-PROJECT_ID.cloudfunctions.net/function-sample-gcp -d "hello"
----

View File

@@ -27,7 +27,7 @@
<artifactId>function-maven-plugin</artifactId>
<version>0.9.1</version>
<configuration>
<functionTarget>org.springframework.cloud.function.adapter.gcloud.GcfSpringBootHttpRequestHandler</functionTarget>
<functionTarget>org.springframework.cloud.function.adapter.gcloud.FunctionInvoker</functionTarget>
<port>8080</port>
</configuration>
</plugin>