This is connected to https://github.com/firebase/firebase-tools/issues/560
I followed @justinrosenthal 's instructions, but I don't understand how I can have multiple projects in firebase.json.
My configuration is as follows:
.firebaserc:
{
"projects": {
"dev": "project-dev",
"prod": "project-prod"
},
"targets": {
"project-prod": {
"database": {
"main": [
"prod-db-01",
"prod-db-02",
"prod-db-03",
"prod-db-04"
]
}
},
"project-dev": {
"database": {
"main": [
"dev-db-01",
"dev-db-02"
]
}
}
}
}
And firebase.json:
{
"database": [
{ "target" : "main", "rules": "database.rules.json" }
]
}
I want to have different rules for all databases in project-dev and all databases in project-prod. Something like this:
{
"database": [
{ "target" : "main", "project" : "project-dev", "rules": "dev-database.rules.json" },
{ "target" : "main", "project" : "project-prod", "rules": "prod-database.rules.json" }
]
}
Basically I want to do this:
# firebase use dev
# firebase deploy --only database # uploads dev-database.rules.json to dev-db-01 and dev-db-02
# firebase use prod
# firebase deploy --only database # uploads prod-database.rules.json to prod-db-01, prod-db-02, prod-db-03 and prod-db-04
Thanks in advance.
Right now the Firebase CLI is built to treat projects as anonymous environments that are functionally identical. This is important to be able to deploy the same assets to multiple projects without having to alter the code (including in firebase.json
).
To achieve what you want, you'll need to set up a dev
and prod
folder, each with their own firebase.json
and each with a target only for that specific project. Deploying different assets to different projects is not supported now and is unlikely to be supported in the future (however, we may allow configuring the location of firebase.json
via a flag at some point).
How about just letting us specify which firebase.json file to use like almost any other tool that uses a config file?
It would solve pretty much every problem we have with firebase atm.
Specifying config file is something I'd like to support in the future.
On Fri, Jul 20, 2018, 3:31 AM Andri Már Sigurðsson notifications@github.com
wrote:
How about just letting us specify which firebase.json file to use like
almost any other tool that uses a config file?It would solve pretty much every problem we have with firebase atm.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/590#issuecomment-406560971,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAD_uVyVgg86foP59VHY_pPI3F4E2nZks5uIbFmgaJpZM4RUdVX
.
is it the future yet?
This is really an issue for me as well. The workaround with different folders seems like a dirty hack. Please provide the CLI argument to specify a path to the firebase.json
file to use.
It is this in progress?
It is really needed on Monorepos
I struggled on this for almost 2 hours now. Tried all sorts of firebase configurations (2 sites, separate projects/ 2 sites, single project). I basically want a landing page hosted on both a production and staging environment, but configuring the .firebaserc
and firebase.json
files is pretty confusing, given the target/alias naming (which _you_ define).
This makes me wonder under what possible use cases can shared resources across multiple sites be leveraged if we cannot easily deploy identical apps in different environments/configurations. I may be missing something here.
I realized the issue was having both websites' hosting configs in a single firebase.json
file. as @mbleigh mentioned, one solution is creating a prod and dev folder, each with a separate firebase.json
. Personally, I prefer just swapping my firebase.json
files in my npm deploy scripts in package.json
// package.json
"deploy": "npm run swap-prod && ng build --aot --prod && firebase use production && firebase deploy",
"deploy-staging": "npm run swap-staging && ng build --configuration=staging && firebase use staging && firebase deploy",
"swap-prod": "cp prod.firebase.json firebase.json",
"swap-staging": "cp staging.firebase.json firebase.json",
Note, you can swap these files in angular.json
's fileReplacements
array, since firebase.json
is not in your src directory (at least I don't have it that way).
create a prod.firebase.json
and a staging.firebase.json
along with your firebase.json
at the root of your project. swap them out in your deploy commands in package.json
.
project here -> https://github.com/superfitapp/superfit-main-landing-site
Deploying multiple sites to a single project and multiple projects seems like such a basic requirement: cdn
/ website
/ app
etc to dev
/ `prod etc. I hope this gets added to the config soon
We support both multiple sites in a single project and multiple projects. This bug is specifically about using different firebase.json
configs for these things, which is not currently supported.
Thanks for clarifying @mbleigh
I hope this gets added to the config
https://github.com/firebase/firebase-tools/issues/590#issuecomment-528557023
Thanks @mbleigh for the quick reply. I managed to do it with cli parameters, but in the firebase.json
would make it cleaner
It's a great project and a big thank you to everyones hard work, I know it is not easy maintaining open source projects 🤓
This is connected to #560
I followed @justinrosenthal 's instructions, but I don't understand how I can have multiple projects in firebase.json.
My configuration is as follows:
.firebaserc:
{ "projects": { "dev": "project-dev", "prod": "project-prod" }, "targets": { "project-prod": { "database": { "main": [ "prod-db-01", "prod-db-02", "prod-db-03", "prod-db-04" ] } }, "project-dev": { "database": { "main": [ "dev-db-01", "dev-db-02" ] } } } }
And firebase.json:
{ "database": [ { "target" : "main", "rules": "database.rules.json" } ] }
I want to have different rules for all databases in project-dev and all databases in project-prod. Something like this:
{ "database": [ { "target" : "main", "project" : "project-dev", "rules": "dev-database.rules.json" }, { "target" : "main", "project" : "project-prod", "rules": "prod-database.rules.json" } ] }
Basically I want to do this:
# firebase use dev # firebase deploy --only database # uploads dev-database.rules.json to dev-db-01 and dev-db-02 # firebase use prod # firebase deploy --only database # uploads prod-database.rules.json to prod-db-01, prod-db-02, prod-db-03 and prod-db-04
Thanks in advance.
Thanks
Ran into a similar problem. I have 3 projects dev, staging and production. I want to deploy different security rules for storage and firestore to different projects. I am thinking of maintaining the following project structure
./
├── README.md
├── firebase.json
├── load_firestore_rules.sh
├── load_storage_rules.sh
├── functions
│ ├── ...
│ ├── ...
│ ├── index.js
│ ├── node_modules
│ ├── package-lock.json
│ ├── package.json
│ └── test
├── rules
│ ├── dev
│ ├── production
│ └── staging
The rules files reside in project dependent rules folders i.e for example rules/dev
for project id project_name-dev.
Modify firebase.json
like so
"firestore": {
// ...
"rules": "firestore.rules",
"predeploy": "./load_firestore_rules.sh $GCLOUD_PROJECT",
"public": "public"
},
"storage": {
"rules": "storage.rules",
"predeploy": "./load_storage_rules.sh $GCLOUD_PROJECT"
}
The load_firestore_rules.sh
bash script looks like so
#!/bin/bash
project_id=$1
if [ project_id == "project_name-dev"]
then
cat ./rules/dev/rules > ./firestore.rules. #overwrite firestore_rules
elif [ project_id == "project_name-staging"]
then
cat ./rules/staging/rules > ./firestore.rules
elif [ project_id == "project_name-production"]
then
cat ./rules/production/rules > ./firestore.rules
else
fi
Finally, this is how it will be used
> cd project_directory
> firebase use project_name-dev
# Following command runs ./load_firestore_rules script which loads project_name-dev's firestore dev rules into firestore.rules, followed by deployment
> firebase deploy --firestore:rules
All of this can go into source control. firestore.rules
and storage.rules
in top-level dir don't need to be part of src control though as they are frequently overwritten
@ziphawkteamusa and others we just released version 8.7.0
which has support for the --config
flag to point at mulitple firebase.json
files.
So for example:
firebase-main.json
{
"firestore" : { "rules": "firestore-main.rules" }
}
firebase-alt.json
{
"firestore" : { "rules": "firestore-alt.rules" }
}
Then you can do:
$ firebase --config=./firebase-main.json deploy
or
$ firebase --config=./firebase-alt.json deploy
@samtstern Is there a way I can specify the configuration file path to be used by different projects in .firebaserc
? Something like:
{
"projects": {
"dev": "project-dev",
"prod": "project-prod"
},
"targets": {
"project-prod": {
"database": {
"main": [
"prod-db-01",
"prod-db-02",
"prod-db-03",
"prod-db-04"
]
},
"config": "<path-to-prod-firebase.json>"
},
"project-dev": {
"database": {
"main": [
"dev-db-01",
"dev-db-02"
]
},
"config": "<path-to-dev-firebase.json>"
}
}
}
@waseem no sorry there's no way to do that. I'd suggest writing your own script to wrap the Firebase CLI to get advanced config switching like that.
Most helpful comment
is it the future yet?