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

Rails開発環境をDocker on Vagrant on Macに移行して快適に!

Rails開発環境をDocker on Vagrant on Macに移行して快適に!

Mac歴20年。Docker使った開発するならlinux使えよーと、いわれても、もう戻れません。
だって、Macが使いたいんだから。

という、仲間に見て欲しいスライド。MacでもVM上にDocker立てれば問題なく開発できるのです。

お手元で、くすぶっているMacの真の力、目覚めさせてくださいませませ。

How to movie
https://www.youtube.com/watch?v=1xBksIE2vAk

https://github.com/junara/vagrantrailstest
https://vagrantrailstest.herokuapp.com/

Bba9b7a926f27fb88ae6b7c03f53f6a8?s=128

jungo araki

May 27, 2020
Tweet

Transcript

  1. 2020-05-29 JUNARA (JUNGO ARAKI) Docker with Vagrant on Mac More

    speed for development experience !
  2. • ߥ໦ ३ޗ • ෎தࢢࡏॅΤϯδχΞ • ࣂ͍ͬͯΔ͏͗͞ͱ͢͢͝ͷ͕ຖ೔ͷָ͠Έ • ओʹRuby on

    RailsΛ࢖ͬͨγεςϜ։ൃ • ͏͗͞ͷࣂҭه࿥ΞϓϦΛ࡞ΔͨΊɺ5݄͔Β UdemyͰFlutterΛษڧ͍ͯ͠·͢ ࣗݾ঺հ
  3. ࣗݾ঺հ ϦϞʔτϫʔΫͰώοτͨ͠΋ͷ ༗ઢยࣖϔουηοτ όϥϯεϘʔϧ

  4. ຊ୊

  5. • ͓͍ͦɺ͓ͦ͗͢Δ Docker on Mac • → vagrantΛ͔ͭ͏ͱ͋͠ΘͤʹͳΕΔΑ Docker on

    Mac too slow. but
  6. DockerΛ͔ͭͬͨ ։ൃମݧʢDXʣ͕ѱ͗͢Δ

  7. • Performance implications of host-container file system consistency • On

    Linux, these guarantees carry no overhead, since the underlying VFS is shared directly between host and container. • Linux͸ಉظͷΦʔόʔϔουͳ͠ɻ • macOS (and other non-Linux platforms) there are significant overheads to guaranteeing perfect consistency • mac͸host containerؒͷಉҰੑ֬อʹΦʔ΂ʔϔου͕େ͖͗͢ • Performance issues, solutions, and roadmap • With large sequential IO operations, osxfs can achieve throughput of around 250 MB/s which, while not native speed, is not likely to be the bottleneck for most applications which perform acceptably on HDDs. • With osxfs, latency is presently around 130μs for most operations or 13× slower. (https://docs.docker.com/docker-for-mac/osxfs/ #performance-issues-solutions-and-roadmap) • ॻ͖ࠐΈ଎౓ࣗମ͸े෼͕ͩɺϨΠςϯγʢಡΈ/ॻ͖Λ໋ྩ͔ͯ͠Β࣮ࡍʹಡΈॻ͖͢Δ·Ͱͷ࣌ؒʣ͕13ഒ஗͍ ݪҼ
  8. ϑΝΠϧಉظ͕໰୊ LinuxͳΒ໰୊ͳ͍

  9. IUUQTTDSBQCPYJPSVCZKQ NBD04&"%PDLFS&$&&&&"#&"# &#&"&#$&#

  10. Θ͔Δ͚Ͳ Ͱ͖ͳ͍

  11. ͳͥͳΒ

  12. ΅͘͸ɺMac ࢖͍͍ͨ

  13. ͩͬͯ 20೥དྷͷ ϚΧʔ͔ͩΒ ͸͡Ίͯߪೖͨ͠ύιίϯ͸ Performa 5320 OS͸׽ࣈTalk 7.5.3 Ͱͨ͠

  14. • linux࢖͏ • host-containerؒͷಉظΛͳΜͱ͔ • → docker-sync → ݹ͔͘Β΍ΒΕ͍ͯΔ͚Ͳෆ҆ఆͳҹ৅ •

    → Dockerެࣜ Mutagen-based caching (Docker Desktop Community 2.3.1.0, 2020-05-20) → ࠓ͸·͚ͩͩͲɺকདྷʹظ଴ • host-containerؒΛΏΔ͘ಉظ • → Dockerެࣜ Tuning with consistent, cached, and delegated configurations → ࢼ͢ • VmͷLinuxͰDocker࢖͏ host-VmؒΛಉظ͢Δ • → VirtualBox image using vagrant with mutagen file sync → ࢼ͢ MacͰͷղܾख๏
  15. MacͰͷղܾख๏ • host-containerؒͷಉظΛͳ Μͱ͔ʢdocker-syncɺ mutagen base syncʣ • host-containerؒΛ ΏΔ͘ಉظ͢Δ

    ʢTuning with consistentʣ • VmͷLinuxͰDocker࢖͏ host-VmؒΛ ಉظ͢ΔʢVirtualBox image using vagrant with mutagen file syncʣ
  16. • Fortunately, in many cases where the performance degradation is

    most severe, perfect consistency between container and host is unnecessary. • ׬શͳಉظ͸ݫີʹ΍Βͳͯ͘΋໰୊ͳ͍ΑͶ • There are three broad scenarios to consider …. consitent … cached … delegated • 3ύλʔϯ͋Δ • cached: the host’s view is authoritative (permit delays before updates on the host appear in the container) • cachedλΠϓ͸host͕ࢧ഑తɻcontainer͔Βͷಉظ͸஗Εͯ΋ྑ͍ͱ͢Δ Tuning with consistent, cached, and delegated configurations
  17. • 2020೥2݄ࠒͷQiitaهࣄΛࢀߟ • Ծ૝؀ڥͷLinux্ʹdockerΛཱͯΔʢઃఆ͸vagrant ʣ • MacͱԾ૝؀ڥؒͷϑΝΠϧͷಉظΛmutagenͰ΍Δ • Mutagen •

    Mutagen is a development utility that lets you use your existing local tools (such as your text editor/ IDE, browser, and terminal) to work in remote environments like cloud servers and containers. It does this by providing high-performance file synchronization and flexible network forwarding, allowing you to develop applications in a way that looks local but runs on remote hardware. • ωοτϫʔΫ্ͷαʔόʔ΍ίϯςφؒͷϑΝΠϧΛര଎Ͱڞ༗ͯ͘͠ΕΔ VirtualBox image using vagrant with mutagen file sync
  18. • DockerͰߏ੒ͨ͠ςετ༻ͷRails appΛ४උ • ίϯςφ͸rubyͱpostgresqlͷ2ͭ • ൺֱ͢Δߏ੒ • Docker on

    Mac • Docker on Mac with tuning with consistent of cache option. • Docker on VM with Vagrant and mutagen • Railsͷىಈ࣌ؒͱϖʔδͷදࣔ࣌ؒͰൺֱ • time docker-compose exec web rails runner ‘puts Rails.env’ ࣮ߦ࣌ؒ • ‘/’ ʹΞΫηε ࢼͦ͏
  19. • https://github.com/junara/vagrantrailstest • Rails • ॅॴΛݕࡧͰ͖ΔΞϓϦ • table usersͷΈ •

    σʔλ͸10ສ݅ • https://vagrantrailstest.herokuapp.com/ ςετ༻ͷΞϓϦ
  20. • Docker on Mac • Docker on Mac with tuning

    with consistent of cache option. • Docker on VM with Vagrant and mutagen σϞ
  21. • Vagrantͷಋೖ • Install VirtualBox • Install Vagrant • Create

    Vagrantfile for vagrant (vm). • Create mutagen.yml for mutagen (file sync) • Start vagrant • ssh to vagrant • Common set up ͕࣌ؒ͋Ε͹
  22. n A B spped up page view [msec] light SQL

    5 2402 ± 311 540 ± 87 4.5 heavy SQL 5 3764 ± 269 1770 ± 96 2.1 much JS, much SQL 5 1692 ± 46 1273 ± 43 1.3 Rails [sec] (rails runner ) 5 47.6 ± 1.7 7.9 ± 0.1 6.1 rspec[sec] 54 examples 5 27.9 ± 0.8 10.8 ± 0.2 2.6 2164 examples 3 272.3 ± 4.9 169.7 ± 2.3 1.6 A Docker on Mac B Docker on VirtualBox Linux on Mac ن໛ͷେ͖ͳ։ൃྫ
  23. • Docker on mac͕஗͍ͷ͸ಉظͷ໰୊ • LinuxͳΒશ͘໰୊ͳ͍ • MacͳΒDocker on vm

    with vagrantΛڧ͘Φεεϝɻ͍·͙͢࠷ߴͷDXΛखʹೖΕΒΕ·͢ • Docker ͕mutagen baseͷಉظΛedgeͰެ։தɻ҆ఆ͢Δ·Ͱ଴ͯΔͳΒͪ͜ΒͰ΋ ·ͱΊ