Merge pull request #479 from meltsufin/gcp-sample-doc
Adds Readme to GCP sample app
This commit is contained in:
@@ -130,3 +130,7 @@ Invoke the HTTP function:
|
|||||||
----
|
----
|
||||||
curl https://REGION-PROJECT_ID.cloudfunctions.net/function-sample-gcp -d "hello"
|
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.
|
||||||
|
|||||||
3
docs/src/main/asciidoc/adapters/gcp.adoc
Normal file
3
docs/src/main/asciidoc/adapters/gcp.adoc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
*{spring-cloud-function-version}*
|
||||||
|
|
||||||
|
include::adapters/gcp-intro.adoc[]
|
||||||
@@ -11,6 +11,7 @@ The reference documentation consists of the following sections:
|
|||||||
<<spring-cloud-function.adoc#,Reference Guide>> :: Spring Cloud Function Reference
|
<<spring-cloud-function.adoc#,Reference Guide>> :: Spring Cloud Function Reference
|
||||||
<<aws.adoc#,AWS Adapter>> :: AWS Adapter Reference
|
<<aws.adoc#,AWS Adapter>> :: AWS Adapter Reference
|
||||||
<<azure.adoc#, Azure Adapter>> :: Azure 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
|
<<openwhisk.adoc#, Apache OpenWhisk Adapter>> :: Apache OpenWhisk Adapter Reference
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -585,4 +585,5 @@ Invoker] acts natively is an adapter for Spring Cloud Function jars.
|
|||||||
|
|
||||||
include::adapters/aws-intro.adoc[]
|
include::adapters/aws-intro.adoc[]
|
||||||
include::adapters/azure-intro.adoc[]
|
include::adapters/azure-intro.adoc[]
|
||||||
|
include::adapters/gcp-intro.adoc[]
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,15 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<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>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.cloud.functions</groupId>
|
<groupId>com.google.cloud.functions</groupId>
|
||||||
<artifactId>functions-framework-api</artifactId>
|
<artifactId>functions-framework-api</artifactId>
|
||||||
<version>${google.cloud.functions.version}</version>
|
<version>${google.cloud.functions.api.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -44,7 +45,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.cloud.functions.invoker</groupId>
|
<groupId>com.google.cloud.functions.invoker</groupId>
|
||||||
<artifactId>java-function-invoker</artifactId>
|
<artifactId>java-function-invoker</artifactId>
|
||||||
<version>${google.cloud.functions.version}</version>
|
<version>${google.cloud.functions.invoker.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -46,13 +46,18 @@ public class FunctionInvoker
|
|||||||
|
|
||||||
public FunctionInvoker() {
|
public FunctionInvoker() {
|
||||||
super();
|
super();
|
||||||
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionInvoker(Class<?> configurationClass) {
|
public FunctionInvoker(Class<?> configurationClass) {
|
||||||
super(configurationClass);
|
super(configurationClass);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
System.setProperty("spring.http.converters.preferred-json-mapper", "gson");
|
System.setProperty("spring.http.converters.preferred-json-mapper", "gson");
|
||||||
Thread.currentThread() //TODO investigate if it is necessary
|
Thread.currentThread() // TODO: remove after upgrading to 1.0.0-alpha-2-rc5
|
||||||
.setContextClassLoader(FunctionInvoker.class.getClassLoader());
|
.setContextClassLoader(FunctionInvoker.class.getClassLoader());
|
||||||
initialize(null);
|
initialize(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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"
|
||||||
|
----
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<artifactId>function-maven-plugin</artifactId>
|
<artifactId>function-maven-plugin</artifactId>
|
||||||
<version>0.9.1</version>
|
<version>0.9.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<functionTarget>org.springframework.cloud.function.adapter.gcloud.GcfSpringBootHttpRequestHandler</functionTarget>
|
<functionTarget>org.springframework.cloud.function.adapter.gcloud.FunctionInvoker</functionTarget>
|
||||||
<port>8080</port>
|
<port>8080</port>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|||||||
Reference in New Issue
Block a user