Skip to content

Commit

Permalink
Merge pull request #707 from jfbenckhuijsen/feature/firebase-emulator…
Browse files Browse the repository at this point in the history
…-config-switch

Feature/firebase emulator config switch
  • Loading branch information
loicmathieu authored Dec 24, 2024
2 parents daf7717 + bc2c5a0 commit 83718a8
Show file tree
Hide file tree
Showing 60 changed files with 11,273 additions and 18 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ jobs:
with:
java-version: 17

- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: firebase-devservices/deployment/src/test/functions/package-lock.json

- uses: bahmutov/npm-install@v1
with:
working-directory: firebase-devservices/deployment/src/test/functions

- name: Cache local Maven repository
uses: actions/cache@v2
with:
Expand All @@ -33,8 +43,14 @@ jobs:
${{ runner.os }}-maven-
- name: Build with Maven
run: mvn -B formatter:validate install --file pom.xml
run: |
export CURRENT_USER=$(id -u)
export CURRENT_GROUP=$(id -g)
mvn -B formatter:validate install --file pom.xml
- name: Build in native
run: mvn -B -Pnative package --file integration-tests/main/pom.xml
run: |
export CURRENT_USER=$(id -u)
export CURRENT_GROUP=$(id -g)
mvn -B -Pnative package --file integration-tests/main/pom.xml
16 changes: 16 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<google-cloud-sdk.version>26.50.0</google-cloud-sdk.version>
<firebase-admin-sdk.version>9.4.2</firebase-admin-sdk.version>

<!-- Dependency convergence issues -->
<opencensus.version>0.31.1</opencensus.version><!-- mess in google-pubsub and grpc deps; should be rather stable as OpenCensus has been sunsetted already - see https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/862 -->
Expand All @@ -37,6 +38,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>${firebase-admin-sdk.version}</version>
</dependency>

<!-- Google Cloud Services common libs-->
<dependency>
Expand Down Expand Up @@ -138,6 +144,16 @@
<artifactId>quarkus-google-cloud-firebase-admin-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-devservices</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase-devservices-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firestore</artifactId>
Expand Down
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
** xref:index.adoc#examples[Example applications]
* xref:bigquery.adoc[BigQuery]
* xref:bigtable.adoc[BigTable]
* xref:firebase-devservices.adoc[Firebase Admin]
* xref:firebase-admin.adoc[Firebase Admin]
* xref:firestore.adoc[Firestore]
* xref:logging.adoc[Logging]
Expand Down
146 changes: 146 additions & 0 deletions docs/modules/ROOT/pages/firebase-devservices.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
= Google Cloud Services - Firebase Dev Services

This extension implements DevServices for applications developed on with the Google Firebase platform. The DevService runs the appropriate emulators of the Firebase platform based on your configuration.

Be sure to have read the https://quarkiverse.github.io/quarkiverse-docs/quarkus-google-cloud-services/main/index.html[Google Cloud Services extension pack global documentation] before this one, it contains general configuration and information.

== Current status

The following emulators have been verified to work:

* Firebase Auth
* Firebase Firestore
* Firebase Emulator UI
* Realtime Database
* PubSub
* Cloud Storage
* Firebase Hosting
* Functions

The following emulators are currently not supported:
* EventArc

Currently you can specify a custom `firebase.json` file but suport for this is limited. A
future version will support reading the configuration from the `firebase.json` file
instead of from the Quarkus configuration.

== Bootstrapping the project

First, we need a new project. Create a new project with the following command (replace the version placeholder with the correct one):

[source, shell script]
----
mvn io.quarkus:quarkus-maven-plugin:${quarkusVersion}:create \
-DprojectGroupId=org.acme \
-DprojectArtifactId=firebase-admin-quickstart \
-Dextensions="quarkus-google-cloud-firebase-devservices"
cd firebase-admin-quickstart
----

This command generates a Maven project, importing the Google Cloud Firebase extension.

If you already have your Quarkus project configured, you can add the `quarkus-google-cloud-firebase` extension to your project by running the following command in your project base directory:

[source, shell script]
----
./mvnw quarkus:add-extension -Dextensions="quarkus-google-cloud-firebase"
----

This will add the following to your pom.xml:

[source, xml]
----
<dependency>
<groupId>io.quarkiverse.googlecloudservices</groupId>
<artifactId>quarkus-google-cloud-firebase</artifactId>
</dependency>
----

If you already have a firebase project (which you can create using the firebase tools by running `firebase init`), you need to make the following changes to get going:
* Add `"host" : "0.0.0.0"` to all emulator entries
* Add the hub, logging and UI emulators to the emulators configuration

