skip to Main Content

We have several 2nd gen functions sharing the same source code. Only one of them needs to be deployed with a different ignore configuration in firebase.json.

It’s about 2 MB inside a bin folder that we want to ignore in all the other functions, except for that one.

Our current firebase.json looks like this:

"functions": [{
  ... ...,
  "ignore": [
    "node_modules",
    "firebase-debug.log",
    ... ...,
    "bin"   // <==== REMOVE THIS LINE FOR A SPECIFIC FUNCTION ONLY
  ]
}]

Any ideas on how we could achieve that?

What we’ve tested:

We thought of configuring a different functions[].codebase: 'code2', for example, (so we could run firebase deploy --only functions:code2:myBinFunction), but actually both functions[].source point to the same folder, so deployment complains with Error: functions.source must be unique but './functions' was used more than once.

We don’t want to split source code to a different folder because they all share many things and to keep maintenance simple. Also, I’m sure anyone in the team will forget and deploy using the wrong codebase and this would need a way to fail if deployed without the bin folder.

Maybe there’s a totally different approach to this? Thanks in advance

EDIT:
Oh well, configuring functions[].source: 'functions' in one block, and functions[].source: './functions' on the other block did the trick to allow deployment. But I still have the problem that I need deployment to fail if the function is deployed from the wrong codebase (i.e., deployed without the bin folder it needs)

2

Answers


  1. Chosen as BEST ANSWER

    I ended up configuring a predeploy and a postdeploy script to:

    • Reject deployment of full function list. Only individual deployment is allowed.
    • Reject deployment if there's a mix of bin-folder-required functions and regular functions.
    • If a bin-folder-required function is being deployed, its corresponding codebase is found in firebase.json, then the ignore list is edited:
      • On predeploy: remove bin folder from ignore list.
      • On postdeploy: add bin folder back.

    The firebase.json looks like this:

    {
      "functions": [
        {
          "source": "functions",
          "codebase": "f2",
          "predeploy": "node scripts/firebase-deploy.js predeploy",
          "postdeploy": "node scripts/firebase-deploy.js postdeploy",
          "ignore": [
            "node_modules",
            ".git",
            ... ...,
            "bin"
          ]
        }
      ],
    

    And the script firebase-deploy.js considers:

    process.env.PROJECT_DIR // where firebse.json is located
    process.env.npm_lifecycle_script // package.json script being run
    

    We always deploy from package.json scripts, so this approach works for us.

    A bit long but if someone wants the script as a reference, just ask. More info on firebase deploy hooks here.


  2. The way the Firebase CLI was designed for function deployment made the initial assumption that all of the function in a single project directory are deployed together, and they all get the same set of files, which is suitable for a large majority of expected use cases for apps that use Firebase. The fact that the CLI offers you the ability to deploy them separately is mostly just an optimization for occasionally deploying only functions that are known to have changed without having to wait for them all to deploy. If you really do have two sets of functions that must be deployed separately with different sets of files and configurations, then the Firebase CLI is just going to make your life hard.

    Best case, you can *create a different project workspace with different sets of files required by each function and manage them separately, but you must be careful that you don’t allow the deployment of one workspace to undo what was deployed in the other. Common code can be npm installed into each project from another location prior to deployment. You will need to know how to work with npm in a way that isn’t typical. See the following for ideas:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search