cli icon indicating copy to clipboard operation
cli copied to clipboard

Deploy all functions at once

Open JSmithOner opened this issue 3 years ago • 9 comments

Feature request

Is your feature request related to a problem? Please describe.

During for example a CI/CD workflow it seems difficult to deploy changes when new functions have been created/updated/deleted

Describe the solution you'd like

based on a configuration file inside the functions directory ( with all options required per function ) it would be nice to deploy all of them at once. Of course if nothing changed or function already exist the operation won't be the same on your side.

The command line could look something like that.

`supabase functions deploy --all

So basically you could create a function supabase functions new myFunction

which would then create a default config file if none exist like functions.config.ts which would be the default config file, if you want to pass another config file you could add an option --config where you could add the path to the desired config file or something like `supabase functions --set-config my/path.ts to avoid writing back the parameter everytime.

functions.config.ts

{
  "functions": {
    "myFunction": {
      "options": {
        "no-verify-jwt":false,
        "--env-file":""
      }
    }
  }
}

Describe alternatives you've considered

creating an obscure bash script to detect updates in folder and loop through result to deploy them one by one

Additional context

On my side this is mainly to automate process, deploying functions outside of the development pipeline can lead to more errors. I think we can merge this enhancement with this issue #431

JSmithOner avatar Sep 13 '22 21:09 JSmithOner

Sounds good - I think we can make supabase functions deploy deploy all (modified) functions if called without a function name.

soedirgo avatar Sep 14 '22 03:09 soedirgo

@soedirgo how deploy all will handle the option like jwt ? and you closed the issue but i don't see it in the all option in the doc, does it done ?

riderx avatar Sep 15 '22 10:09 riderx

@riderx when creating new function you could pass those parameters which would be written in a config file and be updated on each single deploy of course you could also edit the config file. Just an idea.

JSmithOner avatar Sep 15 '22 11:09 JSmithOner

Thanks, do we have a way to create this file for already existing functions?

riderx avatar Sep 15 '22 11:09 riderx

We probably want to do https://github.com/supabase/cli/issues/280 first so that supabase functions deploy determine whether or not to verify JWT for each function.

soedirgo avatar Sep 15 '22 11:09 soedirgo

@soedirgo as mentionned above do you think you could also add the env file path too?

JSmithOner avatar Sep 15 '22 11:09 JSmithOner

Can you clarify what you mean by the env file? What does it get used for? I was thinking of adding the config in the existing supabase/config.toml, as per #280.

soedirgo avatar Sep 15 '22 11:09 soedirgo

@soedirgo I cannot really advice where to put it but for env I'm talking about --env-file flag you can pass when you serve the function, it could be nice to set the path in a config file this would lighten commands like supabase secrets set --env-file .env to supabase secrets set ( again just an idea) also and this another subject I wasn't able to serve multiple functions at once I guess we could rename this issue to "implement bulk operations commands".

JSmithOner avatar Sep 15 '22 11:09 JSmithOner

Gotcha - tracking that on https://github.com/supabase/cli/issues/459. There's no need to add a env-file config since supabase functions serve already has it as a flag.

soedirgo avatar Sep 15 '22 12:09 soedirgo

Any news on that ? at leas i wish the deploy method could be run in paralell for now it's breaking if i do that, so updating my function take 1 min to do it one by one it's a big cost in CI/CD

riderx avatar Nov 04 '22 07:11 riderx

i did tried again to deploy all function in paralell and still the issue : https://github.com/Cap-go/capgo/actions/runs/4613986040/jobs/8156531019

riderx avatar Apr 05 '23 01:04 riderx

We basically decided to have one main edge function that acts as a router due to the limitation of not being able to deploy all. It limits the ability to scale. Hopefully, this can be added soo!

bombillazo avatar May 12 '23 15:05 bombillazo

We have added the ability to supabase functions deploy which defaults to deploying all functions in supabase/functions directory in sequence.

Currently it does not deploy all in parallel due a limitation of our api. If it becomes a performance bottleneck for your use case, please feel free to file a new issue.

sweatybridge avatar May 19 '23 06:05 sweatybridge

I am the only one receiving error when deploying all?

$ supabase functions deploy --debug
Supabase CLI 1.88.0
Version 1.30.3 is already installed
Invalid Function name. Must start with at least one letter, and only include alphanumeric characters, underscores, and hyphens. (^[A-Za-z][A-Za-z0-9_-]*$)

Am I missing something?

Pictor13 avatar Aug 27 '23 03:08 Pictor13

This error indicates a malformed function name. Could you do a ls -la supabase/functions to help confirm?

sweatybridge avatar Aug 27 '23 03:08 sweatybridge

Right. There are other directories in the folder, all prefixed by underscore to differentiate from edge-functions (_domain, _app). That's shared code.

I couldn't move those deps to a parent directory because (on local-dev) the supabase-cli copies over (to the Deno docker container) only the files under the supabase/functions folder.

Another reason... iirc, was also to solve issues resulting in different parsing/linting among VSCode, Deno-VSCodeExtension and the Deno-in-the-container. So I opted for the whole application source to stay under a single directory.

Pictor13 avatar Aug 27 '23 03:08 Pictor13

@sweatybridge any idea how should I handle my case? Is there any way to move the shared code somewhere else up in the directory hierarchy?

Also, from how I see it, the directories I created are outside of the valid pattern for edge-functions name (the starting _ indeed), hence should be acceptable to have them.
Although I understand that you might not know how to distinguish legit non-function folders from wrongly named function folders.

Maybe, to instruct the CLI how to do that, we need to add one more option to the config.toml, as was already done for verify-jwt and import-map?

I can go on deploying manually each function for now, but it would be nice to get the ability to deploy-all from CI/CD even tho there's shared code in the same namespace.

Pictor13 avatar Aug 28 '23 00:08 Pictor13

the directories I created are outside of the valid pattern for edge-functions name (the starting _ indeed), hence should be acceptable to have them.

I think this is a reasonable expectation so I've created a PR to fix it.

Meanwhile, you can deploy multiple functions passing in all their names. For eg.

supabase functions deploy func_1 func_2

sweatybridge avatar Aug 28 '23 05:08 sweatybridge

@sweatybridge do we have documentation for deploy all with option like no jwt ?

riderx avatar Sep 19 '23 10:09 riderx

Oh i found the doc here: https://supabase.com/docs/guides/functions/cicd-workflow thanks a lot

riderx avatar Sep 19 '23 10:09 riderx

Thank you a bunch @sweatybridge !

Pictor13 avatar Sep 22 '23 11:09 Pictor13