Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
MItamae Hacking Guide
Search
Takashi Kokubun
November 01, 2016
Programming
7
8k
MItamae Hacking Guide
Roppongi.rb #2 Infrastructure x Ruby
http://roppongirb.connpass.com/event/42633/
Takashi Kokubun
November 01, 2016
Tweet
Share
More Decks by Takashi Kokubun
See All by Takashi Kokubun
YJIT Makes Rails 1.7x faster / RubyKaigi 2024
k0kubun
7
12k
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
9.4k
YJIT: Dive into Ruby's JIT compiler written in Rust / Rust.Tokyo 2022
k0kubun
1
2k
Towards Ruby 4 JIT / RubyKaigi 2022
k0kubun
3
11k
Optimizing Production Performance with MRI JIT / RubyConf 2021
k0kubun
1
410
Why Ruby's JIT was slow / RubyKaigi Takeout 2021
k0kubun
3
1.8k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
760
Ruby 3.0 JIT on Rails
k0kubun
9
9.1k
Other Decks in Programming
See All in Programming
Jakarta EE meets AI
ivargrimstad
0
540
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
290
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
920
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Amazon Qを使ってIaCを触ろう!
maruto
0
400
RubyLSPのマルチバイト文字対応
notfounds
0
120
Macとオーディオ再生 2024/11/02
yusukeito
0
370
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
Statistics for Hackers
jakevdp
796
220k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
The Cult of Friendly URLs
andyhume
78
6k
For a Future-Friendly Web
brad_frost
175
9.4k
Writing Fast Ruby
sferik
627
61k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
[RailsConf 2023] Rails as a piece of cake
palkan
52
4.9k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
28
2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Transcript
MItamae Hacking Guide Roppongi.rb #2 @k0kubun
ࣗݾհ
ࠓ͢͜ͱ • 1. Itamaeͱ • 2. Itamae Goͱ • 3.
MItamaeͷ͝հ
1. Itamaeͱ
Itamaeͱ • https://github.com/itamae-kitchen/itamae • ChefϥΠΫͳߏཧπʔϧ • αʔόʔͷߏΛRuby DSLͰهड़͢Δ
Itamae DSL package 'nginx' do action :install end service 'nginx'
do action [:enable, :start] end
ItamaeΛ͏ͱԿ͕خ͍͠ͷ͔ • Puppet, Ansibleͱҧ͍ઃఆϑΝΠϧ͕Ruby • มͳDSLͱ͔YAMLΑΓRubyΛಡΉɾॻ͘ํָ͕͍͠ • ChefʹൺͯγϯϓϧͳπʔϧͳͷͰอक͕͍͢͠ • Chefʹൺίʔυϕʔε͕খ͘͞ɺ͙͢ʹΈΛѲ
Ͱ͖Δ • Berkshelfͷ͔ΘΓʹrubygemsΛ͏
ΫοΫύουʹ͓͚ΔItamae • αʔόʔͷߏཧʹΘΕ͍ͯΔ • ݹ͍ͷPuppet͕ͩItamaeʹҠߦத • ৽͍͠αʔόʔجຊతʹItamaeͰཧ͞Ε͍ͯΔ • ͨͩ͠AppαʔόʔͳͲঢ়ଶΛ࣋ͨͳ͍ͷDocker •
։ൃऀͷϚγϯͷηοτΞοϓʹΘΕΔʮ༧ఆʯ • RubyͰॻ͔Εͨπʔϧ͔ΒItamaeϕʔεͷͷʹҠߦத
Itamaeͷӡ༻Ͱൃੜͨ͠՝ • Itamaeͷ࣮ߦͷͨΊʹrubyΛηοτΞοϓ͠ͳ͚Εͳͳ͍ • itamae ssh(sshܦ༝ͷద༻)͕͍ͷͰαʔόʔଆʹItamaeΛೖΕ࣮ͯߦ͢ Δ • ։ൃڥͷηοτΞοϓʹ͓͍ͯɺLinuxͩͱruby͕ೖͬͯͳ͍͜ͱ͕͋Δ •
ItamaeͷͨΊ͚ͩʹrubyͷڥҰࣜΛύοέʔδϯά͢Δͷ໘ͩ͠ɺ͔ ͱ͍ͬͯී௨ʹ͏rubyͷڥԚͨ͘͠ͳ͍ • ύοέʔδطʹ͋Δͷͷɺ࠷ॳ͔ΒγϯάϧόΠφϦͰ࡞ΒΕͨ Itamae͕͋Δͱखܰͦ͏
2. Itamae Goͱ
Itamae Go • https://github.com/k0kubun/itamae-go • GolangͰγϯάϧόΠφϦItamaeΛ࡞ͬͨ
࡞ͬͨಈػ
Itamae GoͷΈ • mrubyͷVMΛ mitchellh/go-mruby ͰΈࠐΜͰ͍Δ • mrubyͷΦϒδΣΫτΛҾʹGoͷstructΛ࡞ΔGoͷؔ Λmrubyͷϝιουͱͯ͠ఆٛͨ͠ΫϥεΛ࡞Γɺͦ ͷΫϥε্ͰItamaeϨγϐΛinstance_eval
• ͜Ε͕ItamaeͷDSLʹͳΔ • ࡞ΒΕͨGoͷstructΛݟͯGoͷؔͰΦϖϨʔγϣϯ
Itamae Goͷϝϯςਏ͍ • GoͷίʔυͰRubyͷϝιουΛఆ͍ٛͯ͘͠ ͷ͕͔ͳΓ໘ • SpecinfraΛGoͰ࠶࣮͢Δͷେม • libmruby.aΛϦϯΫ͠ͳ͕ΒCGOόΠϯσΟϯ άͷΫϩείϯύΠϧ͢Δͷଟී௨ʹͰ͖Δ
͚Ͳ໘
go-mrubyͷ࣮༻ྫͱͯ͠໘ന͍͕… • ͦͦGoΛ͏ඞཁ͋Δͷ͔ʁ • ผʹGo͡Όͳ͍ͱ͑ͳ͍ϥΠϒϥϦͱ͔ݴޠػೳΛͬͯ ͳ͍ • mruby-cliͱ͍͏ɺRubyΛධՁͰ͖ΔγϯάϧόΠφϦΛ࡞Δผ ͷιϦϡʔγϣϯ͕͋ͬͨ •
͍ͯ͏͔ͿͬͪΌ͚ڈͷRubyConfͰ͚ͬͯͨͲPokemon Goʹ͔͚ͨํ͕ྲྀߦΔͱࢥ͍ͬͯͭͬͯ͠·ͬͨ
3. MItamaeͷ͝հ
MItamae • https://github.com/k0kubun/mitamae • mruby-cliΛͬͨItamaeͷpure mruby࣮ • ʮݟڅ͑ʯʁ • ΤϜ(mruby)ɾΠλϚΤͰ͢
mruby-cliͱ • https://github.com/hone/mruby-cli • mrubyͰγϯάϧόΠφϦΛ࡞ΔͨΊͷϘΠϥʔϓϨʔτ • ίϚϯυϥΠϯҾΛmrubyͷArrayʹม͠ɺmrubyͰఆٛ͞Εͨ __main__ Λݺͼग़͢Cݴޠͷmainؔ •
͜ͷ __main__ ͷ࣮͚ͩ͢Εྑ͍ͷͰɺRubyҎ֎Λॻ͔ͣʹࡁΉ • macOS, Windows͚ʹΫϩείϯύΠϧ͢ΔͨΊͷڥΛ࣋ͭ Dockerfile • ࣮ମ: https://github.com/hone/mruby-cli-docker
MItamae: ΅͕͔͘Μ͕͍͖͑ͨ͞ΐ͏ͷItamae • rubygemʹґଘ͠ͳ͍ͨΊɺόΠφϦΛμϯϩʔυ͢Δ͚ͩͰଈ࣮ߦՄೳ • CRubyΛ͏߹ͱҧͬͯίϯύΠϧࡁͳͷͰɺىಈ͕ߴ • ιʔείʔυΛύʔεͯ͠YARV iseqʹίϯύΠϧ͢Δ·Ͱͷίετ͕ͳ͍ •
2.5GHz Intel Core i7Ͱɺitamae: 499ms, mitamae: 23ms (21.7ഒ) • itamae sshΛαϙʔτ͍ͯ͠ͳ͍ͷͰɺSpecinfra(ඞͣԿΒ͔ͷίϚϯυΛ͏) ͷ͔ΘΓʹී௨ʹCͷؔΛ͏͜ͱͰߴԽ͕Մೳ • Ͳ͏ͤitamae ssh͍ͷͰɺαʔόʔͷItamaeͷॳճΠϯετʔϧͱ͔ʹ ͔͠Θͳ͍͠ɺΔʹͯ͠ผͷπʔϧʹͯ͠Αͦ͞͏
MItamaeͷεςʔλε • େମͷػೳ͋Δ • https://github.com/k0kubun/mitamae#supported-features • fileͷedit, host inventory, verify,
subscribes(notifies͋Δ)͕ͳ͍ • remote_directory, http_request, local_ruby_block ͕ͳ͍ • Arch Linux, CentOS, Debian, Gentoo, macOS, UbuntuΛαϙʔτ • ItamaeຊՈͷ݁߹ςετ͕େମ௨Δ • Travis্ͰDockerίϯςφʹapplyͯ͠ServerspecͰςετͯ͠Δ
Itamae 2ʁ • ҿΈձͰryotarai͞Μ(Itamae࡞ऀ)͕itamae- mruby(MItamaeͷ࣌ͷ໊લ)ΛItamae 2ʹ͢Δͬͯ ݴͬͯͨ • ͱΓ͋͑ͣػೳ͕ἧͬͯར༻࣮૿͑Δඞཁ͕͋Γ ͦ͏
• ͳͷͰɺ͓͢͢Ίͷ༻్ͱɺMItamaeͷ෦ઃܭ ։ൃํ๏ʹ͍ͭͯઆ໌͠·͢
MItamaeͷ༻్
ͷMItamaeͷ༻్ • dotfilesͷద༻ • https://github.com/k0kubun/dotfiles • ϨγϐΛࢀߟʹ͍ͨ͠ํ https://github.com/k0kubun/ legacy-dotfiles Ͳ͏ͧ
• ࣗͰձࣾͰσεΫτοϓϚγϯʹLinuxΛ͍ͬͯΔ͕ɺ ࠷ॳͷηοτΞοϓલʹrubyΛ͍ΕΔඞཁ͕ͳͯ͘ඍົʹॿ͔Δ • ىಈ͍͠ɺgem install / bundle installෆཁͩ͠Կ͔ͱָ
ΫοΫύουͰͷར༻ঢ়گ • ։ൃڥͷηοτΞοϓπʔϧΛItamaeϕʔεͷͷʹҠߦதͰɺͦ͜ʹ MItamae͕࠾༻͞Ε͍ͯΔ • αʔόʔͷߏཧ͚ʹ·ͩΘΕͯͳ͍ • ͚ࣾͷपลπʔϧ͕Itamaeͱ݁߹͍ͯͯ͠Ҡߦ͕एׯେม • ͦͦItamaeͩͱ໘ͳͷύοέʔδϯά͕ͩɺࣾͰ͍ͬͯΔ
αʔόʔ͚ʹطʹύοέʔδ͕͋ΔͷͰͦΕ΄ͲϞνϕʔγϣϯ͕ͳ ͍ • ͰγϯάϧόΠφϦͰΫϦʔϯ͔͍ͭͷͰ͜Ε͔Βಋೖ͢Δํʹ͓ ͢͢Ί
Inside MItamae
MItamaeͷ෦࣮ • جຊతʹmruby-cliͬͯΔ͚ͩ • Itamae෦εΫϥον • Specinfra෦΄΅ͦͷ··͖࣋ͬͯͨ • ͪΖΜAuthorsͱLICENSEදهʹmizzy͞Μ ͕͍·͢
MItamaeͱItamaeͷ࣮ͷҧ͍ • resourceͱresourceΛద༻͢Δ͕͞Ε͍ͯͯɺresource ͨͩͷϞσϧʹ͗͢ͳ͍ • ryotarai͞ΜͷΞΠσΞ • ͷझຯ͕ೖ͍ͬͯΔ • ͳΔ͘method_missingΛආ͚ϕλॻ͖͢Δ(͏গ͠ݮΒͤ
Δ͚Ͳ)ɺͳͲ • defineͨ͠resourceʹωετͨ͠resourceͰparams͕͑Δ
defineͨ͠resourceʹωετͨ͠ resourceͰparams͕͑Δ ???? # Itamae ͷ߹ define :ruby do version
= params[:name] execute "..." do not_if "... #{version}" end end ruby '2.3.1'
defineͨ͠resourceʹωετͨ͠ resourceͰparams͕͑Δ ???? # MItamaeͷ߹ (Itamaeͩͱparams͕ࢀরෆೳ) define :ruby do execute
"..." do not_if "... #{params[:name]}" end end ruby '2.3.1'
Hacking MItamae
cloneͯ͠ίϯύΠϧ࣮ͯ͠ߦ $ git clone https://github.com/k0kubun/mitamae $ cd mitamae $ rake
compile $ mruby/build/host/bin/mitamae local recipe.rb
ςετͷ࣮ߦ # Ϣχοτςετͷ࣮ߦ $ rake test:mtest # DockerͱServerspecΛͬͨςετ $ rake
test:integration
ΫϩείϯύΠϧ # mitamae-buildσΟϨΫτϦʹ࡞ΒΕΔ $ rake release:build
·ͱΊ • MItamaeͯ͘Πϯετʔϧ͕؆୯ͳͷͰ ͬͯཉ͍͠ • ։ൃڥͬͯΔͷͰMItamaeͷ։ൃʹࢀ Ճ͠Α͏!