From 831bf89f4eab46f59e359792f17745e1663a4135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mathieu?= Date: Tue, 23 Aug 2022 12:24:21 +0200 Subject: [PATCH] Google Cloud Functions documentation improvements --- build-parent/pom.xml | 3 ++ docs/pom.xml | 1 + .../main/asciidoc/funqy-gcp-functions.adoc | 20 +++++------ .../src/main/asciidoc/gcp-functions-http.adoc | 12 +++---- docs/src/main/asciidoc/gcp-functions.adoc | 34 ++++++++----------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/build-parent/pom.xml b/build-parent/pom.xml index f47dad17b27ca..b7d6d2983f433 100644 --- a/build-parent/pom.xml +++ b/build-parent/pom.xml @@ -171,6 +171,9 @@ 1.7.0 + + + 1.1.1 diff --git a/docs/pom.xml b/docs/pom.xml index a22583d71d58d..35eb9777b93e8 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -2882,6 +2882,7 @@ ${grpc.version} ${protoc.version} ${elasticsearch-server.version} + ${gcf-invoker.version} ${quarkus-home-url} diff --git a/docs/src/main/asciidoc/funqy-gcp-functions.adoc b/docs/src/main/asciidoc/funqy-gcp-functions.adoc index e2764e3115688..c452d813ee7b0 100644 --- a/docs/src/main/asciidoc/funqy-gcp-functions.adoc +++ b/docs/src/main/asciidoc/funqy-gcp-functions.adoc @@ -78,7 +78,7 @@ In this example, we will create two background functions and a cloud events func Background functions allow you to react to Google Cloud events like PubSub messages, Cloud Storage events, Firestore events, ... Cloud events functions allow you to react to supported events using the Cloud Events specification. -NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must use `gcloud beta` command and add the `--gen2` parameter. +NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must add the `--gen2` parameter. [source,java] ---- @@ -248,7 +248,7 @@ Then, use this command to deploy to Google Cloud Functions: [source,bash] ---- -gcloud beta functions deploy quarkus-example-cloud-event --gen2 \ +gcloud functions deploy quarkus-example-cloud-event --gen2 \ --entry-point=io.quarkus.funqy.gcp.functions.FunqyCloudEventsFunction \ --runtime=java11 --trigger-bucket=example-cloud-event --source=target/deployment ---- @@ -274,10 +274,10 @@ The easiest way to locally test your function is using the Cloud Function invoke You can download it via Maven using the following command: -[source,bash] +[source,bash,subs="attributes"] ---- mvn dependency:copy \ - -Dartifact='com.google.cloud.functions.invoker:java-function-invoker:1.1.0' \ + -Dartifact='com.google.cloud.functions.invoker:java-function-invoker:{gcf-invoker-version}' \ -DoutputDirectory=. ---- @@ -291,9 +291,9 @@ Then you can use it to launch your function locally, again, the command depends For background functions, you launch the invoker with a target class of `io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction`. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/funqy-google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction ---- @@ -313,9 +313,9 @@ This will call your PubSub background function with a PubSubMessage `{"data":"he For background functions, you launch the invoker with a target class of `io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction`. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/funqy-google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction ---- @@ -337,9 +337,9 @@ WARNING: Cloud Events Function is a feature of Cloud Functions gen 2 only. For cloud events functions, you launch the invoker with a target class of `io.quarkus.funqy.gcp.functions.FunqyCloudEventsFunction``. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/funqy-google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.funqy.gcp.functions.FunqyBackgroundFunction ---- diff --git a/docs/src/main/asciidoc/gcp-functions-http.adoc b/docs/src/main/asciidoc/gcp-functions-http.adoc index 840e477a69e2f..ee3595b18a10a 100644 --- a/docs/src/main/asciidoc/gcp-functions-http.adoc +++ b/docs/src/main/asciidoc/gcp-functions-http.adoc @@ -65,7 +65,7 @@ For real life applications, you should choose one of this technology and stick t If you don't need endpoints of each type, you can remove the corresponding extensions from your `pom.xml`. -NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must use `gcloud beta` command and add the `--gen2` parameter. +NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must and add the `--gen2` parameter. === The JAX-RS endpoint @@ -163,7 +163,7 @@ Then you will be able to use `gcloud` to deploy your function to Google Cloud. ---- gcloud functions deploy quarkus-example-http \ --entry-point=io.quarkus.gcp.functions.http.QuarkusHttpFunction \ - --runtime=java11 --trigger-http --source=target/deployment + --runtime=java11 --trigger-http --allow-unauthenticated --source=target/deployment ---- [IMPORTANT] @@ -202,10 +202,10 @@ The easiest way to locally test your function is using the Cloud Function invoke You can download it via Maven using the following command: -[source,bash] +[source,bash,subs="attributes"] ---- mvn dependency:copy \ - -Dartifact='com.google.cloud.functions.invoker:java-function-invoker:1.1.0' \ + -Dartifact='com.google.cloud.functions.invoker:java-function-invoker:{gcf-invoker-version}' \ -DoutputDirectory=. ---- @@ -213,9 +213,9 @@ Before using the invoker, you first need to build your function via `mvn package Then you can use it to launch your function locally. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/deployment/google-cloud-functions-http-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.gcp.functions.http.QuarkusHttpFunction ---- diff --git a/docs/src/main/asciidoc/gcp-functions.adoc b/docs/src/main/asciidoc/gcp-functions.adoc index e82883fdd1639..2b0142064d9af 100644 --- a/docs/src/main/asciidoc/gcp-functions.adoc +++ b/docs/src/main/asciidoc/gcp-functions.adoc @@ -41,8 +41,6 @@ You can use the following Maven command to create it: :create-app-extensions: google-cloud-functions include::{includes}/devtools/create-app.adoc[] -Now, let's remove the `index.html` from `resources/META-INF/resources` or it will be picked up instead of your Function. - == Login to Google Cloud Login to Google Cloud is necessary for deploying the application. It can be done as follows: @@ -57,7 +55,7 @@ gcloud auth login For this example project, we will create four functions, one `HttpFunction`, one `BackgroundFunction` (Storage event), one `RawBackgroundFunction` (PubSub event) and one `CloudEventsFunction` (storage event using the Cloud Events specification). -NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must use `gcloud beta` command and add the `--gen2` parameter. +NOTE: Quarkus supports Cloud Functions gen 1 and gen 2. For an overview of Cloud Functions gen 2 see https://cloud.google.com/functions/docs/2nd-gen/overview[this page] on the Google Cloud Functions documentation. To use gen 2 you must add the `--gen2` parameter. == Choose Your Function @@ -94,10 +92,6 @@ public class TestHttpFunction implements HttpFunction { [source,java] ---- -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; import java.io.Writer; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; @@ -179,7 +173,7 @@ import io.quarkus.gcp.function.test.service.GreetingService; @Named("rawPubSubTest") // <1> @ApplicationScoped // <2> public class RawBackgroundFunctionPubSubTest implements RawBackgroundFunction { // <3> -@Inject GreetingService greetingService; // <4> + @Inject GreetingService greetingService; // <4> @Override public void accept(String event, Context context) throws Exception { // <5> @@ -262,7 +256,7 @@ This is an example command to deploy your `HttpFunction` to Google Cloud: ---- gcloud functions deploy quarkus-example-http \ --entry-point=io.quarkus.gcp.functions.QuarkusHttpFunction \ - --runtime=java11 --trigger-http --source=target/deployment + --runtime=java11 --trigger-http --allow-unauthenticated --source=target/deployment ---- [IMPORTANT] @@ -354,7 +348,7 @@ it needs to use `--trigger-bucket` parameter with the name of a previously creat [source,bash] ---- -gcloud beta functions deploy quarkus-example-cloud-event --gen2 \ +gcloud functions deploy quarkus-example-cloud-event --gen2 \ --entry-point=io.quarkus.gcp.functions.QuarkusCloudEventsFunction \ --runtime=java11 --trigger-bucket=example-cloud-event --source=target/deployment ---- @@ -377,10 +371,10 @@ The easiest way to locally test your function is using the Cloud Function invoke You can download it via Maven using the following command: -[source,bash] +[source,bash,subs="attributes"] ---- mvn dependency:copy \ - -Dartifact='com.google.cloud.functions.invoker:java-function-invoker:1.1.0' \ + -Dartifact='com.google.cloud.functions.invoker:java-function-invoker:{gcf-invoker-version}' \ -DoutputDirectory=. ---- @@ -392,9 +386,9 @@ include::{includes}/devtools/build.adoc[] To test an `HttpFunction`, you can use this command to launch your function locally. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.gcp.functions.QuarkusHttpFunction ---- @@ -407,9 +401,9 @@ Your endpoints will be available on http://localhost:8080. For background functions, you launch the invoker with a target class of `io.quarkus.gcp.functions.BackgroundFunction`. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.gcp.functions.QuarkusBackgroundFunction ---- @@ -429,9 +423,9 @@ This will call your Storage background function with an event `{"name":"hello.tx For background functions, you launch the invoker with a target class of `io.quarkus.gcp.functions.BackgroundFunction`. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.gcp.functions.QuarkusBackgroundFunction ---- @@ -453,9 +447,9 @@ IMPORTANT: `CloudEventsFunction` is a feature of Cloud Function gen 2 only. For cloud events functions, you launch the invoker with a target class of `io.quarkus.gcp.functions.QuarkusCloudEventsFunction`. -[source,bash] +[source,bash,subs="attributes"] ---- -java -jar java-function-invoker-1.1.0.jar \ +java -jar java-function-invoker-{gcf-invoker-version}.jar \ --classpath target/google-cloud-functions-1.0.0-SNAPSHOT-runner.jar \ --target io.quarkus.gcp.functions.QuarkusCloudEventsFunction ----