Connect Cloud Run to Firebase Hosting for custom domains and CDN

To set up a new public endpoint for your Cloud Run service, you can use Firebase Hosting in front of your Cloud Run service. With Firebase Hosting, you can get access to a global CDN and can configure free custom domains for your service. Firebase Hosting lets you direct hosting requests to your Cloud Run service, but might require time to onboard if you're not familiar with using Firebase Hosting.

By using the Cloud Run integrations (Preview) described on this page, you can quickly expose your Cloud Run service through a new Firebase Hosting site without having to setup Firebase Hosting. If you want to use an existing site, refer to Serve dynamic content and host microservices with Cloud Run.

Before you begin

  • Make sure the Cloud Run service you are integrating with is already deployed.
  • Review the Firebase Hosting pricing pricing page. You are billed for individual resources used in the integration.

Required roles

To use the Cloud Run integrations, you or your administrator must grant IAM roles on two different principals.

Click to view required roles for your Google Account

To get the permissions that you need to use Cloud Run integrations, ask your administrator to grant your Google Account the following IAM roles on your project:

Click to view the required roles for the service account

To deploy the Cloud Run service, you can either use the auto-created Compute Engine default service account, or specify a user-managed service account. The service account must have the following roles:

Connect your Cloud Run service to a Firebase Hosting site

You can connect to a Firebase Hosting site using the console or the command line.

Console

  1. In the Google Cloud console, go to the Cloud Run page.

    Go to Cloud Run

  2. Click the service in the services list that you want to use in this integration.

  3. Click the Integrations tab.

  4. Click Add integration.

  5. Click Firebase Hosting.

    image

  6. Enter a site ID in the Subdomain (Site ID) field. Your service will be hosted at site_ID.web.app after creation.

  7. If prompted to enable a list of APIs, click Enable and wait for the APIs to be enabled. Note that the Firebase Hosting API is under the Firebase Terms of Service.

  8. Under Resources, note the new resources that will be created as a result of this integration.

  9. Click Submit and wait for the integration and resources to be created.

    • When complete, the public URLs of the site are displayed.
    • You can also click the provided link to go directly to the Firebase console.

Command line

  1. Update to the latest Google Cloud CLI:

    gcloud components update
    
  2. Create the integration:

    gcloud beta run integrations create \
    --type=firebase-hosting \
    --service=SERVICE \
    --parameters='site-id=SITE_ID'
    

    Replace:

    • SITE_ID with the Firebase Hosting site ID you want to create and use. This appears as the subdomain for the Firebase URL 'SITE_ID.web.app'
    • SERVICE with the name of the Cloud Run service you are using.

    Optionally, include the --service-account=SERVICE_ACCOUNT_EMAIL flag.

    • Replace SERVICE_ACCOUNT_EMAIL with the user-managed service account email address (PROJECT_NUMBER-compute@developer.gserviceaccount.com) that is used to deploy the service. Omit this flag if you want to use the default compute service account (SERVICE_ACCOUNT_ID@PROJECT_ID.iam.gserviceaccount.com).

      To continue using the specified service account when deploying Cloud Run integrations, run:

      gcloud config set runapps/deployment-service-account
      
  3. Wait about 1-2 minutes while the Firebase Hosting site is created. When the process is complete, the following success message is shown:

    [firebase-hosting] integration [firebase-hosting-1] has been created successfully.
    

    You can check the status using gcloud beta run integrations describe.

Update Firebase Hosting integrations

Updating an integration updates all of the Google Cloud resources associated with that integration. To update a Firebase Hosting integration from your Cloud Run service:

Console

  1. In the Google Cloud console, go to the Cloud Run page.

    Go to Cloud Run

  2. Click the service you want to update.

  3. Click the Integrations tab.

  4. Locate the Firebase Hosting integration and click Edit.

  5. When you are finished with updating the fields, click Update.

Command line

  1. Use the following command to get a list of available integrations:

    gcloud beta run integrations list
  2. Run the command to update the integration:

    gcloud beta run integrations update INTEGRATION_NAME
    

    Replace:

    • INTEGRATION_NAME with the name of your Firebase Hosting integration.

    Optionally, you can use the following flag options:

    Option Description
    --parameters The site ID you are replacing the Cloud Run service with.
    --service-account The user-managed service account email address to specify when updating the service. This service account overrides the previous service account that was used at deployment.

View Firebase Hosting integrations

To view the current status of Firebase Hosting integrations for your Cloud Run service:

Console

  1. In the Google Cloud console, go to the Cloud Run page.

    Go to Cloud Run

  2. Click the service in the services list that you want to use in this integration.

  3. Click the Integrations tab.

  4. Locate the Firebase Hosting integration you are interested in and click View details.

Command line

  1. Use the following command to get a list of available integrations:

    gcloud beta run integrations list
  2. Using a name from the returned list, display the details for it:

    gcloud beta run integrations describe INTEGRATION_NAME

    Replace INTEGRATION_NAME with the name of your Firebase Hosting integration.

Delete Firebase Hosting integrations

Deleting an integration will also delete all of the Google Cloud resources associated with that integration, but it will not delete your Cloud Run service.

To delete a Firebase Hosting integration from your Cloud Run service:

Console

  1. In the Google Cloud console, go to the Cloud Run page.

    Go to Cloud Run

  2. Click the service you want to delete an integration from.

  3. Click the Integrations tab.

  4. Locate the Firebase Hosting integration you are interested in and click the ellipsis icon to the right of the integration, then click Delete.

Command line

  1. Use the following command to get a list of available integrations:

    gcloud beta run integrations list
  2. Using a name from the returned list, delete the integration:

    gcloud beta run integrations delete INTEGRATION_NAME
    

    Replace:

    • INTEGRATION_NAME with the name of your Firebase Hosting integration.

    Optionally, you can use the following flag options:

    Option Description
    --service-account The user-managed service account email address to perform the delete operation.

Limitations

The Cloud Run integrations is only supported in certain regions. If you need to use a region that is not supported by the Cloud Run integrations, refer to Serve dynamic content and host microservices with Cloud Run.