Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20130727 Packerの紹介 (Python Developers Festa 2013.07)

ymotongpoo
August 02, 2013

20130727 Packerの紹介 (Python Developers Festa 2013.07)

introducing packer, mentioning installation, usage and extension.

ymotongpoo

August 02, 2013
Tweet

More Decks by ymotongpoo

Other Decks in Technology

Transcript

  1. ࢁޱೳ᫫
    id : ymotongpoo
    1
    1BDLFSͷ঺հ
    1ZUIPO%FWFMPQFST'FTUB

    View full-size slide

  2. ͓લɺ୭Αʁ
    •  ࢁޱೳ᫫ʢ΍·͙ͪΑ͠;Έʣ
    •  :PV5VCF5FDIOJDBM"DDPVOU.BOBHFS
    (PPHMF*OD
    •  JEZNPUPOHQPP
    –  ͱΜ΀ʔͱݺ͹Ε͍ͯ·͢
    •  :"."(6$)*XFCMPH
    –  ZNPUPOHQPPIBUFOBCMPHDPN
    2

    View full-size slide

  3. ͓લɺ୭Αʁ
    •  (P͕޷͖Ͱ͢
    •  (P$POGFSFODFͱ͍͏ΠϕϯτΛ͠·ͨ͠
    •  Թઘʹߦ͘ʮ(PཏԹઘʯͱ͍͏ԹઘاըΛ͠·
    ͨ͠
    •  ઌ೔͸౎ిߥ઒ઢΛି͠੾ͬͨʮిंͰ(Pʯ
    ͱ͍͏ΠϕϯτΛ͠·ͨ͠
    3

    View full-size slide

  4. ͓લɺ୭Αʁ
    4

    View full-size slide

  5. ཱྀͷࢥ͍ग़
    5

    View full-size slide

  6. "HFOEB
    •  1BDLFSͬͯφχʁ
    •  1BDLFSΛ࢖ͬͯΈΔ
    •  1BDLFSΛ֦ுͯ͠ΈΔ

    6

    View full-size slide

  7. 7

    ͬͯφχʁ

    View full-size slide

  8. 1BDLFSͬͯφχʁ
    •  7BHSBOUͷ࡞ऀ.JUDIFMM)BTIJNPUP࡞
    •  (P੡
    •  ʹWFSTJPOެ։
    –  ൃද࣌࠷৽൛͸
    •  ެࣜαΠτ
    –  http://www.packer.io  

    8

    View full-size slide

  9. 10
    Packer is a tool for creating identical
    machine images for multiple platforms
    from a single source configuration.
    Platform A
    Platform B
    Platform C
    Machine
    Image A
    Machine
    Image B
    Machine
    Image C

    View full-size slide

  10. 11
    ͦΕͬͯ
    7BHSBOUͱ͔
    'BCSJDͱ͔ͱ
    φχ͕ҧ͏ͷʁ

    View full-size slide

  11. ֤ϓϩϏδϣχϯάπʔϧͱͷҧ͍
    12
    OS distribution
    pkg
    pkg
    7BHSBOU΍'BCSJD͸جຊతͳ04Πϝʔδͷ্ʹ
    ઃఆΛߦ͏
    •  パッケージのインストール
    •  設定ファイルのコピー
    •  スクリプトの実行
    etc…
    file
    script
    Machine Image

    View full-size slide

  12. ֤ϓϩϏδϣχϯάπʔϧͱͷҧ͍
    13
    1BDLFS͸ͦ΋ͦ΋ͷϚγϯΠϝʔδΛ࡞੒
    Packer
    config
    Packer
    OS distribution
    Machine Image A
    OS distribution
    Machine Image B

    View full-size slide

  13. 7FFXFFͱ͸φχ͕ҧ͏ͷʁ
    •  7FFXFFͱ΍ͬͯΔ͜ͱ͸͍ۙ
    –  7FFXFF͸7JSUVBM#PY 7.XBSF'VTJPO ,7.
    1BSBMMFMTΛ࡞ΕΔ
    –  ֦ͨͩ͠ுػߏ͸ͳ͍
    –  ϓϩϏδϣχϯά͸7BHSBOUݶఆ
    14

    View full-size slide

  14. ݱঢ়ରԠϓϥοτϑΥʔϜ
    15

    View full-size slide

  15. 16
    1BDLFSΛ࢖ͬͯΈΔ

    View full-size slide

  16. Πϯετʔϧ
    17
    $  wget  http://path/to/packer.binary.zip  
    $  unzip  packer.binary.zip    

    View full-size slide

  17. Πϯετʔϧ
    (P੡ͳͷͰ֤؀ڥ༻ͷόΠφϦΛ࢖͑͹ྑ͍
    19
    http://www.packer.io/downloads.html

    View full-size slide

  18. ઃఆϑΝΠϧ
    •  ઃఆϑΝΠϧ͸+40/ܗࣜͰهड़
    •  (PͷUFYUUFNQMBUFʹ४ڌͯ͠ɺม਺ΛຒΊࠐ
    Ή͜ͱ΋Մೳ
    •  ཁૉ͸ͭ
    –  CVJMEFSTԾ૝ϚγϯΛ࡞੒͢ΔΠϯϑϥͷࢦఆ
    –  QSPWJTJPOFSTϏϧυ׬ྃޙͷ؆୯ͳϓϩϏδϣχϯ
    ά
    –  QPTUQSPDFTTPSTϓϩϏδϣχϯά׬ྃޙͷॲཧ

    20

    View full-size slide

  19. ઃఆϑΝΠϧ
    {  
       "builders":  [{  
           "type":  "amazon-­‐ebs",  
           "access_key":  "YOUR  KEY  HERE",  
           "secret_key":  "YOUR  SECRET  KEY  HERE",  
           "region":  "us-­‐east-­‐1",  
           "source_ami":  "ami-­‐de0d9eb7",  
           "instance_type":  "t1.micro",  
           "ssh_username":  "ubuntu",  
           "ami_name":  "packer-­‐example  {{.CreateTime}}"  
       }],  
       “provisoners”:  [  
           “type”:  “shell”,  
           “scripts”:  [  
               “initial-­‐install.sh”  
           ]  
       ],  
       “post-­‐prosessors”:  [{  
           “type”:  “compress”,  
           “format”:  “tar.gz”  
       }]  
    }  
    21

    View full-size slide

  20. ࣮ߦ͢Δ
    22
    $  packer  validate  
    $  packer  build  config.json    

    View full-size slide

  21. ςοςϨʔ
    23

    View full-size slide

  22. 24
    1BDLFSΛ֦ுͯ͠ΈΔ

    View full-size slide

  23. 1BDLFS1MVHJOT
    •  packerίϚϯυ͸ඪ४Ͱ΋ϓϥάΠϯΛୟ͍ͯ
    ͍Δ  

    25
    $  ls  
    packer  
    packer-­‐builder-­‐amazon-­‐ebs  
    packer-­‐builder-­‐digitalocean  
    packer-­‐builder-­‐virtualbox  
    packer-­‐builder-­‐vmware  
    packer-­‐command-­‐build  
    packer-­‐command-­‐fix  
    packer-­‐command-­‐validate  
    packer-­‐post-­‐processor-­‐vagrant  
    packer-­‐provisioner-­‐file  
    packer-­‐provisioner-­‐shell  
    શ෦ϓϥάΠϯ

    View full-size slide

  24. 1BDLFS1MVHJOT
    •  ϓϥάΠϯͷ࡞੒͸(PͰͷΈ࡞੒Մೳ
    –  ֤ͨͩ͠ϓϥάΠϯ͸ಠཱͨ͠ίϚϯυͱͯ͠࡞੒
    –  ໋໊نଇ͸packer-­‐TYPE-­‐NAME  
     


    QBDLFSCVJMEFSBNB[POFCT
    QBDLFSDPNNBOEWBMJEBUF

    26

    View full-size slide

  25. 1BDLFS1MVHJOT
    •  ֦ுΛ௥Ճͨ͠Β$HOME/.packerconfig  ʹ௥
    Ճͷ֦ுΛॻ͍͓ͯ͘  
    –  ઈରύε  or  ૬ରύε  or  PATH͕௨͍ͬͯΔͱ͜Ζ  
    –  ඪ४ίϚϯυ΋ಉܗࣜͰϋʔυίʔυ͞Ε͍ͯΔ  
    27
    {  
       "builders":  {  
           "custom-­‐cloud":  "packer-­‐builer-­‐custom-­‐cloud"  
       },  
       "commands":  {  
           "spam":  "packer-­‐command-­‐spam",  
     "egg":  "packer-­‐command-­‐egg"  
       }  
    }  

    View full-size slide

  26. 1BDLFSશମͷίʔυߏ੒
    28
    packerίϚϯυ
    buildersͰݺ͹ΕΔඪ४֦ு܈
    post-­‐processorsͰݺ͹ΕΔඪ४֦ு܈
    provinoersͰݺ͹ΕΔඪ४֦ு܈
    packerͰݺ͹ΕΔඪ४֦ு܈
    ͍͚ͭͩ͜ݟΕ͹ྑ͍
    ඪ४֦ு܈ͷNBJOHP

    View full-size slide

  27. 1BDLFSશମͷίʔυߏ੒
    •  ύοέʔδͩͱҎԼͷͭ
    •  QBDLFSQBDLFS
    –  1BDLFSͷίΞɾ֦ு։ൃͷͨΊͷύοέʔδ
    •  QBDLFSQBDLFSQMVHJO
    –  ϓϥάΠϯ֦ுͷJOUFSGBDFͷఆٛͷΈ
    29
    github.com/mitchellh/packer/packer  
     
    github.com/mitchellh/packer/packer/plugin  

    View full-size slide

  28. #VJMEFSͷ֦ு
    30
    Packer Plugins
    type  Builder  interface  {  
           Prepare(...interface{})  error  
           Run(ui  Ui,  hook  Hook,  cache  Cache)  (Artifact,  error)  
           Cancel()  
    }  
    •  1SFQBSF
    ઃఆϑΝΠϧͷಡΈࠐΈͱલॲཧ
    –  ͍͍ͨͯ͸map[string]interface{}  Ͱ౉͞ΕΔ  
     
    •  3VO
    ϚγϯΠϝʔδͷ࡞੒Λߦ͏
    –  Artifact  JOUFSGBDFΛ࣮૷ͨ͠TUSVDUʹϚγϯΠϝʔδʢͷϝλσʔλʣ

    •  $BODFM
    $USMDͳͲ͕ԡ͞Εͨ࣌ͷޙॲཧ

    View full-size slide

  29. $PNNBOEͷ֦ு
    31
    Packer Plugins
    type  Command  interface  {  
           Help()  string  
           Run(env  Environment,  args  []string)  int  
           Synopsis()  string  
    }  
    •  )FMQ
    packer  COMMAND  -­‐-­‐helpͰग़ྗ͞ΕΔϝοηʔδ
    •  3VO
    ࣮ࡍͷίϚϯυͷ࣮ߦ
    –  ىಈதͷ1BDLFSͷ΄΅͢΂ͯͷ৘ใΛͱΕΔ
    •  CVJMEFS 6* $BDIF QPTUQSPDFTTPS QSPWJTJPOFS
    •  4ZOPQTJT
    packer  -­‐-­‐helpͰग़ྗ͞ΕΔ୹͍ϝοηʔδ  
    –  50จࣈఔ౓  

    View full-size slide

  30. ͦͷଞͷ֦ு
    •  QPTUQSPDFTTPS
    •  QSPWJTJPOFS
    –  QSPWJTPOFSͷϑοΫ͸CVJMEFSଆͷ֦ுͰ࣮૷͢Δඞ
    ཁ͕͋Δ
    32
    Packer Plugins
    ࠓճ͸ॏཁ͡Όͳ͍ͷͰলུ

    View full-size slide

  31. 34
    Packer is a tool for creating identical
    machine images for multiple platforms
    from a single source configuration.
    Platform A
    Platform B
    Platform C
    Machine
    Image A
    Machine
    Image B
    Machine
    Image C

    View full-size slide

  32. ·ͱΊ
    •  ϓϩϏδϣχϯάΛޠΔલʹɺϚγϯΠϝʔδ
    ͷ͜ͱΛߟ͑Α͏
    •  ֦ு΋࡞ΕΔͷͰɺࣾ಺؀ڥ༻ʹ΋֦ு͕࡞Ε
    ͯΑ͍
    •  (P͸ྑ͍
    –  ඪ४ͷ+40/ύʔαΦϓγϣϯύʔαɺόΠφϦ഑

    35

    View full-size slide