To set up a custom domain for Firebase Hosting using the Firebase CLI on Cloud Build, follow these steps:

  1. Install and configure Firebase CLI:
  • Install the Firebase CLI on your local machine using npm (Node.js package manager).
  • Authenticate the Firebase CLI with your Firebase account by running the firebase login command and following the authentication process.
  1. Create a Cloud Build configuration file:
  • In your project’s root directory, create a file named cloudbuild.yaml.
  • Add the following configuration to the cloudbuild.yaml file: steps: - name: 'gcr.io/cloud-builders/npm' args: ['install', '-g', 'firebase-tools'] - name: 'gcr.io/$PROJECT_ID/firebase' args: ['use', '--add'] entrypoint: 'bash' env: - 'CLOUDSDK_CORE_PROJECT=$PROJECT_ID' - name: 'gcr.io/$PROJECT_ID/firebase' args: ['target', 'hosting', 'deploy'] env: - 'CLOUDSDK_CORE_PROJECT=$PROJECT_ID'
  1. Configure your custom domain in Firebase Hosting:
  • Open the Firebase console and go to your project.
  • In the left sidebar, select “Hosting.”
  • Click on the “Add custom domain” button.
  • Enter your custom domain and follow the instructions to verify domain ownership.
  1. Add the custom domain to your Firebase project:
  • In the Firebase console, go to your project’s settings by clicking on the gear icon in the top-left corner.
  • Select the “Hosting” tab.
  • Scroll down to the “Custom domains” section.
  • Click on the “Add custom domain” button.
  • Enter your custom domain and click “Continue.”
  1. Deploy your Firebase project using Cloud Build:
  • Open a terminal or command prompt and navigate to your project’s root directory.
  • Run the following command to initiate the Cloud Build deployment:
    gcloud builds submit --config=cloudbuild.yaml .
  1. Map your custom domain to the Firebase Hosting URL:
  • After the Cloud Build deployment completes successfully, you need to map your custom domain to the Firebase Hosting URL.
  • Obtain the Firebase Hosting URL from the Cloud Build logs or the Firebase console.
  • Go to your domain registrar or DNS provider and create a CNAME record pointing your custom domain to the Firebase Hosting URL.

Once the DNS changes propagate, your custom domain should be correctly set up with Firebase Hosting using Cloud Build.

Leave A Comment