Firebase: deploy same app to multiple Firebase-projects
Asked Answered
M

3

10

I´m trying to deploy my code to two different Firebase-projects, one for development and one for production.

The my-app-dev project was already included and working, so I added the my-app (for production) with firebase use --add and selected the my-app.

This is how my Firebase-config looks now:

.firebaserc

{
  "targets": {
    "my-app-dev": {
      "hosting": {
        "app": [
          "my-app-dev"
        ]
      }
    }
  },
  "projects": {
    "default": "my-app-dev",
    "prod": "my-app"
  }
}

firebase.json

{
  "hosting": [
    {
      "target": "app",
      "public": "dist/app",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "rewrites": [
        {
          "source": "**",
          "destination": "/index.html"
        }
      ]
    }
  ],
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ]
  }
}

As long as I deploy to my default project, everything works fine, but when I try to firebase deploy -P prod it shows the following error:

Deploy target app not configured for project my-app. Configure with:

firebase target:apply hosting app <resources...>

I tried to find some more information about this command, but still don´t know what to put for resources. Overall I feel like the .firebaserc has a very confusing structure.

Mexico answered 16/6, 2020 at 13:0 Comment(0)
M
1

According to this comment in GitHub it cannot be done without a "hacky" method like swapping the firebase.json programmatically during deploying.

Right now the Firebase CLI is built to treat projects as anonymous environments that are functionally identical. This is important to be able to deploy the same assets to multiple projects without having to alter the code (including in firebase.json).

To achieve what you want, you'll need to set up a dev and prod folder, each with their own firebase.json and each with a target only for that specific project. Deploying different assets to different projects is not supported now and is unlikely to be supported in the future (however, we may allow configuring the location of firebase.json via a flag at some point).

Mexico answered 16/6, 2020 at 19:50 Comment(0)
L
6

I had the same problem but in a different fashion.

The project I have is an Angular 11 project, which has 4 different environments - the same behaviour of deploying to the default project (env) was fine but as soon as I tried to deploy to a different environment (firebase project), it failed with the same error: Deploy target ___ not configured for project ___. Configure with:

I resolved this by adding to my .firebasesrc > targets:

{
  "projects": {
    "default": "default-project"
  },
  "targets": {
    "default-project": {
      "hosting": {
        "frontend": [
          "default-project"
        ]
      }
    },
    "staging-project": { // Added this entry.
      "hosting": {
        "frontend": [
          "staging-project"
        ]
      }
    } 
  }
}
Leptorrhine answered 11/10, 2021 at 11:2 Comment(0)
G
2

Here is how I solved it to deploy to a production project and staging project:

In my .firebaserc file i declare the 2 projects and their sites:

{
  "targets": {
    "my-production-project": {
      "hosting": {
        "production": [
          "my-production-site-id"
        ]
      }
    },
    "my-staging-project": {
      "hosting": {
        "staging": [
          "my-staging-site-id"
        ]
      }
    }
  }
}

Then in my firebase.json I have something like that (conf might differ base on your framework, I m using nextjs here...)

{
  "hosting": [
    {
      "target": "staging",
      "source": ".",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "frameworksBackend": {
        "region": "europe-west1"
      }
    },
    {
      "target": "production",
      "source": ".",
      "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
      ],
      "frameworksBackend": {
        "region": "europe-west1"
      }
    }
  ]
}

Finally I have Makefile with rules to deploy:

staging:
    @echo "Deploying to staging"
    firebase use my-staging-project
    firebase deploy --only hosting:staging

production:
    @echo "Deploying to production"
    firebase use my-production-project
    firebase deploy --only hosting:production

Note the call to firebase use my-production-project

Greggrega answered 27/3, 2024 at 10:29 Comment(0)
M
1

According to this comment in GitHub it cannot be done without a "hacky" method like swapping the firebase.json programmatically during deploying.

Right now the Firebase CLI is built to treat projects as anonymous environments that are functionally identical. This is important to be able to deploy the same assets to multiple projects without having to alter the code (including in firebase.json).

To achieve what you want, you'll need to set up a dev and prod folder, each with their own firebase.json and each with a target only for that specific project. Deploying different assets to different projects is not supported now and is unlikely to be supported in the future (however, we may allow configuring the location of firebase.json via a flag at some point).

Mexico answered 16/6, 2020 at 19:50 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.