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
13k
Ruby JIT Hacking Guide / RubyKaigi 2023
k0kubun
2
9.5k
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
420
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
770
Ruby 3.0 JIT on Rails
k0kubun
9
9.1k
Other Decks in Programming
See All in Programming
103 Early Hints
sugi_0000
1
250
採用事例の少ないSvelteを選んだ理由と それを正解にするためにやっていること
oekazuma
2
1k
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
160
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
500
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
500
Haze - Real time background blurring
chrisbanes
1
520
useSyncExternalStoreを使いまくる
ssssota
6
1.3k
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
240
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
バグを見つけた?それAppleに直してもらおう!
uetyo
0
180
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
280
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
170
Featured
See All Featured
Unsuck your backbone
ammeep
669
57k
Building Adaptive Systems
keathley
38
2.3k
Done Done
chrislema
182
16k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Embracing the Ebb and Flow
colly
84
4.5k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
We Have a Design System, Now What?
morganepeng
51
7.3k
For a Future-Friendly Web
brad_frost
175
9.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
A Modern Web Designer's Workflow
chriscoyier
693
190k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
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ͷ։ൃʹࢀ Ճ͠Α͏!