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

add skip_register_ami option #4681

Closed
wants to merge 2 commits into from

Conversation

jeremy-asher
Copy link
Contributor

This is a cleaner implementation of #3793 which should take into account feedback from @mwhooker. In summary, this allows the AWS builders to be used for additional purposes when the AMI is not the final product of the build. When the "skip_register_ami" option is set, this skips all the steps following provisioning and proceeds straight to instance termination.

Note: this PR doesn't yet modify the newer EBS Surrogate Builder. I wasn't clear on how it works or how it differs from using from_scratch option I added to the Chroot builder. I can add a similar bypass to the Surrogate builder if that makes sense. @jen20 could your clarify?

@mwhooker
Copy link
Contributor

@jeremy-asher thanks very much for keeping up with this. Will target for next release

@jeremy-asher
Copy link
Contributor Author

@mwhooker should I just add this for the EBS Surrogate Builder as well and add the docs?

@mwhooker
Copy link
Contributor

hmm, not sure it makes sense to add to that builder. Will have to think if it makes sense to add this to all the builders or just 1 or 2.

@jeremy-asher
Copy link
Contributor Author

Thinking about this a bit more, I don't really see any harm in adding this option to the surrogate builder, but I can't think of any obvious use case. If someone wanted to do something with a blank device, they could use the regular EBS builder with this. I still think it's potentially useful with all of the other three builders.

@mwhooker
Copy link
Contributor

@jeremy-asher This is looking good. Would you please add documentation to

  • website/source/docs/builders/amazon-chroot.html.md
  • website/source/docs/builders/amazon-ebs.html.md
  • website/source/docs/builders/amazon-instance.html.md

describing the new skip registration option and maybe giving a 1 sentence reason for why you might want to use this?

@@ -173,6 +174,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
b.config.RunConfig.Comm.SSHPassword),
},
&common.StepProvision{},
}

amiCreationSteps := []multistep.Step{
&awscommon.StepStopEBSBackedInstance{
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 we want to stop the instance even if we're not creating an AMI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@jeremy-asher
Copy link
Contributor Author

Okay, I'll take care of the documentation.

Add a skip_register_ami option which bypasses all steps after
provisioning.  The ami_name setting is not required with
skip_register_ami.
@jeremy-asher
Copy link
Contributor Author

Rebasing this real quick. @mwhooker is the desired style now to indent the second and subsequent lines of a multi line list item block an extra two spaces? I see some inconsistencies since rebasing the docs.

@mwhooker
Copy link
Contributor

mwhooker commented Jun 5, 2017

hey @jeremy-asher, would you please email me at [email protected] when you get a chance? I want to talk about this PR a little bit

@jeremy-asher
Copy link
Contributor Author

Hey @mwhooker. Pinged you on mail. Do you need anything else on this?

@mwhooker
Copy link
Contributor

mwhooker commented Jun 12, 2017 via email

@jeremy-asher
Copy link
Contributor Author

@mwhooker I'm currently using this for two purposes:

One is to use the amazon-ebs builder to stand up an instance to run the amazon-chroot builder in. I don't need an AMI from the instance, so it saves time to immediately terminate the instance at the end instead of making AMIs I have to clean up or leave sitting around. I haven't wanted to migrate to a persistent instance due to the maintenance effort and the speed has been good enough for now.

The other use I have is for running test builds. I use the amazon-ebs builder to stand up an instance from an AMI I just built and I use the provision step to test that the instance works as expected. I don't need an AMI built from this either, so it saves time to throw it away at the end also.

Another use case that I was thinking of would be build an instance and use provisioners to produce a file artifact which is then extracted from the instance before terminating it. I don't have a specific use for that right now, but it seems like it would pair well with the artifice post-processor.

It would also be nice if artifice would output an AMI artifact instead of just a file since that could allow my first example to emit the actual AMI product from the inner build, but this isn't really necessary for my purposes.

@mwhooker
Copy link
Contributor

Going to discuss this a bit more, but it's not ready to go out in this release. We're going to be better about releasing every 4 weeks or so, so next release won't be too far away

@mwhooker mwhooker modified the milestones: v1.0.2, v1.0.1 Jun 19, 2017
@jen20
Copy link
Collaborator

jen20 commented Jun 19, 2017

@jeremy-asher worth noting that for your first use case you can use the EBS Surrogate builder instead - it was designed exactly for that use case. You can find an example of using it here.

For running tests, perhaps Terraform might be more appropriate?

@SwampDragons
Copy link
Contributor

I know there's been a lot of offline communication around this, and I believe that we've come down on solving the issue another way. Feel free to reopen if this isn't the case.

@patrickf55places
Copy link

@SwampDragons Could you share the solution? This could be handy for me as well (use case is testing packer configuration without actually creating an AMI).

@lorengordon
Copy link

I'm interested in the proposed solution. Posted my use case in the user group to see if anyone else has pointers on testing AMIs, https://groups.google.com/d/topic/packer-tool/Jj7yBpimlSY/discussion.

@jeremy-asher
Copy link
Contributor Author

For anyone else who runs into this issue, I'm going to be using Terraform to do the testing instead.

If you don't want to do that, this patch isn't necessary to do the workflow I described where your build system executes a second Packer EBS builder run after the first. Instead, you can configure a fixed name (test-image for example) and set force_deregister_image to true. The only disadvantages are that it will take a bit longer to run the build and you will have one image from your last test build sitting around at all times.

@lorengordon
Copy link

@jeremy-asher thanks, yeah, that's the approach i decided to take also (force_deregister_image).

@subbu11
Copy link

subbu11 commented Jul 4, 2018

@jeremy-asher @mwhooker

I am not able to find 'skip_register_ami' option in the documentation of ebs-chroot/ebs-surrogate.

I need to use it for skipping snapshot creation and ami creation.

Please help.

@cetex
Copy link

cetex commented Nov 8, 2018

If i understood this correct it allows us to skip snapshoting and creating an ami, thats great.

I think It should be possible on ebs builder as well as you may want to build a whole new system, and have a test which tests building a whole new system but not "committing it" to an ami.

@avdhoot07
Copy link

@jeremy-asher @mwhooker

I have similar use case. Can you please share the updated code/branch link for github. I clone this branch https://github.com/hashicorp/packer.git but it is not showing me the updated changes.
Thanks in advance.

@willthames
Copy link

The simplest way to achieve this is to just exit 1 or equivalent at the end of your provisioning step (I use ansible so I just have a - fail: task at the end of my provisioning playbook). If the provisioning step fails, no AMI is created.

@jerryjvl
Copy link

jerryjvl commented May 27, 2019

The down-side of the exit 1 approach is that the intentional failure is indistinguishable from a real failure elsewhere in the provisioning / testing process.

I use InSpec to validate the AMI state, which I want to be able to run on my PR branches, but without creation of an AMI artifact until it gets merged to master. If the InSpec fails, I want a normal Packer exit code to indicate this failure... but... I do not want my early exit to avoid creating an AMI to be treated as an error. I cannot see a way to achieve both these goals with this work-around.

Combined this with the fact that Packer does not propagate exit codes, or as far as I can tell provide any mechanism to explicitly control the exit code ... and this turns into a very poor work-around for real-world build pipelines.

@jerryjvl
Copy link

jerryjvl commented May 27, 2019

@SwampDragons -- is there a credible alternate work-around to distinguish intentional failures that should be suppressed in a Packer config from actual real failures?

Note, valid_exit_codes does not help in this case, because that once again suppresses the exit code within Packer, which is behaviour I want to leverage to avoid creating the actual AMI.

@ghost
Copy link

ghost commented Mar 28, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 28, 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.