FirebaseExtended / action-hosting-deploy

Automatically deploy shareable previews for your Firebase Hosting sites
https://firebase.google.com/docs/hosting/github-integration
Apache License 2.0
695 stars 202 forks source link

Deploying to Multiple Domains within the same project #176

Closed JamesVanWaza closed 2 years ago

JamesVanWaza commented 2 years ago

Action config

- uses: FirebaseExtended/action-hosting-deploy@v0
    with:
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_xxxxxx }}'
          channelId: live
          projectId: xxxxx

Actual behavior

It works, but I would like to know how to change it to work for a specific project.

  1. In Firebase I have the main project start-bootstrap but I also have another 20 different, but they are in the same project but all have different subdomains. When I deploy all my projects, they deploy to start-bootstrap, but I want them to have different subdomains
riker09 commented 2 years ago

You have to define a target parameter under with like so:

    - uses: FirebaseExtended/action-hosting-deploy@v0
      with:
        target: my-target
        repoToken: "${{ secrets.GITHUB_TOKEN }}"
        firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_xxxxxx }}"
        channelId: "live"
        projectId: xxxx

And in your .firebaserc you define the targets:

{
  "projects": {
    "default": "my-project"
  },
  "targets": {
    "my-project": {
      "hosting": {
        "my-target": [
          "id-of-target-as-defined-during-creation"
        ],
        "my-other-target": [
          "other-target-id"
        ]
      }
    }
  }
}
JamesVanWaza commented 2 years ago

@riker09 is this correct?

.firebase-hosting-merge.yml

    - uses: FirebaseExtended/action-hosting-deploy@v0
        with:
          target: my-target
          repoToken: '${{ secrets.GITHUB_TOKEN }}'
          firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_xxxxx }}'
          channelId: live
          projectId: startbootstrap-dostesting

.firebaserc

{
    "projects": {
        "default": "startbootstrap-dostesting"
    },
    "targets": {
        "my-project": {
            "hosting": {
                "my-target": ["algolia-instantsearch-demo"]
            }
        }
    }
}
riker09 commented 2 years ago

I'd say yes, this looks okay. Did you try it out? I have a Firebase project with four different frontends that are defined as different deploy targets and they all deploy successfully using this pattern.

JamesVanWaza commented 2 years ago

@riker09 not yet, still getting an error. Is there a way to show how you have setup your .firebaserc file, this is the error see screenshots attached.

Screen Shot 2021-12-09 at 11 31 25 AM Screen Shot 2021-12-09 at 11 31 41 AM Screen Shot 2021-12-09 at 11 31 52 AM
riker09 commented 2 years ago

Sorry for not getting back to you on this. The .firebaserc I have posted here in this issue was copied straight from my editor and was only modified for security reasons (changed the real project ID with my-project and the targets with my-target). Make double-sure those strings are aligned with your firebase.json.

JamesVanWaza commented 2 years ago

@riker09 still having the problem, is it possible for you to show how you did it because even if I run the following firebase target:apply hosting blog myapp-blog https://firebase.google.com/docs/cli/targets#set-up-deploy-target-hosting if I run firebase deploy --only hosting I keep getting error 500.

riker09 commented 2 years ago

Hello @JamesVanWaza, I'm afraid this is all the insights I can give you for now. I had a difficult time setting this up when I began using Firebase as well. It is maybe a hard-to-spot typo in one of the project names or aliases? My advise is to read the documentation carefully (again) and make double-sure that the aliases and project names match and are in the right places.

JamesVanWaza commented 2 years ago

Thanks, will review again, maybe @puf has some ideas on the right way to do this.

JamesVanWaza commented 2 years ago

@riker09 so I was able to solve it, thank you but for some sites, I think it's caching the old target name and any idea for it to update because all the steps are correctly done on firebase.json and .firebaserc

riker09 commented 2 years ago

Great to hear that you were able to solve you problem! 👍🏻

Caching can be a royal PITA, especially if you're not aware that something is cached. Maybe you can leave some informaton here on how you figured out that caching was an issue in the first place and how you got around it for the next person stumbling upon this issue?

JamesVanWaza commented 2 years ago

@riker09 if anyone experiences the same issue, delete the following files firebase-hosting-merge.yml and firebase-hosting-pull-request.yml, then ran firebase init. Make sure you have the most updated version 9.6.6 and above and the setup will be done automatically. Thank you so much it was a lot of error-checking but if anyone has a problem I can help you solve it.

killoblanco commented 2 years ago

Hi, yesterday (05/24/2022) I did face this issue. Below is a code snippet letting you know how I did figure it out. I hope this helps to solve this issue 😃

secrets.FIREBASE_TOKEN was generated by running firebase login:cli

- run: npm i -g firebase-tools
- run: firebase use --add <project-id> --token ${{ secrets.FIREBASE_TOKEN }}
- run: firebase target:apply hosting <target-name> <target-id>
- uses: FirebaseExtended/action-hosting-deploy@v0
  with:
    repoToken: '${{ secrets.GITHUB_TOKEN }}'
    firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_KILLOBLANCO_119F3 }}'
    target: <target-name>
    projectId: <project-id>

My conclusion about this is that as far as the firebase CLI uses the file .firebaserc but this is usually not committed in the repository you must install and create the file on the remote process before running the action, so the action can perform successfully

JamesVanWaza commented 2 years ago

@killoblanco if you have any questions let me know, otherwise closing