This is a small demo showing the possibilities for creating and updating an AMI using Packer, CodePipeline, CodeBuild, Chef, and tested using Chef's InSpec.
Deploy the CloudFormation template cfn/pipeline.yml
. You'll need permissions on CloudFormation, EC2, IAM, S3, CodePipeline and CodeBuild. The following parameters are required:
- A GitHub username or org name (e.g. https://github.com/stelligent)
- A repository name
- The branch (e.g.
master
) - A GitHub OAuth Token with at least read access to the repository
Once the CloudFormation stack has deployed, the Pipeline will build a simple AMI with Nginx and a basic HTML file using Chef.
The pipeline accomplishes this by running the following tasks:
- Pull the latest version of the code from the repo/branch
- Validate the Packer template
packer/ami.json
- Build the AMI via Packer and Chef
packer/ami.json
packer/ami_params.json
cookbooks/nginx
- Launch a test instance with the newly built AMI
cfn/test-instance.yml
- Test the AMI using InSpec
test/inspec/test.rb
- Delete the test instance
- Publish the AMI by saving the AMI ID in an SSM Parameter called
/packerdemo/packer_ami_pipeline/LatestAMI
buildscripts/
Scripts used to configure test instancebuildspec/
CodeBuild BuildSpec YML filescfn/
CloudFormation templatescookbooks/
Chef Cookbooks used to configure Imagepacker/
Packer templates and parameter filestest/
InSpec tests