Fabric を導入した話

Fabric を導入した話

9d3843095a200625dc8ee739e2c19987?s=128

shinichi yamaguchi

April 15, 2016
Tweet

Transcript

  1. FabricΛಋೖͨ͠࿩ Yamaguchi Shinichi 2016 / 04 / 15 #osakapy ࠓߋײ΋


    ͋Γ·͕͢
  2. “ࣗݾ঺հ”

  3. ࣗݾ঺հ

  4. ΤϯδχΞྺ • ʙ5೥໨: PGɻ Cɺ.NetɺJavaɺColdfusionɺ AS400ɺPHPͱ͔ • ʙ10೥໨: PG &

    PMɻ ओʹPHPɺ͍ͪͬ͞αΠτ͍ͬ ͺ͍࡞ͬͨΓ • ʙ13೥໨: Ϣʔβʔاۀʹస৬ɻݩʹ໭ͬͯPGɻ Python ͱ͔ Fabric ͱ͔ Docker ͱ͔
  5. “ΞδΣϯμ”

  6. ΞδΣϯμ 1. Fabric ʹ͍ͭͯ 2. Infrastructure as Code ʹ͍ͭͯ 3.

    Fabric Λಋೖͨ͠࿩ 4. ·ͱΊ
  7. “Fabric ʹ͍ͭͯ”

  8. http://www.fabfile.org

  9. Fabric ͱ͸ • Python ੡ͷσϓϩΠؔ܎ͷϥΠϒϥϦ͕๛෋ͳίϚ ϯυϥΠϯπʔϧ • SSH Ͱର৅αʔόʹϩάΠϯͯ͠͝ʹΐ͝ʹΐ͢Δ

  10. http://dekokun.github.io/posts/2013-05-21.html

  11. Fabric ͷϝϦοτ • ബ͍ϑϨʔϜϫʔΫ • ֶशίετ͕௿͍

  12. “Infrastructure as Code ʹ͍ͭͯ”

  13. http://d.hatena.ne.jp/naoya/20131215/1387090668

  14. Infrastructure as Code ͱ͸ • ࡞ۀखॱ͕શ෦ίʔυʹͳΔ • Πϯϑϥ΋ίʔυϨϏϡʔ • ΞϓϦέʔγϣϯ։ൃͰߦΘΕ͖͍ͯͨΖ͍Ζͳϫʔ

    ΫϑϩʔΛΠϯϑϥ࡞ۀͷੈքʹ΋ಋೖ
  15. http://simplearchitect.hatenablog.com/entry/2016/02/18/165917

  16. Infrastructure as Code ʹ͸
 2 छྨ͋ΔΒ͍͠ • ʮVM΍ɺPaaSɺNetworkʯͳͲͷ ੜ੒ͷࣗಈԽ
 ὎

    AWS SDK ͱ͔ • ىಈͨ͠VMʹରͯ͠ɺ֤छͷπʔϧ΍ϥΠϒϥϦΛ Πϯετʔϧͯ͠ઃఆͷࣗಈԽ
 ὎ Chef ΍ Ansible
  17. ΍ͬͯΈͨײ૝ • όʔδϣϯ؅ཧ͞ΕͯΔͷͰ҆৺ • ؀ڥ͕յΕͯ΋͙͢ʹݩʹ໭ͤΔ • ΞϓϦέʔγϣϯ։ൃͷ͜ͱ͚ͩߟ͑ͯΕ͹ྑ͘ͳͬ ͨ

  18. “Fabric Λಋೖͨ͠࿩”

  19. http://qiita.com/shinichi62/items/b188ca9f5e92bd92d39a

  20. ͳͥಋೖ͔ͨ͠ • ΋ͱ΋ͱ͸γΣϧεΫϦϓτͰࣗಈԽ͞Εͯͨɻେ ͖ͳ໰୊͸ͳ͔͚ͬͨͲɺγΣϧεΫϦϓτ͕ಘҙ ͳਓ͕ϝϯς͢Δͱ͍͏ײ͡ʹͳͬͯͨͷͰ΋ͬͱ ؾܰʹͩΕͰ΋मਖ਼Ͱ͖ΔΑ͏ʹ͔ͨͬͨ͠ɻ

  21. FabricΛબΜͩཧ༝ • Capistrano ͱͲͬͪʹ͢Δ͔ͱ͍͏໰୊͸ࠓ͍Δձ ͕ࣾ Python ϝΠϯͰ Ruby ͞ΘΕΔਓ͕΄΅͍ͳ͍ ͷͰফڈ๏Ͱ

    Fabric Λબ୒ɻ
  22. ࣮૷ • Fabric ͰΊΜͲ͍͘͞ͷ͸ϕʔεͷϑϨʔϜϫʔΫ ͕ͳ͍ͷͰࣗ෼ͰҰ͔Βॻ͔ͳ͍ͱμϝͳͱ͜Ζɻ ࠷খͷϑϨʔϜϫʔΫΛ࡞ͬͯνʔϜʹఏڙ͢Δ͜ ͱʹͨ͠ɻ

  23. ͜Μͳײ͡ ᵓ── README.md ᵓ── lib │ ᵓ── git.py │ └──

    hipchat.py ᵓ── projectA │ ᵓ── README.md │ ᵓ── config │ │ ᵓ── common.py │ │ ᵓ── develop.py │ │ ᵓ── production.py │ │ └── staging.py │ └── fabfile.py ᵓ── projectB ᵓ── projectC
  24. ͜Μͳײ͡ @task def deploy(): """σϓϩΠ͢Δ""" lib.git.update(env.repo_url, env.branch, env.deploy_from) rsync_project(remote_dir=env.deploy_to, local_dir=env.deploy_from

    + '/', exclude=('.git'), delete=True) #run('uname -a') print yellow('ϩʔϧόοΫ͢Δͱ͖͸ҎԼͷίϚϯυΛ࣮ߦ͠·͠ΐ͏') print yellow('fab -H %s %s branch:master deploy' % (env.hosts, env.environment))
  25. ༻ޠͷ౷Ұ ଐਓੑΛഉআ͢ΔͨΊʹϓϩδΣΫτ͕ҟͳͬͯ΋ΠϯλʔϑΣʔε͸౷ Ұ͢Δɻ ϊʔϚϧͳσϓϩΠ fab -H host1,host2 develop deploy ϒϥϯνΛࢦఆͨ͠σϓϩΠ

    fab -H host1,host2 develop deploy:feat/ABC ϩʔϧόοΫ fab -H host1,host2 develop rollback
  26. fab -l • Fabric ͷඪ४ίϚϯυɻ͖ͪΜͱίϝϯτΛॻ͍ͯ ར༻ऀʹ҆৺ͯ͠࢖ͬͯ΋Β͏ɻ % fab -l Available

    commands: fab -H host1,host2 develop deploy fab -H host1,host2 develop deploy:feat/ABC ɹfab -H host1,host2 develop rollback
  27. “݁Ռ”

  28. ݁Ռ • σϓϩΠ͕γϯϓϧʹͳͬͨɻσϓϩΠ࣌ؒ΋୹͘ ͳͬͨ • ͨͩ Infrastructure as Code ͕ͳ͍ͱޮՌ͕൒ݮ

  29. “·ͱΊ”

  30. ·ͱΊ • Fabric ͱ Capistrano ͲͪΒ͔ద͍ͯ͠Δ͔ݕ౼͠Α ͏ • Infrastructure as

    Code ͕ͳ͍ͱޮՌ͕൒ݮ͢ΔͷͰ Ansible ΍ Chef ΋ݕ౼ͯ͠Ұॹʹಋೖ͠Α͏
  31. “͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ”