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

CircleCI初心者が、AWS/EC2へWEBページの反映作業を自動化してみた!

 CircleCI初心者が、AWS/EC2へWEBページの反映作業を自動化してみた!

F060c1ea407b622c00087e2353645778?s=128

hikaru-miyazawa

June 28, 2019
Tweet

Transcript

  1. CIRCLECIॳ৺ऀ͕ɺAWS/EC2΁WEBϖʔδ ͷ൓ө࡞ۀΛࣗಈԽͯ͠Έͨʂ MEILY INC INFRA SRE HIKARU MIYAZAWA

  2. 2 AGENDA 1. ࣗݾ঺հ 2. CercleCIΛಋೖ͠Α͏ͱࢥͬͨܦҢ 3. CircleCIͰWEBϖʔδͷ൓өࣗಈԽ 4. CircleCIͷIPڐՄͱϒϥϯνʹΑͬͯ൓өઌΛม͑Δ

    5. ·ͱΊ
  3. 3 HIKARU MIYAZAWA ɾ2016/10ʙ2017/3
 લ৬ͰΠϯλʔϯɺΠϯϑϥͷۀ຿OJT ɾ2017/4ʙ2017/11
 Πϯλʔϯޙೖࣾ ΠϯϑϥSREνʔϜ
 ɾ2017/11ʙࠓ·Ͱ
 גࣜձࣾMeily

    ૑ۀ ઐ೚ͰΠϯϑϥΛ୲౰ झຯɿϙέΧ,DQR,͓ञ(ϋΠϘʔϧ͕޷͖)
 ޷͖ͳٕज़ɿFargate,Ansible,Terraform,CircleCI←new!
  4. 4 CERCLECIΛಋೖ͠Α͏ͱࢥͬͨܦҢ ▸ HP΍Q&A౳ͷϖʔδΛߋ৽͢Δͱ͖ʹɺSSHͯ͠υΩϡ ϝϯτϧʔτͰ git pull ͢Δ͜ͱͰߋ৽͍ͯͨ͠ɻ ▸ σβΠφʔ͕SSH΍ίϚϯυϥΠϯΛ࢖͏ඞཁ͕͋ͬͨ

    ▸ ϝϯόʔ͕৽͘͠PCΛങ͍ସ͑ͨΓॳظԽͨ࣌͠ʹɺ SSHͷઃఆΛ͠௚͢ͷ͕ͭΒ͍ɻɻ ▸ SSH͢ΔͨΊʹIPڐՄ͢Δඞཁ΋
  5. 5 CERCLECIΛಋೖ͠Α͏ͱࢥͬͨܦҢ ▸ AWS Summit Tokyo 2019ʹࢀՃ͖ͯ͠·ͨ͠ʂ ▸ ༑ਓͷΤϯδχΞʮcircle ci

    ͸͍͍ͧʯ
 

 ▸ circle ciϒʔεͰฉ͍ͯΈΔʂ
 


 ▸ TγϟπΛ΋Βͬͯ΍Δؾʹˡ ▸ ొஃػձΛ͍͖ͨͩ͋Γ͕ͱ͏͍͟͝·͢ʂ
 

  6. 6 CIRCLECIͰWEBϖʔδͷ൓өࣗಈԽ ΍͍͖ͬͯ·͢ʂ

  7. 7 WEBαʔόͷߏ੒ ▸ AWS/EC2 ▸ Route53→CloudFront→ALB→EC2 ▸ OS AmazonLinux ▸

    H2O 2.2.4
  8. 8 GITHUB࿈ܞͰϩάΠϯ ▸ ϩάΠϯ ▸ GitHub organization Ͱ circleci ͔ΒͷΞΫηεΛڐՄ

    ▸ Switch Organization Ͱબ୒
  9. 9 CONFIG.YML ▸ .circleci/config.ymlΛ࡞੒ͯ͠ϓογϡ͠·͢ɻ

  10. 10 SET UP PROJECT ▸ ࢖͏ϦϙδτϦͷSetUpProjectΛΫϦοΫ͠·͢ʂ

  11. 11 CIRCLECI͋Δ͋Δ ▸ ബ͍ਫ৭ͷϘλϯԡ࣌͢ʹෆ҆ʹͳΔ

  12. 12 ԡ͠·͢

  13. 13 ઃఆ ࠷ॳ͸ࣦഊ͠·͕͢ɺؾʹͤͣઃఆΛ͍͖ͯ͠·͢ɻ

  14. 14 SSH伴࡞੒ ൿີ伴ΛCircleCIʹొ࿥͠ɺެ։伴Λαʔόʹ഑ஔ

  15. 15 伴ͷొ࿥ fingerprint͸ޙ΄ͲίʔυͰ࢖͏ͷͰίϐʔ͓͖ͯ͠·͢ɻ

  16. 16 ؀ڥม਺ͷొ࿥ HOST_NAMEͱUSER_NAMEΛొ࿥͠·͢

  17. 17 ؀ڥม਺ͷొ࿥ HOST_NAMEͱUSER_NAMEΛొ࿥͠·͢

  18. 18 վΊͯ΍ͬͯΈΔ ίʔυΛมߋͯ͠gitʹ͋͛Δ͚ͩͰɻ੒ޭʂ

  19. 19 վΊͯ΍ͬͯΈΔ ίʔυΛมߋͯ͠gitʹ͋͛Δ͚ͩͰɻ੒ޭʂ

  20. 20 ϖʔδ֬ೝ

  21. 21 ແࣄͰ͖͕͍͔࣮ͨͭ͘ݱ͍ͨ͜͠ͱ͕ ‣ ϒϥϯνຖʹผͷαʔόʹ൓ө͍ͨ͠ɻ ‣ SSH࢖ͬͯΔ͚ͲɺCircleCI͞ΜͷIPຖճมΘΔ͠Ͳ͏ͨ͠ Β͍͍ͷʂ ‣ Ϗϧυத͚ͩCircleCIͷIPڐՄͯ͠ɺϏϧυऴΘͬͨΒϧʔ ϧΛফͤͨΒϕετ

  22. 22 CIRCLECIͷIPڐՄͱϒϥϯνʹΑͬͯ൓өઌΛม͑Δ ‣ ͍Ζ͍ΖGoogleௐ΂ͯΈΔͱɺ͍͍ײ͡ͷࣄྫ͕͍ͭ͘ ΋ʂ
 
 ͬͦ͘͞΍ͬͯΈ·͢ʂ

  23. 23 CIRCLECIͷIPڐՄͱϒϥϯνʹΑͬͯ൓өઌΛม͑Δ ‣ AWSCLIΛ࢖ͬͯ൓өத͚ͩIPڐՄɺऴΘͬͨΒด͡Δ ‣ CLIΛ࢖͏ͨΊIAMͷઃఆ ‣ config.ymlͷॻ͖ํͰϒϥϯνຖʹ൓өઌΛม͑ΒΕΔ ‣ ඞཁͳ؀ڥม਺Λదٓొ࿥

  24. 24 IAMͷઃఆᶃ αʔϏεɺIAMɺϙϦγʔɺϙϦγʔͷ࡞੒
 ηΩϡϦςΟάϧʔϓͷૢ࡞ͷΈΛڐՄ͢ΔϙϦγʔΛ࡞੒

  25. 25 IAMͷઃఆᶄ άϧʔϓʹϙϦγʔΛΞλον͠ɺάϧʔϓΛ࡞੒͠·͢ɻ

  26. 26 IAMͷઃఆᶅ Ϣʔβʔ࡞੒͠·͢ɻ

  27. 27 IAMͷઃఆᶆ ઌఔͷάϧʔϓʹ௥Ճɻ

  28. 28 IAMͷઃఆᶇ ΞΫηεΩʔͱγʔΫϨοτΞΫηεΩʔΛϝϞ͓͖ͯ͠·͢

  29. 29 ؀ڥม਺ͷొ࿥ DEVͱPRDͦΕͧΕͷ؀ڥม਺Λొ࿥͠·͢ɻ

  30. 30 CONFIG.YMLͷղઆᶃ

  31. 31 CONFIG.YMLͷղઆᶄ

  32. 32 CONFIG.YMLͷղઆᶅ

  33. ͍͟PUSHʂ
 ˠMergeʂ

  34. 34 ։ൃɺຊ൪ڞʹ੒ޭʂ

  35. 35 ·ͱΊ ▸ ൓ө࡞ۀ͸Gitʹ͋͛Δ͚ͩʂૣ͍ʂࣗಈԽૉ੖Β͍͠ ▸ αʔό؅ཧऀͱɺσβΠφʔ΍ΤϯδχΞͱͷྖҬΛ໌֬ʹ ෼͚ΒΕ·ͨ͠ʂ ▸ νϡʔτϦΞϧɺυΩϡϝϯτɺهࣄ͕๛෋Ͱײँɻɻ
 ▸

    ࠓޙ͸ECS΁ͷσϓϩΠ΋ࣗಈԽ͍͖͍ͯͨ͠ʂ

  36. 36 ࢀߟϦϯΫ ‣ެࣜυΩϡϝϯτ ‣https://circleci.com/docs/ja/ ‣Circle CIͰwebαΠτΛࣗಈσϓϩΠ ‣https://esnetk6.com/2018/04/circle-ci-deployment/
 ‣CircleCI2.0͔ΒEC2ʹΞΫηε͢Δͱ͖͚ͩಛఆͷIPΛڐՄ ͍ͨ͠ ‣https://qiita.com/rintaro-ishikawa/items/

    02e6a63dbc90ea67a991
  37. ͝ਗ਼ௌ
 ͋Γ͕ͱ͏͍͟͝· ͨ͠ʂ