[source,json]
----
{
"emulators" : {
"ui": {
"port": 4000,
"enabled": true,
"host": "0.0.0.0"
},
"hub": {
"port": 4400,
"host": "0.0.0.0"
},
"logging": {
"port": 4500,
"host": "0.0.0.0"
}
}
}
----
* If you use Firestore, also set the Firestore Websocket port
[source,json]
----
{
"emulators" : {
"firestore": {
"port": 8080,
"websocketPort" : 9150,
"host": "0.0.0.0"
}
}
}
----
* For both entries, you can of course use your own custom ports, where needed.

The extension will try to read the `firebase.json` file from the current working directory the
process was started in (it will not attempt to traverse the directory upwards to try to find the
file). In some cases you may need to specify this working directory. E.g. when using Gradle:

[source,text]
----
quarkusDev {
workingDirectory = rootProject.projectDir
}
----

== Custom Docker image

To run the emulators, a custom Docker image is build on the fly to run the Firebase emulators. This image is based on a NodeJS based image (refer to the configuration of the default value of `quarkus.google.cloud.firebase.devservice.image-name` to see the base image).

You can configure a custom image if needed as base image to run the Firebase Emulators in. This image has the following requirements:

* The image must support NodeJS in a version compatible with the required Firebase Tools
* The image must be `alpine` based (or at least able to install the following packages using `apk`: )
** openjdk17-jre
** bash
** curl
** openssl
** gettext
** nano
** nginx
** sudo

== Custom Firebase JSON

If emulators are configured via the configuration options, a `firebase.json` file is generated inside the image to configure the various emulators. You can configure the Dev Services to use your own custom firebase.json file (e.g generated using the Firebase tools CLI). The following requirements are defined for this file:

* Each of the emulators must be exposed on `0.0.0.0` as host as described https://firebase.google.com/docs/emulator-suite/use_hosting#emulators-no-local-host[here]. If this is not done, the Emulators will not be reachable from the Docker host.
* Emulators need to be configured to use the default ports. Customizing the ports on which they run is currently not supported (this might change in a future version).

== Interaction with other extensions

The following extensions support Dev Services which conflicts with the Dev Services exposed by the Firebase Emulators.

* Firestore
* PubSub
* TODO: Verify Storage

When including this module, these Dev Services will automatically be disabled, as the Firebase emulator should feature wise be on-par or more extensive than the individual emulators.

== Configuration Reference

include::./includes/quarkus-google-cloud-firebase-devservices.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,42 @@ endif::add-copy-button-to-env-var[]
|boolean
|`false`

a| [[quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-emulator-host]] [.property-path]##link:#quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-emulator-host[`quarkus.google.cloud.firebase.auth.emulator-host`]##

[.description]
--
Sets the emulator host to use.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_EMULATOR_HOST+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_EMULATOR_HOST+++`
endif::add-copy-button-to-env-var[]
--
|string
|

a| [[quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-use-emulator-credentials]] [.property-path]##link:#quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-use-emulator-credentials[`quarkus.google.cloud.firebase.auth.use-emulator-credentials`]##

[.description]
--
Forces the usage of emulator credentials. The logic automatically uses emulator credentials in case the emulatorHost is set.

- If true: force usage of emulator credentials
- If false: force not using emulator credentials


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_USE_EMULATOR_CREDENTIALS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_USE_EMULATOR_CREDENTIALS+++`
endif::add-copy-button-to-env-var[]
--
|boolean
|`true`

|===

Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,42 @@ endif::add-copy-button-to-env-var[]
|boolean
|`false`

a| [[quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-emulator-host]] [.property-path]##link:#quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-emulator-host[`quarkus.google.cloud.firebase.auth.emulator-host`]##

[.description]
--
Sets the emulator host to use.


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_EMULATOR_HOST+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_EMULATOR_HOST+++`
endif::add-copy-button-to-env-var[]
--
|string
|

a| [[quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-use-emulator-credentials]] [.property-path]##link:#quarkus-google-cloud-firebase-admin_quarkus-google-cloud-firebase-auth-use-emulator-credentials[`quarkus.google.cloud.firebase.auth.use-emulator-credentials`]##

[.description]
--
Forces the usage of emulator credentials. The logic automatically uses emulator credentials in case the emulatorHost is set.

- If true: force usage of emulator credentials
- If false: force not using emulator credentials


ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_USE_EMULATOR_CREDENTIALS+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_USE_EMULATOR_CREDENTIALS+++`
endif::add-copy-button-to-env-var[]
--
|boolean
|`true`

|===

Loading

0 comments on commit 83718a8

Please sign in to comment.