mvila / serverless-plugin-scripts

Add scripting capabilities to the Serverless Framework
123 stars 15 forks source link

Added support for arrays of commands in a hook #4

Closed sgulics closed 6 years ago

sgulics commented 6 years ago

I added the ability to add an array of commands to a hook:

hooks:
  deploy:deploy:
    - node bin/doSomething.js
    - node bin/doSomethingElse.js
    - echo Finished deploying ${self:service} service!
mvila commented 6 years ago

Thank you, @sgulics, but couldn't you just use the shell features? I mean you can achieve the same thing with just node bin/doSomething.js && node bin/doSomethingElse.js && etc.. I'm sorry, but I am not very keen to add a feature for something that can be achieved at a lower level.

sgulics commented 6 years ago

Hi @mvila, thanks for taking a look and I understand your reasoning. I forked it to use arrays because in the current project I am working on we have 5 scripts that get run on deployment. We thought that the array made it look cleaner than chaining the commands together with &&. Also, some of the scripts are relatively complex, so if something goes wrong, we know which script failed.

Here is an example of what our current configuration looks like:

deploy:deploy:
  - REGION=${opt:region, self:provider.region} STACK_NAME=${self:custom.stackName} node bin/export_cf_output.js 
  - "ES_HOST=${self:custom.elasticSearch.environment.ES_HOST} \
  ES_INDEX_NAME=${self:custom.elasticSearch.environment.ES_INDEX_NAME} \
  node migrations/elasticsearch/index.js"
  - "source .serverless/cf_output_variables && LAMBDA_ARN=$CF_ALambdaFunctionQualifiedArn \
  node bin/add_lambda_permission.js"
  - "source .serverless/cf_output_variables && STAGE=${self:custom.stage} \
  VALIDATION_LAMBDA_ARN=$CF_AnotherLambdaFunctionQualifiedArn \
  BUCKET_NAME=${self:custom.templates.bucketName} node bin/deploy_templates.js"
  - echo Finished deploying ${self:service} service!
mvila commented 6 years ago

I am sorry, but I really think that your issue should be solved in another way. To make things cleaner, maybe you should put everything in a simple bash script.