Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Packer, where DevOps begins

4,363 views

Published on

Packer 係 Vagrant 作者 Mitchell Hashimoto 的另一套作品,幫助人們在不同平台上建置相同的 machine image 或 container,可視作是 Continuous Integration 乃至Continuous Delivery 的起始點,亦是 Infrastructure-as-Code 中靠近圓心的一環。
本次分享將介紹 Packer 的適用情境,使用方法,以及 SPN 整合 Packer 進 CI/CD 的哲學與理念。

Published in: Software
  • Want to preview some of our plans? You can get 50 Woodworking Plans and a 440-Page "The Art of Woodworking" Book... Absolutely FREE ▲▲▲ http://t.cn/AidirSTh
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • GIVE HER A BIGGER PACKAGE THIS VALENTINE'S DAY ♣♣♣ https://tinyurl.com/yy3nfggr
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/y8nn3gmc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • There are over 16,000 woodworking plans that comes with step-by-step instructions and detailed photos, Click here to take a look  http://ishbv.com/tedsplans/pdf
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Packer, where DevOps begins

  1. 1. Packer, where DevOps begins Jeff Hung
  2. 2. @jeffhung • github.com/jeffhung • Works in Trend Micro – Hadoop infrastructure – Platform as-a Service • Experience – Runs agile/scrum 5 years – Runs DevOps 2 years
  3. 3. What is DevOps?
  4. 4. DevOps 是一種 92 共識, 認真就輸了。(誤?!)
  5. 5. Dev ♥ Ops Continuous Integration / Delivery Forever Stack DevOps could be…
  6. 6. Release Early, Release Often Fast Iteration
  7. 7. Forever Stack Tools Jenkin s New Relic Gangli a Nagios Cacti Gradle Ant Solan o Chef Ansible Puppet SaltStack Logstash Splunk PaperTrial NoSQL Balsamiq IaaS, PaaS Docker Selenium Every software runs on Operating System
  8. 8. Packer Workflow Build Provision Post- Process AWS EC2 VMware VirtualBox Docker … packer.jso n
  9. 9. Packer Workflow Build Provision Post- Process AWS EC2 VMware VirtualBox Docker … packer.jso n
  10. 10. packer.json { "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-9eaa1cf6", "instance_type": "t2.micro", "ssh_username": "ubuntu", "ami_name": "packer-example {{timestamp}}" }] } The variables section The builders section
  11. 11. The variables section { "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-9eaa1cf6", "instance_type": "t2.micro", "ssh_username": "ubuntu", "ami_name": "packer-example {{timestamp}}" }] } User Variables Calls the user function to get value Calls the env function to get value from environment variables. The env function is only valid within the variables section.
  12. 12. The builders section { "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-9eaa1cf6", "instance_type": "t2.micro", "ssh_username": "ubuntu", "ami_name": "packer-example {{timestamp}}" }] } Creates EBS-backed AMI by launching a source AMI and re-packaging it into a new AMI after provisioning. The source AMI Use timestamp function to make it unique The resulting AMI
  13. 13. $ packer build -var 'aws_access_key=YOUR ACCESS KEY' -var 'aws_secret_key=YOUR SECRET KEY' packer.json ==> amazon-ebs: amazon-ebs output will be in this color. ==> amazon-ebs: Creating temporary keypair for this instance... ==> amazon-ebs: Creating temporary security group for this instance... ==> amazon-ebs: Authorizing SSH access on the temporary security group... ==> amazon-ebs: Launching a secure AWS instance... ==> amazon-ebs: Waiting for instance to become ready... ==> amazon-ebs: Connecting to the instance via SSH... ==> amazon-ebs: Stopping the source instance... ==> amazon-ebs: Waiting for the instance to stop... ==> amazon-ebs: Creating the AMI: packer-example 1371856345 ==> amazon-ebs: AMI: ami-19601070 ==> amazon-ebs: Waiting for AMI to become ready... ==> amazon-ebs: Terminating the source AMI instance... ==> amazon-ebs: Deleting temporary security group... ==> amazon-ebs: Deleting temporary keypair... ==> amazon-ebs: Build finished. ==> Builds finished. The artifacts of successful builds are: --> amazon-ebs: AMIs were created: us-east-1: ami-19601070
  14. 14. Builders • Amazon EC2 (AMI) • DigitalOcean • Docker • Google Compute Engine (GCE) • OpenStack • Parallels • QEMU • VirtualBox • VMware Builders are responsible for creating machines and generating images from them for various platforms.
  15. 15. Packer Workflow Build Provision Post- Process AWS EC2 VMware VirtualBox Docker … packer.jso n
  16. 16. Customize with provisioners { "variables": {…}, "builders": […], "provisioners": [{ "type": "shell", "script": "./scripts/install-puppet.sh” }, { "type": ”puppet-masterless", "manifest_file": "puppet/manifest/site.pp", "module_paths": [ "puppet/modules" ], "hiera_config_path": "puppet/hiera.yaml” }] } Provisioners are executed one by one. 1 2
  17. 17. Install puppet agent { "variables": {…}, "builders": […], "provisioners": [{ "type": "shell", "script": "./scripts/install-puppet.sh” }, { "type": ”puppet-masterless", "manifest_file": "puppet/manifest/site.pp", "module_paths": [ "puppet/modules" ], "hiera_config_path": "puppet/hiera.yaml” }] } Provision machines using shell scripts Usually we will reuse these scripts in different kinds of machines.
  18. 18. Provision with puppet scripts { "variables": {…}, "builders": […], "provisioners": [{ "type": "shell", "script": "./scripts/install-puppet.sh” }, { "type": ”puppet-masterless", "manifest_file": "puppet/manifest/site.pp", "module_paths": [ "puppet/modules" ], "hiera_config_path": "puppet/hiera.yaml” }] } No need for a puppet server Manifests, modules, and hiera data can all be stored in git.
  19. 19. Provisioners Templates to install and configure software within running machines prior to turning them into machine images. • Remote Shell • Local Shell • File Uploads • PowerShell • Windows Shell • Ansible • Chef Client/Solo • Puppet Masterless/Server • Salt • Windows Restart
  20. 20. Packer Workflow Build Provision Post- Process AWS EC2 VMware VirtualBox Docker … packer.jso n
  21. 21. Local Repository Packaging and Publishing After the machine is built, we would like to: • Package as a zip-ball for local use • Package as Vagrant Box and publish on Atlas • Preserve Vagrant Box in Local Machin e Built Compres s Package Publish Atlas Foo.zip Foo.box
  22. 22. { … "post-processors": [{ "type": "compress", "output": "{{.BuildName}}-{{isotime "20060102"}}.zip" }, [{ "type": "vagrant", "output": "{{.BuildName}}-{{isotime "20060102"}}.box" }, { "type": "atlas", "token": "{{user `atlas_token`}}", "artifact": "trendmicro/centos62", "artifact_type": "virtualbox", "keep_input_artifact": true }]] } Post-Processor Chains Package as a zip- ball for local use Package as Vagrant Box and publish on Atlas
  23. 23. { … "post-processors": [{ "type": "compress", "output": "{{.BuildName}}-{{isotime "20060102"}}.zip" }, [{ "type": "vagrant", "output": "{{.BuildName}}-{{isotime "20060102"}}.box" }, { "type": "atlas", "token": "{{user `atlas_token`}}", "artifact": "trendmicro/centos62", "artifact_type": "virtualbox", "keep_input_artifact": true }]] } Compress into Single Archive Go-style date format Compression format auto-inferred from extension
  24. 24. { … "post-processors": [{ "type": "compress", "output": "{{.BuildName}}-{{isotime "20060102"}}.zip" }, [{ "type": "vagrant", "output": "{{.BuildName}}-{{isotime "20060102"}}.box" }, { "type": "atlas", "token": "{{user `atlas_token`}}", "artifact": "trendmicro/centos62", "artifact_type": "virtualbox", "keep_input_artifact": true }]] } Sequence definition Publish Vagrant Box Preserve the vagrant box packaged in previous step Preserve Vagrant Box in Local
  25. 25. Post-Processors The post-processor section configures any post-processing that will be done to image built by the builders. • compress • vSphere • Vagrant • Vagrant Cloud • Atlas • docker-import • docker-push • docker-save • docker-tag
  26. 26. What Else Do You Need? • Kickstart – Use kickstart file to install Linux from ISO • chef/bento – Vagrant Box Packer definitions by Chef – Published on Atlas: https://atlas.hashicorp.com/chef • Windows – Windows Automated Installation Kit (AIK) – Unattended Windows Setup
  27. 27. Pets Cattles Pets vs. Cattles • Ticket-based • Handcrafted • Scale-up • Smart Hardware • Self-Service • Automated • Scale-out • Smart Apps
  28. 28. Jenkins Cattles Workflow Base.jso n Std.json Win.json Code Dev Dev.box YUM repo RPM Web.jso n App.json … DB.json Image repo Web.box App.box … DB.box Win7.bo x … Win8.bo x AWS Build RPM Build Imag e Deploy App Tower Playbook
  29. 29. Jenkins SPN (Pets) Flow Base.jso n Std.json Win.json Code Dev Dev.box YUM repo RPM Win7.bo x … Win8.bo x DC / AWS Build RPM Deploy App Puppet Manifest To Docker or not?
  30. 30. What is Your Flow? • You need to define your DevOps flow • No need to build Rome in one day • Consider company culture • Tool adoption
  31. 31. Summary • DevOps  Fast Iteration • Packer as the starting point • Builders  Provisioners  Post- Processors • Pets or Cattle? • Define Your DevOps Workflow
  32. 32. THANK YOU!
  33. 33. Alternative Format? But we needs comments to add annotations and disable entire experimental blocks... It is one of the primary reason we choose JSON as the configuration format: it is highly convenient to write a script to generate the configuration. @mitchellh .SUFFIXES: .json .yml .yml.json: ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' < $< > $@; https://github.com/mitchellh/packer/issues/ 887

×