Skip to content

Commit

Permalink
Merge pull request #27438 from loicmathieu/gcf-doc-improvements
Browse files Browse the repository at this point in the history
Google Cloud Functions documentation improvements
  • Loading branch information
loicmathieu authored Aug 31, 2022
2 parents 0bfed3e + 831bf89 commit 7e0ba16
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 36 deletions.
3 changes: 3 additions & 0 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@

<surefire.argLine.additional></surefire.argLine.additional>
<os-maven-plugin.version>1.7.0</os-maven-plugin.version>

<!-- google cloud functions invoker-->
<gcf-invoker.version>1.1.1</gcf-invoker.version>
</properties>

<dependencyManagement>
Expand Down
1 change: 1 addition & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2882,6 +2882,7 @@
<grpc-version>${grpc.version}</grpc-version>
<protoc-version>${protoc.version}</protoc-version>
<elasticsearch-version>${elasticsearch-server.version}</elasticsearch-version>
<gcf-invoker-version>${gcf-invoker.version}</gcf-invoker-version>

<!-- Project website home page -->
<quarkus-home-url>${quarkus-home-url}</quarkus-home-url>
Expand Down
20 changes: 10 additions & 10 deletions docs/src/main/asciidoc/funqy-gcp-functions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
----
Expand Down Expand Up @@ -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
----
Expand All @@ -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=.
----

Expand All @@ -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
----
Expand All @@ -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
----
Expand All @@ -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
----
Expand Down
12 changes: 6 additions & 6 deletions docs/src/main/asciidoc/gcp-functions-http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -202,20 +202,20 @@ 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=.
----

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
----
Expand Down
34 changes: 14 additions & 20 deletions docs/src/main/asciidoc/gcp-functions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
----
Expand All @@ -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=.
----

Expand All @@ -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
----
Expand All @@ -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
----
Expand All @@ -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
----
Expand All @@ -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
----
Expand Down

0 comments on commit 7e0ba16

Please sign in to comment.