Skip to content

Allow commands to define before/after command dependencies that should run as well #2659

Closed

Description

@flomotlik

This is a Feature Proposal

Description

Some commands (e.g. Deployment) depend on other steps of the process (e.g. packaging) that should be handled in a separate command, so they can be exposed to users as well. We need a clean way for command authors to define this dependency and then for the Plugin System to actually execute this command beforehand or after.

To implement this we need to extend the Plugin System to allow for dependent commands to run before or after the command the user entered. The command will execute its own lifecycle events and will have the same options that are available to the command the user entered. This might lead to issues with overlapping command line options which we can address in a future update by namespacing options (if necessary, doubt it will be at this point).

Config Example

To define dependencies to other commands you can add a dependencies config parameter that can have before and after sections to your command config. Before/After can take strings or arrays of strings in case there are several dependencies. Those dependent commands will then be executed.

dependencies: {
  before: 'package',
  after: ['info', 'cleanup']
}

Here is an example deploy command:

this.commands = {
  deploy: {
    usage: 'Deploy a Serverless service',
    dependencies:{
      before: 'package',
      after: ['info', 'cleanup']
    }
    lifecycleEvents: [
      'cleanup',
      'initialize',
      'setupProviderConfiguration',
      'createDeploymentArtifacts',
      'compileFunctions',
      'compileEvents',
      'deploy',
    ],
  }
}

Similar or dependent issues:

Activity

  1. added this to the 1.3 milestone on Nov 8, 2016
  2. austencollins commented on Nov 13, 2016

    @austencollins
    Member

    Please don't move forward with this until we've had some time to discuss.

  3. flomotlik commented on Nov 16, 2016

    @flomotlik
    ContributorAuthor

    Yup, please share your thoughts in this issue so we can start planning this.

    On 14 November 2016 at 00:57:20, Austen ([email protected]) wrote:

    Please don't move forward with this until we've had some time to discuss.

    —
    You are receiving this because you authored the thread.
    Reply to this email directly, view it on GitHub, or mute the thread.

  4. pmuens commented on Nov 22, 2016

    @pmuens
    Contributor

    Would like to continue the discussion here.

    @ac360 can you share your thoghts?

    /cc @nikgraf @mthenw @eahefnawy

  5. nikgraf commented on Nov 23, 2016

    @nikgraf
    Contributor

    We were also thinking about exposing an API to invoke function programmatically. This benefit would be that you could start using Serverless as a toolbox to build and run your own flows. Compared to just before/after it would be more flexible as you could defined different paths based on previous commands.

    The benefit of having before and after is the static nature. The framework can provide the CLI with more information on which steps actually will run. Did I miss other benefits?

    In both cases we clearly have the opportunity to modularize the code even further. Right now there are some functions re-used by multiple plugins which simply could be a command invoked e.g. serverless info. Also as @johncmckim pointed out both ways we can create a build/package command.

    Thoughts? @ac360 @johncmckim @eahefnawy @pmuens

  6. removed this from the 1.3 milestone on Nov 23, 2016
  7. johncmckim commented on Nov 24, 2016

    @johncmckim
    Contributor

    @nikgraf a formal plugin API would be great (with documentation!). Right now we're hanging so much stuff off serverless.service. To work out what we need we're looking at the serverless source and basing plugins on existing plugins.

    An option to trigger other plugins would be helpful. In relation to build/package this would allow deploy to trigger a build if required.

  8. pmuens commented on May 19, 2017

    @pmuens
    Contributor

    Closing this to keep the issue count low. We'll revisit this when working on upcoming Serverless versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions