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
How to safely upgrade Rails
Search
Takashi Kokubun
March 28, 2016
Programming
6
13k
How to safely upgrade Rails
Rails Upgrade Casual Talks at Crowd Works
https://cw-meetup.doorkeeper.jp/events/40728
Takashi Kokubun
March 28, 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
PicoRubyと暮らす、シェアハウスハック
ryosk7
0
210
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
いりゃあせ、PHPカンファレンス名古屋2025 / Welcome to PHP Conference Nagoya 2025
ttskch
1
170
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
サーバーゆる勉強会 DBMS の仕組み編
kj455
1
300
混沌とした例外処理とエラー監視に秩序をもたらす
morihirok
13
2.2k
LLM Supervised Fine-tuningの理論と実践
datanalyticslabo
8
1.9k
良いユニットテストを書こう
mototakatsu
11
3.6k
為你自己學 Python
eddie
0
520
watsonx.ai Dojo #6 継続的なAIアプリ開発と展開
oniak3ibm
PRO
0
170
선언형 UI에서의 상태관리
l2hyunwoo
0
270
chibiccをCILに移植した結果 (NGK2025S版)
kekyo
PRO
0
130
Featured
See All Featured
Building a Scalable Design System with Sketch
lauravandoore
460
33k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Side Projects
sachag
452
42k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
360
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
Automating Front-end Workflow
addyosmani
1366
200k
The Cost Of JavaScript in 2023
addyosmani
46
7.2k
GraphQLとの向き合い方2022年版
quramy
44
13k
Transcript
How to safely upgrade Rails Rails Upgrade Casual Talks @k0kubun
ࣗݾհ • Takashi Kokubun (@k0kubun) • ΫοΫύου ٕज़෦ ։ൃج൫άϧʔϓ •
Rails 4.1 -> 4.2 ͷΞοϓάϨʔυΛ్த͔Β୲
ࠓ͢͜ͱ • CookpadͷRailsΞοϓάϨʔυͷྲྀΕ • ϦϦʔεલͷ4ஈ֊ͷಈ࡞֬ೝ • Cookpad͕ૺ۰ͨ͠Rails 4.2ͷόά
Cookpadͷ RailsΞοϓάϨʔυͷྲྀΕ Rails 4.1 → 4.2 ͷྫ
CIʹRails 4.2༻δϣϒΛ༻ҙ • ·ͣςετΛ௨͢ • @a_matsuda ͞Μ͕failΓ5ݸ·ͰݮΒͨ͠ͷΛҾ͖ܧ ͗ɺΓΛ௨͢ͷΛ୲ • ϦϦʔε͢Δ·Ͱmaster͔Βrebase͠ଓ͚Δrails42ϒϥϯ
ν͕ςετΛ௨Δঢ়ଶΛอͭͨΊɺCIʹδϣϒΛ༻ҙ͢Δ • CIαʔόʔͷϦιʔε͕ۭ͍͍ͯΔૣேʹ࣮ߦ͢Δ
cherry-pick • σϓϩΠޙͷͷΓ͚Λ༰қʹͨ͠ΓɺϨϏϡʔ ͷෛ୲ܰݮͷͨΊϓϧϦΛׂ͢Δ • 4.1, 4.2྆ํͰಈ͘मਖ਼ઌʹग़ͯ͠͠·͏ • ઌʹΞοϓάϨʔυͰ͖Δgemઌʹ͓ͬͯ͘
cherry-pick failΓ5ͷ࣌ 1308 additions 1087 deletions 650 additions 477 deletions
Ϛʔδͨ͠ϓϧϦ
ඇޓͷҰ࣌త੍ • Rails 4.2ͷAuthenticity TokenͷมߋϩʔϧόοΫͰ͖ ͳ͍ͷͰɺRails 4.1ͷڍಈʹϞϯΩʔύονͰݻఆ • Masked Authenticity
Token ͰຖճϥϯμϜͳtokenΛ ฦ͢Α͏ʹͳΔͷͰɺޙํޓੑ͕ͳ͍ • Rails 4.2σϓϩΠޙམ͍͔ͪͭͯΒ͜ͷύονΛ֎ͨ͠
ඇޓͷҰ࣌త੍ ActiveSupport.on_load(:action_controller) do module ActionController module RequestForgeryProtectionExtension def form_authenticity_token session[:_csrf_token]
||= SecureRandom.base64(32) end end Base.prepend RequestForgeryProtectionExtension end end • Masked Authenticity TokenͷมߋΛ੍͢Δύον
ಈ࡞֬ೝ • ن͕େ͖͘ɺશͯͷӨڹൣғͷѲ͕ࠔͳͷͰɺ • ؔ෦ॺ͕ಈ࡞֬ೝͰ͖ΔظؒΛ2िؒఔઃ͚Δ • ຊ൪ʹ͍ۙڥͰΤϥʔ͕ग़Δ͔֬ೝ͢Δ • ৄࡉޙͷεϥΠυͰ
cookpad.com ͷϦϦʔε • લ͔ΒίʔυϑϦʔζ • ӨڹΛখ͘͢͞ΔͨΊɺޕલ7࣌ग़ࣾɾ8࣌σϓϩΠ • ͳΔ͘τϥϑΟοΫ͕͍࣌ؒଳʹσϓϩΠ͍ͨ͠ ͕ɺؔऀશһʹਂͷग़ࣾΛཁٻ͢Δ΄ͲͰͳ͍
ෳϒϥϯνӡ༻ • ಉ͡ϦϙδτϦʹ cookpad.com ΛؚΉ8ͭͷΞϓϦ͕ಉډ ͍ͯ͠Δ͕ɺҰʹશ෦ϦϦʔε͠ͳ͍ • 8ͭͷΞϓϦ: ཧը໘, όον,
API, ϫʔΧʔ, ... • 1ि͔͚ؒͯஈ֊తʹσϓϩΠ͢Δ • શͯRails 4.2ʹҠߦ͢Δ·ͰRails 4.1༻ͷrails41ϒϥϯν Λ࡞ΓmasterͷมߋΛόοΫϙʔτ͠ଓ͚Δ
σϓϩΠޙͷࢹ • ҎԼͷ2ͭΛࢹ͢Δ • Sentry: Τϥʔ • ࣗࣾϞχλϦϯάπʔϧ: ϨεϙϯελΠϜ
σϓϩΠޙͷࢹ ϨεϙϯελΠϜ Τϥʔ
ΞοϓάϨʔυϑϩʔͷ·ͱΊ • ςετΛ௨͠CIʹδϣϒΛ༻ҙ͢Δ • ϓϧϦͷׂඇޓͷ੍ʹΑΓมߋͷཻΛখ͘͢͞Δ • 2िؒಈ࡞֬ೝ • ෳͷΞϓϦΛ1ि͔͚ؒͯஈ֊తʹϦϦʔε͢Δ •
σϓϩΠޙɺϨεϙϯελΠϜͱΤϥʔΛࢹ
ϦϦʔεલͷ4ஈ֊ͷಈ࡞֬ೝ
1. ։ൃ༻ͷݕূڥͰͷ֬ೝ • ։ൃ༻ͷDBΛࢀর͢ΔݕূڥʹRails 4.2ͷϒϥϯνΛ σϓϩΠ • ΞοϓάϨʔυؔͳ͘ͱͱҙͷϒϥϯνΛҙ ͷαϒυϝΠϯʹσϓϩΠͰ͖ΔΑ͏ʹͳ͍ͬͯΔ •
ྫ: https://rails42.staging.ʙ/ • ͜ͷڥͰ֤෦ॺʹಈ࡞֬ೝΛґཔ
2. ຊ൪ڥͰͷखಈ֬ೝ • Rails 4.2༻ͷϒϥϯνΛσϓϩΠͨ͠ຊ൪ڥΛ༻ҙ • Webͷ߹ • ಛผͳΫοΩʔΛ࣋ͭ߹ͷΈͦͷڥʹϓϩΩγ͞Ε ΔΑ͏ʹͯ͠खಈͰಈ࡞֬ೝ
• ϞόΠϧΞϓϦ༻APIͷ߹ • ಛผͳϦΫΤετϔομʔΛ࣋ͭ߹ͷΈϓϩΩγ
2. ຊ൪ڥͰͷखಈ֬ೝ *OUFSOFU "QBDIF SBJMT SBJMT ௨ৗͷΫοΩʔ foocookie=1 • Webͷ߹
consoleͰదʹ $.cookie('foocookie', 1) CSPXTFS
2. ຊ൪ڥͰͷखಈ֬ೝ • ϞόΠϧΞϓϦ༻APIͷ߹ *OUFSOFU "QBDIF SBJMT SBJMT .PCJMF "QQ
NJUNQSPYZ ϦΫΤετϔομʹ X-Foo=1 Λ͚ͭΔ X-Foo=1 ී௨ͷϦΫΤετ
3. Kage • https://github.com/cookpad/kage • ͋ΔαʔόʔʹདྷͨϦΫΤετΛRails 4.2ΛσϓϩΠͨ͠ͷʹྲྀ ͠ɺDBͳͲͷॻ͖ࠐΈࢭ͢Δ • MySQLͳΒBLACKHOLEɺmemcached
ͳͲִ͢Δ • Τϥʔͷ༗ແύϑΥʔϚϯεΛ֬ೝ͢Δ • tail -f production.log • nginxͷϨεϙϯελΠϜunicornͷϦιʔε༻ྔ
3. Kage *OUFSOFU "QBDIF SBJMT ,BHF SBJMT ಉ͡ϦΫΤετ ϨεϙϯεࣺͯΔ Ϣʔβʔʹฦ͢
4. Production Test • CIޭޙࣗಈతʹσϓϩΠ͞ΕΔɺ΄΅ຊ൪ͷڥ • ΞοϓάϨʔυؔͳ͍ͭ͘Ͱ͜͜Ͱಈ࡞֬ೝΛ͔ͯ͠ ΒσϓϩΠ͢Δ
Cookpad͕ૺ۰ͨ͠Rails 4.2ͷόά
Encoding::UndefinedConversionError • ϚϧνόΠτจࣈྻ͔ͭ֯ͷ"%"ΛؚΉϑΝΠϧ໊ͷϑ ΝΠϧΛΞοϓϩʔυͨ͠ࡍʹग़ΔϨΞͳΤϥʔ • Rails 4.1 → 4.2 ΞοϓάϨʔυ࣌ʹ།Ұग़ͨΤϥʔ
• ຊՈʹ @eagletmt ͕ϓϧϦΛ͛ɺ4.2.4ʹऔΓࠐ·Εͨ • https://github.com/rails/rails/pull/21131
Encoding::UndefinedConversionError
undefined method `unpack' for nil:NilClass • Rails 4.2.4ͱRuby 2.0.0ͷΈ߹ΘͤͰͷΈൃੜ͢ΔΤϥʔ •
Ruby 2.0.0ͩͱ ERB::Util.url_encode ͷgsubͷϒϩο ΫͰ $& Λࢀর͢Δ͕ɺAS::SafeBuffer ͩͱಈ͔ͳ͍ • ຊՈʹ @k0kubun ͕ϓϧϦΛ͛ɺ4.2.5ʹऔΓࠐ·Εͨ • https://github.com/rails/rails/pull/21402
undefined method `unpack' for nil:NilClass
·ͱΊ • ҰʹσϓϩΠ͞ΕΔมߋΛখ͘͢͞Δ • ͳΔ͘ଟ͘ͷखͰɺͳΔ͘ຊ൪ʹ͍ۙڥͰಈ࡞֬ೝ • ΫοΫύουͰૺ۰ͨ͠Rails 4.2ͷόάຊՈͰमਖ਼ࡁ