Separate dev and prod Firebase environment

2019-01-10 09:05发布

问题:

I am considering using Firebase as MBaaS, however I couldn't find any reliable solution to the following problem:

I would like to set up two separate Firebase environment, one for development and one for production, but I don't want to do manual copy of features (eg. remote configuration setup, notification rules, etc.) between the development and production environment.

Is there any tool or method I can rely on? Setting up remote configuration or notification rules from scratch can be daunting task and too risky.

Any suggestions? Is there a better approach than having two separate environments?

Before you post another answer to the question which explains how to set up separate Firebase accounts: it is not the question, read it again. The question is: how to TRANSFER changes between separate dev and prod accounts or any better solution than manually copy between them.

回答1:

I'm not currently using Firebase, but considering it like yourself. Looks like the way to go is to create a completely separate project on the console. There was a blogpost up recommending this on the old Firebase site, looks to be removed now though. https://web.archive.org/web/20160310115701/https://www.firebase.com/blog/2015-10-29-managing-development-environments.html

Also this discussion recommending same: https://groups.google.com/forum/#!msg/firebase-talk/L7ajIJoHPcA/7dsNUTDlyRYJ



回答2:

If you are using firebase-tools there is a command firebase use which lets you set up which project you are using for firebase deploy

firebase use --add will bring up a list of your projects, select one and it will ask you for an alias. From there you can firebase use alias and firebase deploy will push to that project.

In my personal use, I have my-app and my-app-dev as projects in the Firebase console.



回答3:

This blogpost describes a very simple approach with a debug and release build type.

In a nutshell:

  • Create a new App on Firebase for each build type using different application id suffix.
  • Configure your Android project with the latest JSON file.
  • Using applicationIdSuffix, change the Application Id to match the different Apps on Firebase depending on the build type.

=> see the blogpost for a detailed description.

If you want to use different build flavors, read this extensive blogpost from the official firebase blog. It contains a lot of valuable information.

Hope that helps!



回答4:

You will need to manage different build types

Follow this

  1. First, create a new project at Firebase console, name id as YOURAPPNAME-DEV

  2. Click "Add android app" button and create a new app. Name it com.yourapp.debug, for example. New google-services.json file will be downloaded automatically

  3. Under your project src directory create new directory with name "debug" and copy new google-services.json file here

  4. In your module level build.gradle add this

    debug {
            applicationIdSuffix ".debug"
        }
    

Now when you build a debug build google-services.json from "debug" folder will be used and when you will build in release mode google-services.json from module root directory will be considered.



回答5:

The way I did it:

  1. I had 2 projects on firebase- one for DEV other for PROD
  2. Locally my app also had 2 branches - one named DEV, the other named PROD
  3. In my DEV branch I always have JSON file of DEV firebase project & likewise for PROD

This way I am not required to maintain my JSONs.



回答6:

The way we are doing it is by creating different json key files for different environments. We have used service account feature as recommended by google and have one development file and another for production



回答7:

Firebase has a page on this which goes through how to set it up for dev and prod

https://firebase.google.com/docs/functions/config-env

Set environment configuration for your project To store environment data, you can use the firebase functions:config:set command in the Firebase CLI. Each key can be namespaced using periods to group related configuration together. Keep in mind that only lowercase characters are accepted in keys; uppercase characters are not allowed.

For instance, to store the Client ID and API key for "Some Service", you might run:

firebase functions:config:set someservice.key="THE API KEY" someservice.id="THE CLIENT ID"

Retrieve current environment configuration To inspect what's currently stored in environment config for your project, you can use firebase functions:config:get. It will output JSON something like this:

{
  "someservice": {
    "key":"THE API KEY",
    "id":"THE CLIENT ID"
  }
}


标签: firebase