DEV Community

Multiple environments with Firebase Hosting

Valentin Prugnaud 🦊 on October 16, 2019

More often than not, a project requires multiple environments to deploy to. What I commonly use on top of my development environment is a staging e...
Collapse
Β 
ryanrousseau profile image
Ryan Rousseau β€’

Nice post!

I started down the path of creating a staging project for one of my apps, but this was right when multiple sites were introduced to hosting and I saw in the docs that's the suggested way of doing this. I think the biggest obstacle I had was getting the database connection right when swapping back and forth between environments. I'll have to go back and see how I did that. I imagine you avoid that completely with this approach.

Collapse
Β 
valentinprgnd profile image
Valentin Prugnaud 🦊 β€’

Thanks! Each environments has it’s own database, storage etc... I use environment variables in my Gitlab pipelines to build the app with the right environment before deploying to Firebase. I have planned another post covering how I use Gitlab to deploy to Firebase, stay tuned!

Collapse
Β 
ryanrousseau profile image
Ryan Rousseau β€’

Nice, I do something similar Gitlab to build and package but Octopus Deploy to deploy. Also got a blog in the making on the second part.

Thread Thread
Β 
valentinprgnd profile image
Valentin Prugnaud 🦊 β€’

Nice! Let me know when your post is ready, I’d love to read it!

Collapse
Β 
messerli90 profile image
Michael Messerli β€’

Really interesting!

When you said "Use two completely different projects" you mean 2 seperate Firebase projects? I recently ran into the project cap (with only 3 active projects) and it wouldn't let me create another one. Google cleared it up quickly and gave me more but now I'm afraid of creating lots of projects now.

Collapse
Β 
valentinprgnd profile image
Valentin Prugnaud 🦊 β€’ β€’ Edited

I usually use the Blaze plan and I never ran into the project limit myself.

An alternative if you are concerned about the project limit, would be to use Deploy Targets within the same project.

Collapse
Β 
messerli90 profile image
Michael Messerli β€’

I think it was a weird thing with my Google account, I had 3 projects total and when I tried to create a new one it told me I have '-4 projects left', 2 of them were on Blaze

Thanks for that link I'll look into that. πŸ‘

Thread Thread
Β 
valentinprgnd profile image
Valentin Prugnaud 🦊 β€’

Strange behaviour indeed. Seems like Firebase has a hidden limit on the number of projects you can create, but no information on what that limit actually is πŸ€”

Collapse
Β 
spock123 profile image
Lars Rye Jeppesen β€’

What if you have multiple sites in each of those projects?

like "admin" and "shop" for example.

No guide on the Internet I've looked at so far has show how to do this.
It's always either 1) one project with multiple sites or 2) 2 projects with one site each.

Collapse
Β 
valentinprgnd profile image
Valentin Prugnaud 🦊 β€’

You can create multiple sites in the same Firebase project, and leverage the Deployment Targets feature. There is more information here: firebase.google.com/docs/hosting/m...

Collapse
Β 
spock123 profile image
Lars Rye Jeppesen β€’

Thank you, yes I got it working.

Multiple projects with multiple apps in each project. It was a bit weird to get working though, but finally managed.

Thanks