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
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
770
Ruby 3.0 JIT on Rails
k0kubun
9
9.1k
Other Decks in Programming
See All in Programming
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
460
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
250
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
4
260
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
330
PHPで学ぶプログラミングの教訓 / Lessons in Programming Learned through PHP
nrslib
2
210
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
140
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
42 best practices for Symfony, a decade later
tucksaun
1
180
たのしいparse.y
ydah
3
120
Featured
See All Featured
It's Worth the Effort
3n
183
28k
Scaling GitHub
holman
458
140k
Raft: Consensus for Rubyists
vanstee
137
6.7k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
111
49k
Statistics for Hackers
jakevdp
796
220k
Thoughts on Productivity
jonyablonski
67
4.4k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Bash Introduction
62gerente
608
210k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Automating Front-end Workflow
addyosmani
1366
200k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
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ͷ։ൃʹࢀ Ճ͠Α͏!