Firebase hosting deploy using service account created from different project - firebase

When I am deploying firebase hosting, even after passing with the project as an argument, it is trying to deploy firebase hosting to the project that the service account was created.
I have the GOOGLE_APPLICATION_CREDENTIALS set. It points to a service account created from another project (Shared service account for deployments), and it has Firebase App distribution admin and all required permissions on the current project.
./node_modules/.bin/firebase deploy --only hosting:$ENVIRONMENT --project ${PROJECT_NAME} --non-interactive
Error: HTTP Error: 403, Firebase Hosting API has not been used in project 49XXYYZZ628 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/firebasehosting.googleapis.com/overview?project=497XXYYZZ628 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
Of course, the project where the service account was created does not have API enabled.
How to force firebase to deploy the project passed with the firebase deployment command?
I have tried before the deploy command
gcloud config set project ${PROJECT_NAME}
firebase use --project ${PROJECT_NAME}
`

The steps I used to resolve the issue when using a service account from another project for firebase hosting deployment - from a clean CI-CD environment.
Enable Firebase API on the project which the service account was created from.
Below are commands to deploy if you have multiple apps with the targets.
firebase use --add  <ProjectID>
firebase target:apply hosting <TargetName> <TargetHostingName>
firebase deploy --only hosting:<TargetName>

Related

Create Firebase "multiple websites" via CLI

I'm looking for a CLI command to automate the creation of multiple websites:
It looks like there is CLI hosting support but this is limited to "preview channels":
hosting:channel:create [options] [channelId] create a Firebase Hosting channel
hosting:channel:delete [options] <channelId> delete a Firebase Hosting channel
hosting:channel:deploy [options] [channelId] deploy to a specific Firebase Hosting channel
hosting:channel:list [options] list all Firebase Hosting channels for your project
hosting:channel:open [options] [channelId] opens the URL for a Firebase Hosting channel
hosting:clone <source> <targetChannel> clone a version from one site to another
hosting:disable [options] stop serving web traffic to your Firebase Hosting site
https://github.com/firebase/firebase-tools/tree/master/src/commands
I also couldn't find a relevant hosting command in the source code of Firebase tools. Any ideas?
From the documentation on adding additional sites it seems that adding sites right now is only supported through the Firebase console.
I'd recommend filing a feature request on the Github repo.

Firebase CI deploy as service account

I have a CI pipeline to deploy my firebase changes to different environments. (dev, test, prod)
Currently, it works by running firebase deploy --token $FIREBASE_TOKEN command.
I have generated $FIREBASE_TOKEN by running firebase login:ci from my admin account which has access to all projects (dev, test, prod).
Now if someone gets access to dev CI he/she can deploy directly to production reusing the same $FIREBASE_TOKEN token.
How can I authenticate per firebase project to generate 3 separate tokens for each environment?

using "firebase deploy" to deploy to hosting - how does firebase know if it is deploying to hosting and not cloud functions?

I have a firebase project setup and I want to use that same project for both an iOS app and to host a website.
I built a basic iOS app.
On my desktop I have a folder:
myiosproject
- iOS
- firebase
- functions
- index.js
I followed the steps to setup cloud functions which according to the docs are to npm install firebase tools, firebase init and then firebase deploy. I've deployed my code to cloud functions and that works fine.
I've also built a basic website and would like to deploy that to firebase hosting. On my desktop I have a folder:
myWebsite
- images
- index.html
According to the hosting docs the process to set up and deploy is the same as for cloud functions: npm install, firebase init, firebase deploy.
So my question is how does firebase "know" if I am running firebase deploy from my website folder in which case the code should go to hosting or whether I am deploying from my firebase functions folder in which case the code should go to firebase cloud functions?
If you use the Firebase CLI to create your project (https://firebase.google.com/docs/hosting/quickstart) your project will organize your code by default, separating the files to be used for hosting under a "public" directory and the source code for Cloud Functions under a "functions" directory.
Then you can choose to deploy only the hosting
firebase deploy --only hosting
or only the functions:
firebase deploy --only functions
Have a look at the detailed CLI documentation: https://firebase.google.com/docs/cli/
According to the docs:
firebase-deploy
it deploys the following:
New releases of your Firebase Hosting sites
New or existing Cloud Functions
Rules for Firebase Realtime Database
Rules for Cloud Storage
Rules for Cloud Firestore
Indexes for Cloud Firestore
if you only want to deploy specific features, you can do the following:
firebase deploy --only hosting <-- for hosting
firebase deploy --only functions <-- for cloud functions

Firebase - Deploy Your Site - Deletes Cloud Functions

Question
How can I deploy my Firebase site without erasing Cloud Functions.
Maybe, include both site and cloud-functions in one deploy? What does that look like?
Maybe, deploy the site without erasing cloud-functions? I don't find a firebase deploy --only site or similar
Context
I have a Firebase project that uses Cloud Functions. The code is in two folders:
-site-code
-cloud_function-code
When I want to deploy the project, I use firebase CLI tools, in two steps:
Step 1
from -site-code I run:
firebase deploy
Step 2
then from cloud_functions-code I run:
firebase deploy --only functions
Issue
When I run firebase deploy from -site-code, my Firebase Cloud Functions are deleted, so I must follow up with firebase deploy --only functions from -cloud_functions-code.
I did not find an --only directive for deploying just the site code from -site-code
To only deploy your web site, use
firebase deploy --only hosting
The Firebase CLI provides a way to deploy single functions as shown in its documentation:
firebase deploy --only functions:name_of_function

How to deploy google firebase functions using cmd?

I have a problem with a web hosting project. I created a new proyect in google firebase, and I executed the following commands:
C:\myproject>firebase init functions
C:\myproject>firebase deploy --only functions
But the site says this:
Site Not Found
Why am I seeing this?
There are a few potential reasons:
You haven't deployed an app yet.
You may have deployed an empty directory.
This is a custom domain, but we haven't finished setting it up yet.
How can I deploy my first app?
Refer to our hosting documentation to get started.
What could I do for show, at least, some text when an user go to my project url?
The way you now invoke the Firebase CLI, it will only deploy the Cloud Functions in your project. It will not deploy the web site. In fact, the way you've run it, it probably didn't even create a web site to deploy.
Initialize the project with:
firebase init
And answer the questions this shows.
If you want to deploy the web site, use:
firebase deploy --only hosting
More likely you should simply deploy everything to prevent running into this problem:
firebase deploy

Resources