Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] skip_register_ami option #3793

Closed

Conversation

jeremy-asher
Copy link
Contributor

@jeremy-asher jeremy-asher commented Aug 10, 2016

I thought I'd put this up here as an idea for feedback before I do any more work.

It would be nice to avoid doing any AMI build steps in workflows where the AMI is not the true product and Packer is being used as a convenient mechanism to create a temporary AWS instance. I presume anyone using the artifice post processor would want this toggle.

Let me know if this makes any sense from a high level or implementation standpoint.

@pvanbuijtene
Copy link

We first test our images and destroy unused AMI's before creating the final, so you're not the only one interested in this feature ;)

@rickard-von-essen
Copy link
Collaborator

This makes sens to me.

@jeremy-asher
Copy link
Contributor Author

Okay, I'll clean this up and add docs and param checks.

@mwhooker
Copy link
Contributor

@jen20 can you mention this PR when you put your ebs builder up?

}

func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error {
var errs []error
if c.AMIName == "" {
if c.AMIName == "" && !c.AMISkipRegister {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we can replace this with

if c.AMISkipRegister {
    return
}
if c.AMIName == "" {
...

?

Copy link
Contributor

Choose a reason for hiding this comment

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

in https://github.com/mitchellh/packer/blob/master/builder/amazon/ebs/builder.go#L96-L103 it looks like we make use of the AMI name and some other config.

I wonder if we should either not run that step if we're skipping registration, or add another flag like ForceDeregister (eg SkipRegister) to make it a no op.

I generally like letting the steps decide if they're going to run or not, but we're already picking and choosing which steps we run based on config in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the lag in following up with this. I think the rest of the validations in the prepare function can currently be skipped. I put a temporary note below there in the commit that I have to do additional validation that certain other params aren't supplied that don't have any effect with skip_register_ami, though.

Looks like those line references changed since you referenced them, but I presume you mean StepPreValidate and StepSourceAMIInfo. I suppose I got lucky that the PreValidate does still work, but it should be skipped. I don't see any reference to the AMI name in StepSourceAMIInfo. Did you mean a different step?

It looks like StepPreValidate already has ForceDeregister passed in which triggers an informational message. I'm not sure if that is a convention, but I could wrap the whole step like the others or pass a flag in. I don't mind either way, but for the larger blocks it seemed to make more sense to do it outside.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, before I start adding some validations that unused options aren't supplied, would it make sense to modify the signature of Prepare to return warnings as well as errors? I don't like the idea of crashing the run if unused options are supplied, but that seems to be the style for the Prepare functions.

Copy link
Contributor

@mwhooker mwhooker Mar 16, 2017

Choose a reason for hiding this comment

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

the prepare functions are run before any work is done, so erroring is the correct behavior

let's just return early, here. I don't care so much about users having extraneous config

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I was referring to &awscommon.StepPreValidate{. I would add another struct element to it, SkipRegister, and inside the step, check if that flag is set and return early if it is

Add a skip_register_ami option which bypasses all steps after
provisioning.
@jeremy-asher
Copy link
Contributor Author

Rebased to fix conflicts.

@jeremy-asher
Copy link
Contributor Author

@mwhooker I have to do some more updates, but I could use your response to my earlier questions to close this out.

errs = append(errs, fmt.Errorf("ami_name must be specified"))
}

// TODO: confirm that bypassed options aren't supplied with skip_register_ami
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think we need to do this

@mwhooker
Copy link
Contributor

Added a couple of comments.

I think having so many steps being added inside of an if statement makes the code harder to read. Perhaps instead it could look something like:

steps := []multistep.Step{
...
}

amiCreationSteps := []multistep.Step{
... steps where we create the AMI
}

if ! c.AMISkipRegister {
    steps = append(steps, amiCreationSteps)
}

@jeremy-asher
Copy link
Contributor Author

Thanks! I'll update this and make those changes.

@jeremy-asher
Copy link
Contributor Author

I'm replacing this with #4681.

@ghost ghost locked and limited conversation to collaborators Apr 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants