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
640
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
940
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
250
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
EMになってからチームの成果を最大化するために取り組んだこと/ Maximize team performance as EM
nashiusagi
0
100
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Jakarta EE meets AI
ivargrimstad
0
170
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
3
1.2k
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
430
A Tale of Four Properties
chriscoyier
156
23k
Automating Front-end Workflow
addyosmani
1366
200k
Making Projects Easy
brettharned
115
5.9k
For a Future-Friendly Web
brad_frost
175
9.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Ruby is Unlike a Banana
tanoku
97
11k
How STYLIGHT went responsive
nonsquared
95
5.2k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
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ͷ։ൃʹࢀ Ճ͠Α͏!