Testing Packer-Provisioner Outcomes

597 views
Skip to first unread message

Ross Niemi

unread,
Nov 27, 2013, 8:42:59 AM11/27/13
to packe...@googlegroups.com
Hi All,

What I would like to do is only build AMIs/Vagrant Boxes providing that the provisioned VM (during the Packer provisioning step) has passed a suite of tests (whether it be chefspec, serverspec, cucumber, etc.).  Ideally these tests should only execute right after the last provisioning step and just before any post-processing is done.  It appears to me that the current Packer configuration doesn't have a formal "certification" or "verification" construct.  

What have people found to be the best way to test their packer-provisioned VMs before their AMI/Vagrant Boxes are created?

* Have a shell provisioner call your test suite in the last step of the provisioners section?
* Have a custom provisioner call your test suite? (and have it as the last step in the provisioners section)
* Have a custom post-processor call your test suite? (and have it as the first step in the post-processing section)
* Other options?

Thanks!

-- Ross

Gareth Rushgrove

unread,
Jan 1, 2014, 10:21:23 AM1/1/14
to packe...@googlegroups.com
I'd be thinking about the same problem and have found the shell provisioner and serverspec to work. Here's a simple example:


Gareth
 
Thanks!

-- Ross

Ross Niemi

unread,
Mar 19, 2014, 9:09:02 AM3/19/14
to packe...@googlegroups.com
Thanks Gareth. I must have missed your update to this thread earlier -- sorry.

I'm starting to look into this problem again and (coincidentally) I came across your github repo before coming back here on instinct :)

I'll give your example a try.  Thanks for sharing!

-- Ross

Aaron Walker

unread,
Jan 8, 2015, 12:30:12 AM1/8/15
to packe...@googlegroups.com
Hi,

I'm facing a similar situation...

The only problem with using the provisioner approach is that serverspec test run on the instance directly rather than from the client running packer. This means the image being built needs to have the tools chain (ruby etc) required to run serverspec even though it might not part of the image.

Ideally packer would expose a mechanism to perform a verification step prior to taking an image in which we would execute our test scripts and fail the build.

I'm looking at writing a custom provisioner which allows scripts to be executed locally rather than on the remote hosts it would look something like

{
  "type": "shell-local",
  "inline": [
    "bundle install",
    "rake test"
  ] 
}

but it still feels like a hack. A customizable verification hook would be much better.


cheers

Aaron
Reply all
Reply to author
Forward
0 new messages