The problem
I have configured a project that currently is possible to deploy to Firebase Hosting multi sites by using the Firebase CLI.
The problem is that currently I am doing this manually. And I want to programatically do this, and if possible, using NodeJS.
The steps of my system:
User uploads a .zip file with a index.html
I extract and check the .zip file with NodeJS
I deploy the files to Firebase Hosting
Currently I am doing like this:
First create the site page with, where game-project-id-unique should be unique:
firebase hosting:sites:create game-project-id-unique
Then, add the target/project ID linked to the game, where game-id is defined by us:
firebase target:apply hosting game-id game-project-id-unique
Add to the firebase.json the configuration of the file (array):
{
"target": "game-id",
"public": "games/game-id",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
}
Then, to publish:
firebase deploy --only hosting
Possible solutions?
I have researched here, I have found out that is possible to use the API-DEPLOY or the CLOUD BUILD, but this is not enough to guide me into the programatically approach, without the need of a human in-between.
Is there a way of doing this? Is it even possible?
You can certainly just write a script that invokes the CLI. This is very common.
You can also use the Firebase Hosting REST API, but in my opinion that is going to be a lot more work.
Related
I have two projects for dev and prod. I want to be able to run a script to copy dev config to prod.
Firebase Remote Config has an API for programatically updating Remote Config. But as far as I can tell, you need to init admin with a project-specific service account. It seems like I would need two admin instances, but I'm not sure that's possible?
I'm wondering if someone has done this before and has an example script. Thanks!
See docs:
https://firebase.google.com/docs/remote-config/automate-rc
There is no Firebase Admin SDK for Flutter, so you'll have to implement this on a different platform that is supported. For a list of these platforms and instructions on setting it up, see the documentation on adding Firebase to a server.
For these platforms that the Firebase Admin SDK targets, you can create multiple instances of the FirebaseApp class, and initialize each of them with different credentials and project configuration. For examples of how to do this, see the documentation on initializing multiple apps.
I have a single page application which I want to host in different gcp projects, i.e. different firebase projects.
The deployment should be done continuously to my firebase hosting, I want to seperate Continuous Build and Continuous Deployment steps and therefore I don't want to deploy from my local machine to all my firebase projects manually.
My question is:
Is there any best practice around for deploying to a firebase hosting project when I don't want to deploy from my local machine?
In my naive way, I am going to setup the following:
I need to build a zip file that contains all the static html and js files plus my firebase.json and .firebaserc file which I upload to my storage bucket.
With those files the firebase CLI tool is able to execute firebase deploy --only hosting:mytarget. A google cloud builder could run this command on a git push (from github.com for example) that knows about all my gcp projects I want to deploy the single page app to...
However this is a lot of work and maybe there is a nicer solution for this.
I tried to put a gs:// link directly to the firebase.json hosting/public section, however firebase CLI does not recognize this (it needs a local folder) :-(
{
"hosting": [
{
"target": "mySPAApp",
"public" : "gs://mystorage-containing-files-for-hosting/",
"rewrites": [
{
"source": "apps/myapp/**",
"destination": "myapp/index.html"
}]
}
]
}
My guts feelings say that there must be an easier way, maybe even with gcloud CLI that just deploys a bunch of files to firebase hosting.
Internally in firebase the functionality should be implemented similarly to this, because in the firebase console the user can simply rollback to a previous version of the hosted application, however there seems to be no documentation about this.
Ok, I found out that there is an official REST API for firebase hosting which is a bit cumbersome to use.
https://firebase.google.com/docs/hosting/reference/rest/v1beta1/sites.versions/create
The format of the configuration is different to what is provided normally in firestore.json and the files needed to be uploaded in a state-machine manner in a Version before a Release is created.
Still, not a solution to opt for in my opinion.
I've been trying to deploy a React CRUD web-app on firebase however I get "Firebase Hosting Setup Complete" screen whenever I deploy. I have followed documents and after I "firebase init" I choose "Firestore" and "Hosting" from CLI menu and setup the public directory as "build" and didn't make any other changes on initialization but I keep getting Firebase Hosting Page.
I don't know why it's not working. I have followed every step on documents. Is there any other way to host my app on Firebase?
Were there any error messages with firebase deploy? Try to deploy a html file and check whether it works.
Also make sure to check using a private window.
Was recently added to a new firebase project via the web interface but it isn't showing up in firebase list. I can see the project in my firebase console. I've tried restarting my terminal, logging out/in, and doing firebase use, but no avail.
Any ideas?
Thanks.
firebase-init first asks which features you wish to use, e.g. database, firestore, storage, etc.
If you choose firestore but have not yet enabled Firestore in your newly created Firebase project via firebase.google.com website, that project will not show up as a project option.
So, before running firebase-cli, enable all the features you want via the website first, ...before chosing those features in step 1 of firebase init.
Once you've enabled Firestore, for example, your project will now show up.
There is now a --project option you can use with firebase init to choose the project.
firebase init --project <projectId>
You can select your project if you know the project id:
firebase use --add
That will select the project, so when you type "firebase init" will not show the select project option but take you to the next step
After 24 hrs, the project finally showed up in my list. Turns out there's just an extremely long delay if you're not the owner of the project.
While following the firebase init steps, use the [don't setup a default project] option.
Then use firebase use --add projectId to add the project.
So recently I changed my password, and was still logged into my firebase account, I did firebase logout and then tried firebase login again, and this time the firebase use --add command worked
In case this helps anyone else: a firebase project is just a firebase-enabled Google Cloud Platform project.
You can create a GCP project but it won't appear in the firebase CLI until you visit console.firebase.google.com and enable firebase for your GCP project of choice.
Then
firebase use --add your_google_cloud_platform_project_id
Should detect your project.
When firebase init asks you to choose a project from the list just check [don't setup a default project] and after the installation you can manually add the project to the .firebaserc file as shown below.
{
"projects": {
"default": "your-project-id"
}
}
You can check the id's of your projects with the command firebase list.
It'll also show the current project.
The below solution worked for me.
Get the Project Id from firebase console. e.g. myproject-2233
On Firebase CLI run below command
$ firebase -P myproject-2233
Next Select the features you want to add e.g. Web Hosting
Next Select "Don't Setup a default project"
Give the public folder name
It worked only after choosing "Don't Setup a default project"
So I’m testing out the CLI today and firebase init with db/hosting selected, and choosing to create a new project, always says Error: Permission denied..
sudo firebase init didn’t help.
firebase-tools version 3.0.3 on OS X 10.11.5.
firebase init
You're about to initialize a Firebase project in this directory:
/Users/splaktar/Git/tmp
Before we get started, keep in mind:
* You are initializing in an existing Firebase project directory
? What Firebase CLI features do you want to setup for this folder? Database: Deploy Firebase Realtime Database Rules
=== Project Setup
First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.
? What Firebase project do you want to associate as default? [don't setup a default project]
=== Database Setup
Firebase Realtime Database Rules allow you to define how your data should be
structured and when your data can be read from and written to.
? What file should be used for Database Rules? database.rules.json
Error: Permission denied.
I've tried the answers here but they did not help. Is this just a bug in the firebase-tools?
I have the same issue and this is how I fixed it.
run firebase init
Deselect ❯◯ Database: Deploy Firebase Realtime Database Rules
Go through other steps to setup the initial app, selecting the default for each should work just fine.
run firebase serve
Hope that helps.
Sometimes it could happen when .firebaserc file exists.
Remove .firebaserc file and reattempt firebase init.
I was with the same problem, but I was not accessing the right account.
After accessed the right account, I created a new project and run "firebase list" (before this not happened) and my new project was there.
This solved my problem.
You need to have Owner or Editor IAM permission on the GCP project to use firebase init command.
The firebase init command initializes/enables the project to use Cloud Functions/Hosting etc for Firebase. Owners/Editors have higher permissions that allow APIs to be enabled etc.
it is a first-time task when you starting the development, and then init command can be avoided if you have set up your cloud functions code in VCS for multiple developers or you.
i.e, Usually after writing code, you will replicate the project to other developers, who will then also write code and use firebase use yourprojectid further.