Most of the time, we recommend using automatic rollouts or manually-triggered rollouts from the Firebase console. However, you may have a use for a more customized deployment flow. App Hosting has multiple options for custom deployment.
Deploy from source with the Firebase CLI
The Firebase CLI lets you push your app's source code and configuration directly from your local machine to Firebase. This is convenient if you have other Firebase deployments (such as security rules or functions) and want to deploy your web app and backend services together with a single CLI command.
On deployment, App Hosting uploads your source code to a Google Cloud Storage bucket, runs your framework build command in Cloud Build, and deploys the final artifacts to Cloud Run and Cloud CDN. App Hosting uses the same build process for local source deployments as GitHub deployments.
To deploy your app from local source:
- Run
firebase init apphosting
in your local project directory. - At the prompt, select Use an existing project, and then select the chosen Firebase project.
Select either a new or existing backend to deploy to; this step sets up App Hosting deployments for your local directory, prompting you for the information App Hosting needs to successfully deploy your app:
- The ID of the backend to deploy to
- The region to deploy to (if creating a new backend)
- The path to the root directory of the application code
App Hosting saves your deployment preferences in
firebase.json
(creating the file in your local project if it doesn't exist). Once initialization completes successfully, you can runfirebase deploy
to deploy your source code to App Hosting.
If you have local source deployments set up for multiple backends (meaning there
are multiple backendId
entries in firebase.json
), firebase deploy
will
deploy to each of those backends. To deploy to a specific backend, use
firebase deploy --only apphosting:backendId
Example firebase.json
{
"apphosting": [
{
"backendId": "my-backend",
// rootDir specifies the directory containing the app to deploy, but the entire
// parent directory of firebase.json will be zipped and uploaded to ensure that
// dependencies outside of the app directory will be available at build time.
"rootDir": "./my-app",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log",
"functions",
],
},
]
}
Deploy using Terraform
If you need greater control over the build process and deployed environment, you can deploy using Terraform. Terraform lets you define and manage your App Hosting resources using declarative configuration files, and provides the ability to deploy your own prebuilt container image directly to App Hosting instead of relying on App Hosting to build from your source code.
If you're new to Terraform, see Get started with Terraform and Firebase. If you're already familiar with Terraform, you can get started with sample configuration files and other App Hosting resources.
Deploy using Firebase Studio
When you create a web app with the App Prototyping agent in Firebase Studio, you can publish, or deploy, to Firebase App Hosting directly from Firebase Studio. See Publish your app with App Hosting.