devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.22k stars 353 forks source link

Allow plugins to extend devspace with functions #2392

Open gustaff-weldon opened 1 year ago

gustaff-weldon commented 1 year ago

Is your feature request related to a problem?

Yes, it is related to creating a function that does quite complicated operations on dependency arrays better done in languages other than shell. Currently, it is not possible to create a plugin that would bring in the function that under the hood just calls the binary with a specific parameters (similar to how commands work).

Which solution do you suggest?

Add ability to add custom functions that would be run against a given binary installed with the plugin eg. into $HOME/devspace/functions.

name: devspace-plugin-example
version: 0.0.1

functions:
    # This will add the 'my_custom_function' function to devspace
  - name: "my_custom_function"
    # these args are prepended to the plugin binary, so when a user will call function with  'my_custom_function test test2 --flag 123'
    # devspace will call the plugin binary with 'plugin-binary other command test test2 --flag 123'
    baseArgs: ["other", "command"]

Things to consider:

Which alternative solutions exist? One can create a shared function that calls a binary:

  my-custom-function: |-
     result=$(../devspace/bin/function-binary "$(get_config_value dependencies)" args....)

and then use it with imports in many projects.

Problem, with this approach is, that binary path would change depending on the nesting of the project.

An alternative approach, would be to create a wrapper plugin, which will bring in the binary that would be installed during some of the pre-* hooks execution into a known location eg. $HOME/devspace/functions and that could be referenced from there:

     result=$($HOME/devspace/functions/function-binary "$(get_config_value dependencies)" args....)

Additional context This started as a thread on Slack https://loft-sh.slack.com/archives/CDSV29U85/p1666360242137239

FabianKramm commented 1 year ago

@gustaff-weldon thanks for creating this issue! This is actually not a bad idea, we'll discuss this internally and then let you know!

gustaff-weldon commented 1 year ago

Hi @FabianKramm thanks. I already have another use case for this. I would like to write a util that would download identifiers of latest images in our ECR and pass those as variables to deployments. This would allow me to avoid updating devspace files with every image release, instead just getting them dynamically when user tries to deploy.

Obviously such an util would be better of running from a proper programming language script (node, ruby, go) rather then from a shell.