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.6k
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.9k
数時間かかる週一リリースを毎日何度も爆速でできるようにするまで / CI/CD Conference 2021
k0kubun
21
14k
Ruby 3 JIT's roadmap / RubyConf China 2020
k0kubun
0
780
Ruby 3.0 JIT on Rails
k0kubun
9
9.2k
Other Decks in Programming
See All in Programming
ドメインイベント増えすぎ問題
h0r15h0
2
570
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
php-conference-japan-2024
tasuku43
0
430
情報漏洩させないための設計
kubotak
5
1.3k
為你自己學 Python
eddie
0
520
Оптимизируем производительность блока Казначейство
lamodatech
0
950
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
940
ASP.NET Core の OpenAPIサポート
h455h1
0
120
各クラウドサービスにおける.NETの対応と見解
ymd65536
0
250
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
410
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
テストコード書いてみませんか?
onopon
2
340
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Building an army of robots
kneath
302
45k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Optimising Largest Contentful Paint
csswizardry
33
3k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
The Cost Of JavaScript in 2023
addyosmani
46
7.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ͷ։ൃʹࢀ Ճ͠Α͏!