Packer で自分だけの Raspberry Pi イメージを 作った話 / #techstudygroupjp 2020.5.14

Packer で自分だけの Raspberry Pi イメージを 作った話 / #techstudygroupjp 2020.5.14

73d315414e4025bddfb98bd6fb24ad04?s=128

さたけ

May 14, 2020
Tweet

Transcript

  1. PackerͰࣗ෼͚ͩͷ Raspberry PiΠϝʔδΛ ࡞ͬͨ࿩ ͚ͨ͞ #techstudygroupjp 2020.5.14

  2. ࣗݾ঺հ • ಩খ຀ߴઐ 3೥ ৘ใܥ
 ࠤ஛ ߤر • WebϑϩϯτɾόοΫΤϯυ ΠϯϑϥͳͲ͍Ζ͍Ζ…

    @satakenkoki ࡳຈ ಩খ຀
  3. Raspberry Pi • ͍҆: ຊମ͸5000ԁ͙Β͍ • ిؾ୅΋͍҆: 
 24࣌ؒىಈͯ͠΋ɺ਺ඦԁ /

    ݄ ࣗ୐αʔόʹ࠷ద!!
  4. Raspberry Pi • SDΧʔυʹ௚઀OSΛॻ͖ࠐΉ • ΠϯετʔϥΛ࢖Θͳͯ͘OK microSDΧʔυ

  5. RasPiͷΠϝʔδΛ࡞Δํ๏ 1 • Ұ౓Raspberry PiΛىಈͯ͠ɺ؀ڥߏங • SDΧʔυΛΠϝʔδͱͯ͠PCʹอଘ͢Δ • όοΫΞοϓͱಉ͡!!

  6. RasPiͷΠϝʔδΛ࡞Δํ๏ 2 • Raspberry Pi ͷΤϛϡϨʔλΛPC্Ͱɺ
 ىಈɺ؀ڥߏஙɻ
 • ΤϛϡϨʔλΛγϟοτμ΢ϯ͢Ε͹
 Πϝʔδͷ׬੒

  7. ΰʔϧσϯΠϝʔδ • Ϋϥ΢υΛ࢖͏ͱ͖ʹΑ͘࢖ΘΕΔ΍Γํ • ࣄલʹ؀ڥߏஙΛߦͬͨΠϝʔδΛ࡞Δ • ؀ڥߏஙΛऴΘΒͤͨΠϝʔδ͔Β
 Ծ૝ϚγϯΛىಈ͢Δ

  8. ؀ڥߏஙͷޙɺʮӡ༻ʯ͕͋Δ • ී௨ͷαʔόͷӡ༻Ͱ͸
 ΞοϓσʔτͳͲͷมߋΛՃ͍͑ͯ͘ • ʮ࠷ॳͷߏங͕ࡁΊ͹ऴΘΓʯͰ͸ͳ͍

  9. ؀ڥߏஙͷޙɺʮӡ༻ʯ͕͋Δ • ී௨ͷαʔόͷӡ༻Ͱ͸
 ΞοϓσʔτͳͲͷมߋΛՃ͍͑ͯ͘ • ʮ࠷ॳͷߏங͕ࡁΊ͹ऴΘΓʯͰ͸ͳ͍ • ه࿥Λ࢒͓͔ͯ͠ͳ͍ͱɺ
 ࠓͷঢ়ଶ͕Θ͔Βͳ͘ͳͬͯ͠·͏
 ࣗ෼ͻͱΓ͚ͩͳΒ·ͣϝϞ͢Δ͜ͱ͸ͳ͍

  10. ؀ڥߏஙͷޙɺʮӡ༻ʯ͕͋Δ • खݩͷ։ൃ؀ڥͰ͸ಈ͚͘Ͳɺ
 αʔόͰͷಈ࡞͕͓͔͍͠ͱ͔…… • ؀ڥΛ࠶ݱ͢Δͱ͖ɺه࿥ΛཔΓʹ
 ਓͷखͰ࡞ۀ͠ͳ͍ͱ͍͚ͳ͍

  11. Immutable Infrastructure • ΰʔϧσϯΠϝʔδͷൃలܗ • Ұ౓ΠϝʔδΛ࡞ͬͨΒɺ
 αʔόʹ͸खΛՃ͑ͳ͍ͱ͍͏ϙϦγʔ • ߋ৽͕ඞཁͳΒҰ͔Β࡞Γ௚͢

  12. Ұ͔Β࡞Δ ΊΜͲ͍͘͞ͷͰ͸

  13. Ұ͔Β࡞Δ ΊΜͲ͍͘͞ͷͰ͸

  14. ࣗಈԽ͠Α͏ Infrastructure as Code ͱݴͬͨΓ͠·͢

  15. ࣗಈԽ͠Α͏ Infrastructure as Code ͱݴͬͨΓ͠·͢

  16. None
  17. Packer • Πϝʔδ࡞੒ͷࣗಈԽπʔϧ • ެࣜͰ͸ɺAWS΍VirtualBoxͷ
 Πϝʔδͷ࡞੒ʹରԠ͍ͯ͠Δ • ͦΕͧΕ͸ϓϥάΠϯͱ࣮ͯ͠૷͞Ε͍ͯΔ • Raspberry

    PiʹରԠͨ͠ϓϥάΠϯ͕ɺ
 GitHub ʹެ։͞Ε͍ͯΔ
  18. solo-io/packer-builder-arm-image • ArmΠϝʔδΛ࡞ΔͨΊͷ
 PackerϓϥάΠϯ • QEMUΛ࢖ͬͯArmͷԾ૝؀ڥΛ࡞͍ͬͯΔ

  19. PackerͰΠϝʔδΛ࡞Δʹ͸? • PackerΛΠϯετʔϧ͢Δ • packer-builder-arm-image ͱ 
 ͦͷґଘύοέʔδΛΠϯετʔϧ
 (Docker ΍

    Vagrant Ͱ΋Ͱ͖Δ) • JSONΛॻ͘ʂ
  20. JSONͷॻ͘ { "builders": [ { "type": "arm-image", "iso_url" : "file:///build/2020-02-13-raspbian-buster-lite.zip",

    "iso_checksum_type":"sha256", "iso_checksum": "12ae6e17bf95b6ba83beca61e7394e7411b45eba7e6a520f434b0748ea7370e8", "target_image_size": 4294967296 } ], "provisioners": [ { "type": "shell", "inline": [ "systemctl enable ssh”, "mkdir /home/pi/.ssh && chmod 644 /home/pi/.ssh", "curl -o /home/pi/.ssh/authorized_keys https://github.com/satackey.keys” ] } ] } ԿͷΠϝʔδΛ ࡞Δͷ͔(builder) ԿΛ࣮ߦ͢Δͷ͔ (provisioner)
  21. JSONͷॻ͘ { "builders": [ { "type": "arm-image", "iso_url" : "file:///build/2020-02-13-raspbian-buster-lite.zip",

    "iso_checksum_type":"sha256", "iso_checksum": "12ae6e17bf95b6ba83beca61e7394e7411b45eba7e6a520f434b0748ea7370e8", "target_image_size": 4294967296 } ], "provisioners": [ { "type": "shell", "inline": [ "systemctl enable ssh”, "mkdir /home/pi/.ssh && chmod 644 /home/pi/.ssh", "curl -o /home/pi/.ssh/authorized_keys https://github.com/satackey.keys” ] } ] } ϕʔεʹͳΔΠϝʔδͷ ύεΛࢦఆʢURL΋OKʣ
  22. JSONͷॻ͘ { "builders": [ { "type": "arm-image", "iso_url" : "file:///build/2020-02-13-raspbian-buster-lite.zip",

    "iso_checksum_type":"sha256", "iso_checksum": "12ae6e17bf95b6ba83beca61e7394e7411b45eba7e6a520f434b0748ea7370e8", "target_image_size": 4294967296 } ], "provisioners": [ { "type": "shell", "inline": [ "systemctl enable ssh", "mkdir /home/pi/.ssh && chmod 644 /home/pi/.ssh", "curl -o /home/pi/.ssh/authorized_keys https://github.com/satackey.keys" ] } ] } SSH Λ༗ޮԽ ࣗ෼ͷSSHެ։伴Λ GitHub͔Βμ΢ϯϩʔυ
  23. ΠϝʔδΛ࡞Δ $ packer build ssh_key.json output-arm-image ʹ Πϝʔδ͕Ͱ͖͍ͯΔ ͜ΕΛSDΧʔυʹॻ͖ࠐΜͰ׬੒ʂ

  24. Provisioner • ྫ͸ Shell Λಈ͔͢΋ͷͰ͕ͨ͠ɺ
 ͦͷ΄͔ʹ͜Μͳ͜ͱ΋Ͱ͖·͢ʂ • ϑΝΠϧͷίϐʔ • JSON௚ॻ͖ΛͤͣγΣϧεΫϦϓτΛ࣮ߦ

    • AnsibleͳͲΛ࣮ߦ
  25. PackerͰࣗ෼͚ͩͷ Raspberry PiΠϝʔδΛ ࡞ͬͨ࿩ ͚ͨ͞ #techstudygroupjp 2020.5.14

  26. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠!