Skip to content

WIP: Add DRYrun support - #1808

Merged
flomotlik merged 10 commits into
serverless:masterfrom
johncmckim:issue-1496
Aug 16, 2016
Merged

flomotlik merged 10 commits into
serverless:masterfrom
johncmckim:issue-1496

Conversation

@johncmckim

@johncmckim johncmckim commented Aug 10, 2016 •

Copy link
Copy Markdown
Contributor

Pull Request Template ------------------------

Status:

In Development

Description:

Add's a dryRun flag as described in #1496

Todos:
  • Prevent functions being uploaded to S3
  • Prevent cloudformation stacks being updated
  • Write cloudformation template to disk
  • Write tests
  • Consider whether a separate command is more appropriate - it isn't

@pmuens pmuens added this to the v1.0.0-beta.2 milestone Aug 10, 2016
@pmuens

pmuens commented Aug 10, 2016

Copy link
Copy Markdown
Contributor

Thanks for the hard work you've put into here @johncmckim!

IMHO as discussed in #1496 we should consider to switch to an own plugin as it encapsulates the functionality and implements dryrun in a more pluginish fashion (and not spread across multiple places).

@flomotlik

Copy link
Copy Markdown
Contributor

@pmuens @johncmckim I like the --dry-run option as it is pretty much used in this way in many tools (e.g. the AWS CLI)

The only problem I see at the moment is that in the package plugin we also have the cleanup task which removes the whole .serverless folder. So you can't actually get access to the artefacts after serverless deploy --dryRun

Imho there are 2 options.

  1. We completely remove cleanup (which means the .serverless folder will be growing quite a bit)
  2. We ignore cleanup when the --dryRun option is set (probably better for now)

Thoughts?

@johncmckim

Copy link
Copy Markdown
Contributor Author

@flomotlik @pmuens I'm for the new plugin rather than a command option. With this implementation the flag doesn't actually dry run a deploy, it just builds artefacts. I think that makes the flag a little misleading. That said, I'll go with whatever you decide.

In regards to the cleanup, when I ran this locally the .serverless folder wasn't getting cleaned up. But I may have missed something. I'll check.

What if we ran a cleanup before deploy rather than after. That way the .serverless folder doesn't bloat and the user can see the artefacts after a deploy. As part of this, I'd write the cf template to disk every time not just on dryRun. In the past I've wanted to see the generated cf template on a failed deploy but it wasn't accessible.

@flomotlik

Copy link
Copy Markdown
Contributor

@flomotlik @pmuens I'm for the new plugin rather than a command option. With this implementation the flag doesn't actually dry run a deploy, it just builds artefacts. I think that makes the flag a little misleading. That said, I'll go with whatever you decide.

How would this plugin/command work? It would simply package the artefacts, or what specifically would happen as part of the dryRun (that is different from what is happening here). Maybe we should rename --dryRun to something that says "We're going to build artefacts, but we're not going to deploy them"

What if we ran a cleanup before deploy rather than after. That way the .serverless folder doesn't bloat and the user can see the artefacts after a deploy. As part of this, I'd write the cf template to disk every time not just on dryRun. In the past I've wanted to see the generated cf template on a failed deploy but it wasn't accessible.

That sounds good to me.

@pmuens

pmuens commented Aug 10, 2016 •

Copy link
Copy Markdown
Contributor

What if we ran a cleanup before deploy rather than after. That way the .serverless folder doesn't bloat and the user can see the artefacts after a deploy. As part of this, I'd write the cf template to disk every time not just on dryRun. In the past I've wanted to see the generated cf template on a failed deploy but it wasn't accessible.

I like that one! Really makes sense (some kind of the simplest show me the generated files implementation possible (even if it still deploys your stuff)).

Aside: We need to add the .serverless directory to the users .gitignore file when we're about to do this.

However I would still vote for an extra plugin which encapsulates everything. Otherwise we'll end up with so many code spread across multiple files (if checks if the dryrun option is set to true) which makes it hard to maintain, and extend later on.
The plugin is also a good way to communicate that feature as it's listed as a core plugin with an own command (something like serverless plan, or serverless deploy simulate) instead of a hidden option which might be hard to find in the docs.

