Reputation: 2257
I have a react web application using firebase backend. I currently have 2 projects, one for testing and one for production. I use 2 different branches and deploy them manually using the firebase CLI. I want to scale the production site and have 10+ spin offs. I would like to have a different firebase project for each site using its own database/functions.
What is the best approach to do so? Can I use custom .env. files, one for each project, to store the project configurations?
How can I deploy to multiple projects using a single command like "firebase deploy production" which deploys a build using the right environment configuration to each project.
Upvotes: 1
Views: 1118
Reputation: 2257
I came up with the following approach:
1.Create a firebase project for each spin-of (having its own hosting url and db)
2.Replace the firebase config variables like projectId and api-key with env variables:
const projectId = process.env.REACT_APP_FIREBASE_PROJECT_ID;
const apiKey = process.env.REACT_APP_FIREBASE_API_KEY;
const config = {
apiKey,
projectId,
authDomain: `${projectId}.firebaseapp.com`,
databaseURL: `https://${projectId}.firebaseio.com`,
storageBucket: `${projectId}.appspot.com`,
};
firebase.initializeApp(config);
3.set the env variables independently for each project for the build and deploy it while specifying the project using the option -P
REACT_APP_FIREBASE_PROJECT_ID=<projectId> REACT_APP_FIREBASE_API_KEY=<key> yarn build && firebase deploy --only hosting -P <projectId>
4.execute the cmd for each project (probably possible to put them all in one script to be able to deploy to all projects with a single command)
Upvotes: 2