Upgrade to Pro — share decks privately, control downloads, hide ads and more …

インターンから入社してRailsのメール送信をSengGridに移行してみて

tatsuya
September 08, 2021

 インターンから入社してRailsのメール送信をSengGridに移行してみて

tatsuya

September 08, 2021
Tweet

Other Decks in Programming

Transcript

  1. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ΞδΣϯμ  • ࣗݾ঺հ

    • ϑϥϯεྉཧਓ͔ΒRailsΛษڧ͠ɺۦ͚ग़͠ΤϯδχΞ΁ • MENTAͱͷग़ձ͍ • ϙʔτϑΥϦΦ࡞੒ͷϙΠϯτ • ϥϯαʔζΠϯλʔϯ΁ೖࣾ • Lancers Assistant/Creativeͷ঺հ • ϝʔϧૹ৴ΛSendGrid΁Ҡߦ • ·ͱΊ
  2. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ࣗݾ঺հ  ฏ໺ ୡ໵(ͻΒͷ

    ͨͭ΍ ) • Lancers৽ଔΤϯδχΞ • ϑϥϯεྉཧਓˠ2020/11ʹΠϯλʔϯ
 ͱͯ͠δϣΠϯɻ4݄͔Βਖ਼ࣾһʹ • Rails੡ͷLCC(LancersCreativeCloud)Λ։ൃ • झຯ: ஋ஈ͸͍͚҆Ͳྉཧ͕ඒຯ͍͠
 ډञ԰Λ୳͢͜ͱ(࠷ۙ͸ࣗॗؾຯɻɻ ) tatuya4451 @44511336tatuya
  3. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁  ಇ͍ͯͨళฮ •

    ϑϥϯεͷҰͭ੕ϨετϥϯʮChartronʯ • େࡕҰͭ੕ʮAgneldorʯ • ϋΠΞοτϦʔδΣʔϯγʔେࡕ ߴߍੜͷ࣌ɺ฼ͱϑϨϯνΛ৯΂ʹ͍͖িܸΛड͚Δɻ
 →⁋ௐཧࢣઐ໳ֶߍ΁ೖֶ • แஸͷ࢖͍ํ͔Βϑϥϯεޠɺௐཧ࣮शΛ௨ͯ͠ϑϨϯνͷجຊΛֶͿ • ଔۀޙɺϑϥϯε΁Ұ೥ཹֶ • ൒೥ؒ͸ϑϥϯεୈೋͷ౎ࢢϦϤϯͷ͓৓Ͱ(ߍࣷ)ͰޠֶɺྉཧΛษڧ • ࢒Γͷ൒೥͸ݱ஍ݚमΛߦ͏ • ؼࠃޙ͸େࡕͷொ৔΍ϗςϧͰݚᮎΛੵΉ
  4. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁  • ౦ژͰग़ళ͢ΔλΠϛϯάͰίϩφ͕ྲྀߦ

    • ͲΜͳ؀ڥͰ΋ࣗ෼Ͱίϯτϩʔϧͯ͠࢓ࣄ͕Ͱ͖Δ 
 ৬छʹ௅ઓ͍ͨ͠ • ࣌ؒͱ৔ॴʹͱΒΘΕͳ͍ಇ͖ํΛ͍ͨ͠ • ҰͭͷεΩϧʹґଘͨ͘͠ͳ͍ స৬Λܾҙ
  5. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁  • ϓϩάϥϛϯάεΫʔϧͰ໿2ϲ݄ษڧ

    • HTM L • CS S • Rub y • Rail s • Javascrip t • ϝϧΧϦͷΫϩʔϯΞϓϦʮFURIMAʯ
 ΛνʔϜͰ੍࡞ 
  6. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁   •

    ΦϯϥΠϯͰษڧ஥͕ؒͰ͖ΔʮLIve-StudyʯΛ੍࡞ • ௨஌ػೳ • DMػೳ • ϑΥϩʔػೳ • ݕࡧػೳ • ܝࣔ൘ػೳ • Slack௨஌ • Πϕϯτͷ։࠵ɺฤूɺ࡟আɺࢀՃɺऴྃ(CRUD ) • ϩʔΧϧͰ։ൃ • ຊ൪؀ڥ͸͸ECSΛ༧ఆ
  7. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup  MENTAͰSREͷ҆ୡ(@adachin0817)͞Μͱग़ձ͍
 ΠϯϑϥͷجૅΛڭ͑ͯ௖͘͜ͱʹ •

    LinuxͰͷίϚϯυͷૢ࡞ • DockerͰͷ։ൃ؀ڥͷߏங • AWSͰͷαʔόʔߏங • AnsibleΛར༻ͨ͠ΠϯϑϥίʔυԽ • CircleCIͰͷϦϦʔεࣗಈԽ ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁
  8. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup  ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁ ։ൃ؀ڥߏ੒ਤ •

    ։ൃ؀ڥ͸DockerΛ࠾༻ • nginxͱunicornΛϦόʔεϓϩΩγ • supervisorͰىಈ͢ΔϓϩηεΛ؅ཧ

  9. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup  ϑϥϯεྉཧਓ͔Βۦ͚ग़͠ΤϯδχΞ΁ ຊ൪؀ڥߏ੒ਤ •

    ຊ൪αʔόʔ͸AWS/EC 2 • ߏ੒؅ཧ͸AnsibleΛ࠾༻ • CircleCIͰࣗಈσϓϩΠ • SSLԽ͸Let`sEncrypt ALB΍RDSΛ࢖༻͔͕ͨͬͨ͠
 ίετ࡟ݮͷͨΊ࠷খݶͷߏ੒Ͱӡ༻
  10. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϙʔτϑΥϦΦ࡞੒ͷϙΠϯτ  • όάͷͳ͍ΞϓϦέʔγϣϯΛ࡞Δ

    • ׬੒౓ > ೉͍͠ػೳɺڽͬͨσβΠϯ • ࢖༻ٕज़ͷબఆཧ༝Λઆ໌Ͱ͖Δ • ࠷৽ͷٕज़ΛऔΓೖΕͯ΋ཧ༝͕આ໌Ͱ͖ͳ͍ͱ୯७ʹٕज़͕࢖͍͍ͨਓͳͷ͔ͳͱ
 ࢥΘΕͯ͠·͏ • ݱ৔Ͱ͸՝୊ʹଇٕͨ͠ज़બఆΛ͢Δඞཁ͕͋Δ
 • ࢤ๬ઌͷٕज़ελοΫʹ߹ΘͤΔ • Πϯϑϥ໘Ͱ͸ͳΔ΂͘ίετΛ཈͑ͨΠϯϑϥઃܭΛ͢Δ΂͖(݄/2000~3000ԁ ) • ౰࣌ࣗ෼͸ECS/FargateͰӡ༻ֶ͔͕ͨͬͨ͠शίετ(ӡ༻ίετ΋)͕ߴ࣮͗ͯ͢૷Ͱ͖ͳ͔ͬͨ
 

  11. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup  LancersCreativeCloud→AWS ECS/Fargate •

    Ruby 2.7. 1 • Rails 6.0. 3 • Jque y • AW S • ECS/Fargat e • Docke r • CircleC I • DATADO G • SendGrid ϥϯαʔζ΁Πϯλʔϯͱͯ͠ೖࣾ
  12. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup  • ෳࡶͳόονॲཧͷ࣮૷͔Βద༻·Ͱ •

    TerraformΛॻ͖׵͑ͯυϝΠϯΛมߋ • ΫϥΠΞϯτͷϚΠϖʔδ • Docker։ൃ؀ڥͷվળ • DB੔ཧ • CircleCiͷϦϑΝΫλϦϯά • ใु؅ཧػೳ • ϝʔϧαʔόʔΛSendGridʹҠߦ • etc. • SREͷ҆ୡ͞Μ͕͍ۙҐஔʹ͍ΔͷͰΞϓϦέʔγϣϯͷ
 ࣮૷͚ͩͰͳ͘Πϯϑϥ΋΍Βͤͯ௖͘ػձ͕͋ΔͷͰ
 ෯޿͍࣮຿ܦݧ͕Ͱ͖Δ • ΠϯλʔϯͰ΋ࡋྔͷ͋ΔλεΫΛ೚ͯ͠໯͑Δ ϥϯαʔζ΁Πϯλʔϯͱͯ͠ೖࣾ
  13. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϝʔϧαʔόʔΛSendGridʹҠߦ  ՝୊ (NBJMΞΧ΢ϯτݻ༗ͷ໰୊

     w ଘࡏ͠ͳ͍ϝʔϧΞυϨεʹϝʔϧૹ৴Λ͢ΔͱεύϜೝఆ͞Εϝʔϧૹ৴͕Ұ࣌తʹ 
 ετοϓ͢Δ w Ұ೔ͷϝʔϧૹ৴্ݶ͕ݶΒΕ͍ͯΔ LCC͸ΞϓϦ಺Ͱͷ௨஌ػೳ͕ແ͍ͷͰ
 ϝʔϧ͕ૹ৴͞Εͳ͍ͱΫϥΠΞϯτ͔Βͷ
 ཁ๬Λݟಀͯ͠͠·͏͜ͱ΋ɺɺ
 ݱ৔͔ΒͷΞϥʔτ্͕͕͍ͬͯͨͷͰ
 ૣٸʹରԠ
  14. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϝʔϧαʔόʔΛSendGridʹҠߦ  SMTP API

    ϝϦοτ ϝϦοτ σϝϦοτ σϝϦοτ • ௥੻ػೳʢਖ਼͘͠ૹ৴͞Ε͔ͨ֬ೝͰ͖Δʣ • ෼ੳػೳʢϚʔέςΟϯάʹ׆༻ʣ • ૹ৴཰ͷվળʢSPFɺDKIMͷ׬ᘳͳઃఆʣ • HTTPͰૹ৴͢Δ͜ͱʹΑͬͯrailsΞϓϦଆͷॲཧ͸ϦΫΤετΛ
 ౤͛Δ͚ͩʹͳΔ • ActionMailer͕defalutͰ༻ҙ͍ͯ͠Δ഑৴ํ๏
 Λ࢖͏͜ͱ͸rails wayʹ৐Δ͜ͱͰ͋ΔͷͰ(rails
 ͷ఩ֶͱͯ͜͠Ε͸ॏཁ)ɺ࣮૷ͷखؒ౳͸ল͚Δ • طଘͷActionMailerͱͷڞଘ • RailsαʔόʔଆͰඇಉظॲཧΛ͠ͳ͍ͱ͍͚ͳ͍ • GmailͰૹ৴͍ͯ͠ΔͷͰ্ड़ͨ͠໰୊͕ൃੜ͍ͯ͠Δ
  15. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup  w 4.51͔Β4FOE(SJE"1*΁Ҡߦ w

    "DUJPO.BJMFSͷ֤ϝʔϥʔͷॲཧ͸ͦͷ··ྲྀ༻ w "DUJPO.BJMFSͷ഑৴ํ๏Λ4FOE(SJE"1*༻ʹ৽ͨʹ௥Ճ w طଘͷ֤ϝʔϥʔͰ࡞੒͞ΕͨϝʔϧΦϒδΣΫτ͕࣮ߦ͞ΕͨλΠϛϯάͰ 
 .BJM4FOE(SJEΫϥεΛݺͼग़͠4FOE(SJE༻ͷΦϒδΣΫτʹஔ͖׵͑ w ϝʔϧૹ৴ςετ͸ϞοΫίϯςφΛ༻͍ͯςετ ࣮૷ํ਑ SMTP SendGrid API
  16. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup ϝʔϧૹ৴ςετʹ͍ͭͯ  • SREۚᖒ͞Μ͕࡞ͬͯ͘ΕͨϞοΫίϯςφͰ


    ϝʔϧૹ৴Λςετ • ϞοΫίϯςφͰ༻ҙͨ͠ϞοΫAPIʹϦΫΤετ
 Λૹ৴(ӈਤͷHTTP3030 ) • sendgrid-devܦ༝Ͱmaildev΁SMTPͰϝʔϧ഑৴ • http://xxx.xxx.xxx.xxx:1080/ɹʹΞΫηε͢Δ͜ͱͰ
 maildev΁ϝʔϧ͕ૹ৴͞Ε͍ͯΔ͜ͱ͕ϒϥ΢β্Ͱ
 ֬ೝͰ͖Δ • ΞϓϦଆͷ࣮૷͸Mail:SendGridΫϥε಺Ͱ؀ڥຖʹ
 API઀ଓઌͷϗετΛऔಘ
  17. 2021/9/8 ʲLancers x SUPER STUDIOʳEngineer Meetup Ҡߦͯ͠Ͳ͏ͳ͔ͬͨ  • ϝʔϧͷૹ৴਺਺্ݶ͕ͳ͘ͳͬͨͷͰΞϓϦέʔγϣϯͷ֦ுʹ޲͚ͯҰาલਐ

    • ϥϯαʔζຊՈͰ΋SendGridAPIͰૹ৴͍ͯ͠ΔͷͰ஌ݟΛ׆༻Ͱ͖Δ • ௥੻ػೳ(ϝʔϧͷ഑৴ঢ়گΛݟ͑ΔԽ ) • ϝʔϧ΁ͷΧςΰϦʔઃఆ͕Ͱ͖ΔͷͰϚʔέςΟϯάʹ׆༻ • ૹ৴཰ͷվળ(SPFɺDIKMͷ׬ᘳͳઃఆ ) • APIʹΑΔૹ৴(SMTPͰ͸ͳ͘HTTPͰૹ৴Ͱ͖Δ)