@flomotlik

Copy link
Copy Markdown
Contributor

Ok so basically what we're talking about is actually not necessarily dryRun (here at least) but more serverless package to create the artefacts. @johncmckim is that also your idea of it or how would dryRun be different for you?

@flomotlik

Copy link
Copy Markdown
Contributor

One of the reasons why I like this not being a separate plugin is that its future proof. Basically if we update the way deployments happen we need to make dryRun work as well. If its a separate plugin or functionality we might not and it doesn't work correctly any more.

@johncmckim

Copy link
Copy Markdown
Contributor Author

@flomotlik you were right, it was still cleaning up resources. I didn't see it when I was testing as I hadn't setup my AWS_PROFILE.

@pmuens @flomotlik just changed clean to occur before deploying. I've added a new lifecycle event deploy:clean that occurs before deploy:initializeResources. However, I can change it to use before:deploy:initializeResources if you would prefer that.

In relation to the command vs argument, serverless package is what I was thinking. However, the maintainability issue is a fair point.

I think I just don't like the --dryRun terminology. This is probably because of my experience with boto and the aws cli. In both those systems dry run does this for ec2

DryRun (boolean) -- Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation . Otherwise, it is UnauthorizedOperation .

Basically I think --dryRun implies that we're doing more just packaging the artefacts and skipping the deploy.

I do like --plan as to me at least it implies that we're going to get the artefacts ready but do nothing with them. Terraform behaves in this way.

Thoughts? I'm open to either a new plugin, --dryRun or --plan. In the end, they'll all do the job. It's just deciding on the best way to express it.

module.exports = {
writeCreateTemplateToDisk() {
const cfTemplateFilePath = path.join(this.serverless.config.servicePath,
'.serverless', `cf-template-create-${(new Date).getTime().toString()}.json`);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmuens @flomotlik I added a date to the name to keep it inline with the zip package.

Do you think a date is necessary here? It makes it hard to test and if the .serverless folder is being cleaned up it's probably unnecessary.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho timestamp is good here so it doesn't overwrite anything in the future in case we change this implementation a bit and keep more things around.

@flomotlik

Copy link
Copy Markdown
Contributor

Imho --plan is still a bit hard to understand, because it doesn't really say what planning actually is in this context. What about --no-deploy? It clearly states what is going to happen. Looks a bit silly with serverless deploy --no-deploy but at least its very understandable. Another option would be --package-only, although the whole process might be doing more than just packaging things up so this could be a bit misleading as well.

@johncmckim

Copy link
Copy Markdown
Contributor Author

@flomotlik naming things is hard. I could get behind --no-deploy or --package-only.

@flomotlik

Copy link
Copy Markdown
Contributor

lets go with --no-deploy :D. We can easily change it later if we have a better idea

@johncmckim

johncmckim commented Aug 12, 2016 •

Copy link
Copy Markdown
Contributor Author

I've updated it to --noDeploy which isn't as nice as --no-deploy. I was having a few issues with minimist.

To use --no-deploy I need to create a deploy option and minimist will convert --deploy and --no-deploy to true and false. However, since there is no ability to pass defaults to minimist right now the default is false.

I could solve that with _.isNil checks everywhere. However, I wasn't sure that it is the best solution. Otherwise, I could add a default property to plugin command options. This could then be passed into minimist.

What would you prefer?

@pmuens

pmuens commented Aug 13, 2016

Copy link
Copy Markdown
Contributor

@johncmckim thanks for the updates! 💃

I would do the simple solution / the less "hacky" one and vote for --noDeploy for now.

Will look into the PR in detail soon.
At a first glance it looks really good 👍
The only thing I'm thinking about is the introduction of the new clean lifecycle which could be replaced with before:deploy:deploy. The "problem" with adding a new lifecycle is that we need to support those as plugin authors depend on it and we want to understand the other cloud providers in detail so that we have a very general and minimalistic set of lifecycle events every cloud provider would use.

Writing the CloudFormation template to disc might be related to this issue:
#1740

So this PR could be a good preparation for #1740 🎉

@flomotlik

Copy link
Copy Markdown
Contributor

@pmuens I actually like the clean step. Imho its something that sometimes needs to happen at the beginning of a deployment, so Imho introducing a separate step makes it easier for other providers in the future to integrate there. Also in favor of --noDeploy. I also tried it locally and it properly created the files and didn't deploy.

From my perspective this is GTM, @pmuens could you review the code as well and merge in case the code is fine for you.

@pmuens

pmuens commented Aug 14, 2016

Copy link
Copy Markdown
Contributor

Alright! Will look into this and merge once fully reviewed.

Thanks @johncmckim for your work on this one!

@pmuens pmuens self-assigned this Aug 14, 2016
});
});

