Coder Social home page Coder Social logo

firebase-appengine-backend's Introduction

status: inactive

This project is no longer actively developed or maintained.

For new work on this check out Firebase Hosting for Cloud Run.

Build a mobile app using Firebase and App Engine flexible environment

Kokoro Build Status

This repository contains Android client sample code for the Build a Mobile App Using Firebase and App Engine Flexible Environment solution. You can find the sample code for the Android client code in the firebase-android-client repository.

Deployment requirements

Note: Firebase is a Google product, independent from Google Cloud Platform.

A Java application deployed to App Engine Flexible Environment needs to use Java 8 Runtime. However, in your local development environment you can use JDK 8 or newer as long as your JDK is able to produce Java 8 class files.

Google Cloud SDK setup

Configure the SDK to access the Google Cloud Platform by using the following command:

gcloud auth login

Get the project ID from the settings page of your Firebase project. Use the following command to set your Firebase project as the active project for the SDK:

gcloud config set project [project-id]

Configuration

Enable the Google sign-in provider by following these steps:

  1. Sign in to the Firebase console and select your project.
  2. In the Develop section, select Authentication.
  3. In the Authentication page, select Sign-in Method.
  4. Select and enable the Google sign-in provider.

Follow these steps to configure a service account for the backend application:

  1. Go to your project settings page on the Firebase console.

  2. Click the Settings gear next to 'Project Overview' and then Project settings.

  3. Select Service accounts and click the link Manage service account permissions.

  4. In the IAM & admin page click Create service account.

  5. In the dialog, create an account with the following parameters:

    • Enter playchat-servlet in the Service account name field.
    • Select Project > Owner in the Role menu.

    Caution: The owner role gives the service account full access to all resources in the project. In a production app, you should change the role to the minimum access that your service account requires.

  6. After the service account is created, click it and choose Create new key in the ADD KEY dropdown button.

    • Choose JSON as the key type.
    • Click CREATE to download the key.
  7. After you finish creating the account, your browser downloads the service account's private key to your computer as a JSON file. Move the file to the src/main/webapp/WEB-INF folder in the backend project.

  8. From the left menu of the Firebase console, select Database in the Develop group.

  9. In the Database page, click Create database in the Realtime Database section.

  10. In the Security rules for Realtime Database dialog, select Start in test mode and click Enable.

    Caution: Test mode allows anyone with your database reference to perform read and write operations to your database. If test mode isn't appropriate for your purposes, you can write security rules to manage access to your data. For more information, see Get Started with Database Rules in the Firebase documentation.

    This step displays the data you’ve stored in Firebase. In later steps of this tutorial, you can revisit this web page to see data added and updated by the client app and backend servlet.

  11. In the Rules tab of the database, make sure you have the security rules for read/write. For example:

    {
      "rules": {
        ".read": true,
        ".write": true
      }
    }
  12. Make a note of the Firebase URL for your project, which is in the form https://[project-id].firebaseio.com/ and appears next to a link icon.

  13. Open the src/main/webapp/WEB-INF/web.xml file and do the following:

    • Replace the JSON_FILE_NAME placeholder with the JSON file from that stores the service account's private key.
    • Replace the FIREBASE_URL placeholder with the URL of the Realtime Database from the previous step.

    The following example shows the placeholders in the web.xml file:

    <init-param>
      <param-name>credential</param-name>
      <param-value>/WEB-INF/JSON_FILE_NAME</param-value>
    </init-param>
    <init-param>
      <param-name>databaseUrl</param-name>
      <param-value>FIREBASE_URL</param-value>
    </init-param>

Build and deploy

To build and run the backend module locally:

mvn clean package appengine:run

To deploy the backend module to App Engine:

mvn clean package appengine:deploy

View user event logs

Run the Android client app, perform some activities such as signing in and switching channels, and go to the following URL to view user event logs:

https://[project-id].appspot.com/printLogs

License

Copyright 2018 Google LLC. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This is not an official Google product.

firebase-appengine-backend's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

firebase-appengine-backend's Issues

GCLOUD: WARNING: 503 Service Unavailable Retrying...

Hi,

I'm following this guide and feel I have done everything (three times over) as it suggests:
https://cloud.google.com/solutions/mobile/mobile-firebase-app-engine-flexible#before-you-begin
However when running the backend I do not get a connection at the localhost, and receive the error:

GCLOUD: WARNING: Start request to /_ah/start on server 2.default failed (HTTP status=HTTP/1.1 503 Service Unavailable). Retrying...

I attach an entire printout of such a run and any help is appreciated.

INFO: submitting command: C:\Program Files (x86)\Java\jdk1.8.0_251\jre\bin\java.exe -Duse_jetty9_runtime=true -D--enable_all_permissions=true -Dappengine.sdk.root=C:\Users\Rhodr\AppData\Local\google\ct4j-cloud-sdk\LATEST\google-cloud-sdk\platform\google_appengine\google\appengine\tools\java -cp C:\Users\Rhodr\AppData\Local\google\ct4j-cloud-sdk\LATEST\google-cloud-sdk\platform\google_appengine\google\appengine\tools\java\lib\appengine-tools-api.jar com.google.appengine.tools.development.DevAppServerMain --allow_remote_shutdown --disable_update_check --no_java_agent C:\Users\Rhodr\firebase-appengine-backend\target\backend
OutNow.txt

Finally Got the Guide working. (Windows 10)

There appears, to run locally you are required to install 'Python 2.7' (NOT 3.5.2).

Or at least change your system variables so the 'python' CMD is a recognised command.

Without both installed I would get 'python' not recongised command error.

With 3.5.2 installed, it appears the execfile was removed.

http://stackoverflow.com/questions/6357361/alternative-to-execfile-in-python-3


I would advise someone to run through this guide on a cleanly built version of Windows 10 (With nothing installed) and see how much of a headache to get this Tutorial working is.

Error running local server: GCLOUD: agent library failed to init:instrument

To run the sample in the local service:

mvn clean package appengine:run

The command fails with the following message:

May 23, 2019 12:22:18 PM com.google.cloud.tools.appengine.cloudsdk.CloudSdk logCommand
INFO: submitting command: /usr/local/buildtools/java/jdk8-google-v7-64/jre/bin/java -javaagent:/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/lib/agent/appengine-agent.jar -Dappengine.sdk.root=/usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java -cp /usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/lib/appengine-tools-api.jar com.google.appengine.tools.development.DevAppServerMain --allow_remote_shutdown --disable_update_check ~/firebase-appengine-backend/target/backend
[INFO] GCLOUD: Error opening zip file or JAR manifest missing : /usr/lib/google-cloud-sdk/platform/google_appengine/google/appengine/tools/java/lib/agent/appengine-agent.jar
[INFO] GCLOUD: Error occurred during initialization of VM
[INFO] GCLOUD: agent library failed to init: instrument

gcloud version: 247.0.0
app-engine-java version: 1.9.74

The 'Sign Out' button in the ClientApp produces an error

The app just crashes, without signing out:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.cloud.solutions.flexenv, PID: 3437
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.firebase.database.DatabaseReference.removeEventListener(com.google.firebase.database.ChildEventListener)' on a null object reference
at com.google.cloud.solutions.flexenv.PlayActivity$4.onResult(PlayActivity.java:243)
at com.google.cloud.solutions.flexenv.PlayActivity$4.onResult(PlayActivity.java:240)
at com.google.android.gms.internal.zznv$zza.zzb(Unknown Source)
at com.google.android.gms.internal.zznv$zza.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

project uses deprecated Managed VMs beta environment

This project is referenced in guide : https://cloud.google.com/solutions/mobile/mobile-firebase-app-engine-flexible, but is using a deprecated Managed VMs beta environment.

Google sends out E-Mails like this to Firebase users who use this project as a basis. Means it will not work anymore at all on dec 15 2017?

"This is a reminder that the Managed VMs beta environment (App Engine applications deployed with vm: true in their app.yaml) is deprecated and will be turned down on December 15, 2017. The App Engine flexible environment is replacing Managed VMs, which we are no longer updating."

...

"Action required: Please visit the upgrade guide, and learn more about how to move from the vm: true environment to the env: flex environment. The following projects have active App Engine Managed VM versions currently running, and those versions will be stopped on December 15, 2017:"

Since no app.yaml is in use here (appengine.xml) and the google migration guide https://cloud.google.com/appengine/docs/flexible/java/upgrading does not reference Firebase at all, it would be fantastic if this project, or the documentation could be updated as well...
Thanks!

java.io.FileNotFoundException: WEB-INF/logging.properties (No such file or directory)

I tried to deploy this project on google app engine but couldn't get it work. I've set up the firebase project, acquired service account, enabled the billing on google app engine, and set the project with gcloud command. The error reads:

[INFO] Updating service [default] (this may take several minutes)...
[INFO] .................................................................................................................................................................failed.
[INFO] ERROR: (gcloud.app.deploy) Error Response: [9]
[INFO] Application startup error:
[INFO] Info: Limiting Java heap size to: 400M
[INFO] 2018-01-13 00:11:30.918:INFO::main: Logging initialized @523ms
[INFO] 2018-01-13 00:11:32.641:INFO:oejs.Server:main: jetty-9.3.5.v20151012
[INFO] 2018-01-13 00:11:33.029:INFO:oejs.AbstractNCSARequestLog:main: Opened /var/log/app_engine/request.2018_01_13.log
[INFO] Jan 13, 2018 12:11:34 AM com.google.apphosting.vmruntime.VmMetadataCache getMetadata
[INFO] INFO: Meta-data 'attributes/gae_affinity' path retrieval error: http://metadata/computeMetadata/v1/instance/attributes/gae_affinity
[INFO] Jan 13, 2018 12:11:34 AM com.google.apphosting.vmruntime.VmMetadataCache getMetadata
[INFO] INFO: Meta-data 'attributes/gae_appengine_hostname' path retrieval error: http://metadata/computeMetadata/v1/instance/attributes/gae_appengine_hostname
[INFO] Warning: caught exception when reading logging properties.
[INFO] java.io.FileNotFoundException: WEB-INF/logging.properties (No such file or directory)
[INFO]
[ERROR] Error: gcloud app command with exit code : 1
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:05 min
[INFO] Finished at: 2018-01-12T19:12:10-05:00
[INFO] Final Memory: 25M/83M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.google.appengine:gcloud-maven-plugin:2.0.9.121.v20160815:deploy (default-cli) on project backend: Error: gcloud app command exit code is: 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Could someone please help me? Is this because I used the database on Firebase of my other project? I've spent days on this and really hope I can get this example rolling to use google app engine for my own app. Any reply would be greatly appreciated!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.