Hosting a web application with Firebase Hosting
TypeScriptWhen you want to host a web application with Firebase Hosting using Pulumi, you'll leverage the capabilities of the Google Cloud Platform (GCP) provider. Firebase Hosting is a production-grade web content hosting platform that lets you quickly and securely deploy web apps and static content to a global content delivery network (CDN).
The following Pulumi program in TypeScript will help you set up Firebase Hosting for your web application. We'll be defining a site through Firebase Hosting and creating a new site version which we will then release. The
Site
resource represents your Firebase site, and theRelease
resource is used to deploy new content to your site.The process consists of these steps:
- Setting up a new Firebase project or using an existing one,
- Creating a new Firebase site using
Site
resource, - Uploading files to be hosted,
- Creating a version and a release to deploy the files using
Version
andRelease
resources.
We'll start with step 1 and 2, create a new
Site
resource, and configure some properties.import * as pulumi from "@pulumi/pulumi"; import * as gcp from "@pulumi/gcp"; const config = new pulumi.Config(); const projectName = config.require("gcpProject"); const siteId = "your-site-id"; // Choose a unique name for your Firebase site // Create a new Firebase Hosting site const site = new gcp.firebase.HostingSite("mySite", { siteId: siteId, project: projectName, }); // Next, you would typically use Pulumi to upload your site's files to Google Cloud Storage. // However, this step involves procedures outside the scope of Pulumi's Infrastructure-as-Code. // You would include commands or a CI/CD workflow to upload the content to Firebase hosting buckets. // Once files are uploaded, you need to create a version resource. const version = new gcp.firebase.HostingVersion("myVersion", { siteId: siteId, // Other configurations related to headers, redirects, and rewrites can be set here. // The actual files should be uploaded to Firebase through Firebase CLI or another method // since Pulumi is not designed to handle file uploads directly. }); // Finally, create a release to make the version live. const release = new gcp.firebase.HostingRelease("myRelease", { siteId: siteId, versionName: version.name, message: "Deploying my web application", }); export const siteName = site.siteId; export const siteUrl = site.url; export const versionName = version.name; export const releaseName = release.name;
In the program, replace
"your-site-id"
with a unique identifier for your Firebase Hosting site. Note that this program assumes you have existing content to be hosted which should be handled typically through Firebase CLI by runningfirebase deploy
.This program simply sets up the necessary resources through Pulumi and references them. After that, you need to deploy the actual files using Firebase CLI or an equivalent method outside of Pulumi, since the deployment of web files is not something Pulumi manages directly.
When deploying using Pulumi, ensure you have the appropriate credentials set up to interact with Google Cloud. This usually means that you've run
gcloud auth login
andgcloud config set project YOUR_PROJECT_NAME
with your project's ID.Lastly, don't forget to run
pulumi up
to deploy the resources specified in the program.For further reading, please refer to the following documentation: