14
Packer by Hashicorp

Packer by HashiCorp

Embed Size (px)

Citation preview

Page 1: Packer by HashiCorp

Packer by Hashicorp

Page 2: Packer by HashiCorp

Agenda● Packer - overview● Advantages● Use cases● Supported platforms● Workflow - Build, Provision & Post Process ● Demo

Page 3: Packer by HashiCorp

Packer is a tool for creating machine and container images for multiple platforms from a single source configuration.

A machine image is a single static unit that contains a pre-configured operating system and installed software which is used to quickly create new running machines.

Packer only builds images. It does not attempt to manage them in any way. After they're built, it is up to you to launch or destroy them.

Packer

Page 4: Packer by HashiCorp

Advantages of using :

● Super fast infrastructure deployment - Packer images allow you to launch completely provisioned and configured machines in seconds. This benefits not only production, but development as well.

● Multi-provider portability - Packer creates identical images for multiple platforms, you can run production in AWS, staging/QA in a private cloud like OpenStack, and development in desktop virtualization solutions such as VMware or VirtualBox. Each environment is running an identical machine image, giving ultimate portability.

● Improved stability - Packer installs and configures all the software for a machine at the time the image is built. If there are bugs in these scripts, they'll be caught early, rather later when a machine is launched.

● Greater testability - After a machine image is built, that machine image can be quickly launched and smoke tested to verify that things appear to be working. If they are, you can be confident that any other machines launched from that image will function properly.

Packer

Page 5: Packer by HashiCorp

● Continuous Delivery - Add Packer in the middle of your continuous delivery pipeline. It can be used to generate new machine images for multiple platforms on every change to Chef/Puppet. As part of this pipeline, the newly created images can then be launched and tested, verifying the infrastructure changes work. If the tests pass, you can be confident that the image will work when deployed. This brings a new level of stability and testability to infrastructure changes.

● Dev/Prod Parity - Packer helps keep development, staging, and production as similar as possible. Packer can be used to generate images for multiple platforms at the same time. So if you use AWS for production and Docker for development, you can generate both an AMI and a VMware machine using Packer at the same time from the same template. Mix this in with the continuous delivery use case above, and you have a pretty slick system for consistent work environments from development all the way through to production.

● Appliance/Demo Creation - Since Packer creates consistent images for multiple platforms in parallel, it is perfect for creating appliances and disposable product demos. As your software changes, you can automatically create appliances with the software pre-installed. Potential users can then get started with your software by deploying it to the environment of their choice. Packaging up software with complex requirements has never been so easy.

Use cases

Page 6: Packer by HashiCorp

Supported Platforms

● Amazon EC2 (AMI)● CloudStack● OpenStack● DigitalOcean● Docker● Google Compute Engine● Parallels● QEMU● VirtualBox (OVF)● VMware (VMX)

You can add support to any platform by extending Packer by plugins [2].

Page 7: Packer by HashiCorp

Workflow

Page 8: Packer by HashiCorp

Workflow - terminology

● Templates: JSON files containing the build information● Builders: Platform specific building configuration● Provisioners: Tools that install software after the initial OS

install● Post-processors: Actions to happen after the image has been

built

Page 9: Packer by HashiCorp

{

"variables": {

"aws_access_key": "{{env `AWS_ACCESS_KEY`}}",

"aws_secret_key": "{{env `AWS_SECRET_KEY`}}"

},

"builders": [{

"type": "amazon-ebs",

"access_key": "{{user `aws_access_key`}}",

"secret_key": "{{user `aws_secret_key`}}",

"region": "us-east-1",

"source_ami": "ami-fce3c696",

"instance_type": "t2.micro",

"ssh_username": "admin",

"ami_name": "yourApp {{timestamp}}"

}]

}

Validate -> packer validate packer.json

Packer can create multiple images for multiple platforms in parallel, all configured from a single template [8].

Workflow - Build

Page 10: Packer by HashiCorp

● Via Command line using -var flag

> packer build

-var ‘aws_access_key=Secret

-var ‘aws_secret_key=Secret2

packer.json

● Via File with -var-file flag

{

"aws_access_key": "accessKey",

"aws_secret_key": "secretKey"

}

> packer build -var-file=variables.json packer.json

Var-file flag can be specified multiple times and variables from multiple files will be read and applied. Combining the the -var and -var-file flags together also works how you'd expect. Flags set later in the command override flags set earlier.

Workflow - Build & Variables

Page 11: Packer by HashiCorp

{

"variables": ["..."],

"builders": ["..."],

"provisioners": [{

"type": "shell",

"inline": [

"sleep 30", --waiting for SSH to be available

"sudo apt-get update",

"sudo apt-get install -y redis-server"

]

}, {

"type": "shell",

"script": "./scripts/install-java.sh",

}]

}

Others - Remote shell, File uploads, Ansible (local & remote), Chef, Puppet, Salt, PowerShell etc.

Workflow - Provision

Page 12: Packer by HashiCorp

{

"variables": "...",

"builders": ["..."],

"provisioners": ["..."],

"post-processors": [

{

"type": "compress",

"format": "tar.gz"

}

]

}

Others - Amazon Import, CheckSum, Docker Push/Tag/Save, Google Compute Export, Vagrant, vSphere etc.

Workflow - Post Process

Page 13: Packer by HashiCorp

Demo

Page 14: Packer by HashiCorp

Thanks!Any questions ?

Thank you http://www.slidescarnival.com for layout!

References :1. https://www.packer.io2. https://www.packer.io/docs/extend/builder.html3. https://www.packer.io/docs/builders/virtualbox-iso.html4. https://www.packer.io/docs/builders/amazon.html5. https://www.packer.io/docs/builders/docker.html6. https://www.packer.io/intro/getting-started/build-image.html7. https://www.packer.io/intro/getting-started/provision.html8. https://www.packer.io/intro/getting-started/parallel-builds.html9. https://www.packer.io/docs/templates/user-variables.html

10. https://www.packer.io/docs/templates/post-processors.html11. https://github.com/chef/bento12. http://blog.deimos.fr/2015/01/16/packer-build-multiple-images

-easily/13. http://kappataumu.com/articles/creating-an-Ubuntu-VM-with-

packer.html