it('should resolve if dry run', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update this test description (should resolve if no deploy)?

@pmuens

pmuens commented Aug 15, 2016

Copy link
Copy Markdown
Contributor

@johncmckim just reviewed it and added a few comments (mainly some renamings).

Furthermore some documentation about this new feature would be great (some description on how to use it here: https://github.com/serverless/serverless/tree/master/lib/plugins/deploy and the new lifecycle here: https://github.com/serverless/serverless/tree/master/lib/plugins/deploy#provided-lifecycle-events)

After those changes it's GTM from my side.

Great work 🎉 ❤️

Comment thread lib/plugins/package/index.js Outdated
.then(this.zipService),

'after:deploy:deploy': () => BbPromise.bind(this)
'deploy:clean': () => BbPromise.bind(this)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this above deploy:createDeploymentArtifacts so that correct order the hooks run through can be seen without looking into the deploy plugin.

@pmuens

pmuens commented Aug 16, 2016

Copy link
Copy Markdown
Contributor

@johncmckim great! Thanks for the updates 👍 . Will pull, test and merge it today!

Comment thread lib/plugins/aws/deploy/index.js Outdated
.then(() => {
const msg = this.options.noDeploy ?
'Deployment successful!' :
'Did not deploy due to --noDeploy';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably remove the "Deployment successful" message since deployment never really happened.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I think I've got my messages the wrong way around. That would be confusing. I can update later today.

@nicka

nicka commented Aug 16, 2016

Copy link
Copy Markdown
Contributor

Another reason I really like this dry-run/no-deploy is that it allows for a CF diff plugin. First generate the new template without deploying and diffing against the running CF stack. This allows you to be more confident about what CF is going to perform during the deployment.

@johncmckim

Copy link
Copy Markdown
Contributor Author

@nicka although it's a separate issue I've been wondering about that too. Whether serverless could or should use CloudFormation Change Sets and the separation of build and deploy.

With a few small changes you could support deploying pre-built artefacts. This would be helpful for projects like LambCI where people deploy the project into their own environment.

@nicka

nicka commented Aug 16, 2016 •

Copy link
Copy Markdown
Contributor

@johncmckim Not sure about the CloudFormation Change Sets(maybe haven't used it enough). This could even be it's own plugin, to build and to deploy. For me personally simply seeing the diff between two templates would already be a useful addition. Although it might take some more skill to predict what will happen based on the diff, it could also help new users to get used to CF.

And my mind is blown by LambCi 🚀 !!!

@flomotlik
flomotlik merged commit 83a99b5 into serverless:master Aug 16, 2016
@flomotlik

Copy link
Copy Markdown
Contributor

thanks @johncmckim for this!

@thenikso

thenikso commented Aug 16, 2016 •

Copy link
Copy Markdown

Great job! Looking forward for beta2

question: will I be able with --noDeploy to see the merged/final CloudFormation configuration? It would be extremely useful to understand if I'll be deploying exactly what I'd like to

EDIT: Just checked out this PR's sources and yes, I'll be able to see the CloudFormation template with this 😆

@ozbillwang

Copy link
Copy Markdown

Seems this PR is gone, I can't find the option of noDeploy now.

Will sls still support this feature?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants