devspace icon indicating copy to clipboard operation
devspace copied to clipboard

Allow plugins to extend devspace with functions

Open gustaff-weldon opened this issue 3 years ago • 2 comments

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:

  • do we give access to devspace env variables and config file to that function?
  • the binary of the function would not most likely be able to use other functions

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

gustaff-weldon avatar Oct 24 '22 14:10 gustaff-weldon

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

FabianKramm avatar Nov 03 '22 16:11 FabianKramm

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.

gustaff-weldon avatar Nov 07 '22 11:11 gustaff-weldon