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

ECS/Fargateの活用事例(CakePHP編)

adachin0817
September 25, 2020

 ECS/Fargateの活用事例(CakePHP編)

https://connehito.connpass.com/event/187729/
【ランサーズ社合同勉強会】コネヒトマルシェオンライン「事業を支えるWeb開発」vol.2

adachin0817

September 25, 2020
Tweet

More Decks by adachin0817

Other Decks in Technology

Transcript

  1. 2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ։ൃ؀ڥΛ࡞ΔϙΠϯτ  ɾຊ൪؀ڥͱಉ౳ͷߏ੒Λ࠶ݱ ɾELB(H2O)ίϯςφ(ϦόʔεϓϩΩγ) ɾAppίϯςφ ɹɾPHP5.5-alpine/CakePHP2.5.4/Nginx ɾMySQLίϯςφ ɾSendGridίϯςφ

    ɾphpMyAdminίϯςφ ɾWordPressίϯςφ(PHP7.3-alpine/Nginx) ɾ֤ΞϓϦέʔγϣϯͷىಈ͸SupervisorͰ؅ཧ ɾcomposer install͸AppίϯςφͰϩάΠϯ࣌ʹ࣮ߦ ɹɾsupervisorctlͰΞϓϦΛrestart͢ΔΑ͏ʹ
  2. 2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 Stg/ຊ൪؀ڥͷߏ੒ʹ͍ͭͯ  ɾTerraformͰશϦιʔείʔυԽ ɾStg؀ڥ͸ۃྗίετΛ཈͑λεΫ਺͸1ͭ ɾdevopsίϯςφͷར༻ ɾDB͸RDS AuroraʹҠߦ ɾϝʔϧૹ৴͸Postfix͔ΒSendGridԽ

    ɾίʔϙϨʔταΠτ͸WordPressԽ ɾը૾౳S3Խ ɾWordPressͷը૾ ɹɾWP Offload Media LiteϓϥάΠϯͰS3ʹ ɾϩά͸CloudWatch Logs ɾόον͸ECS Scheduled Tasks ɾ಺෦؂ࠪ(ϩάͷू໿) ɹɾAmazon Kinesis ɾσϓϩΠ͸CircleCIͷΈͰ࣮૷ ɾ؂ࢹ͸Datadog
  3. 2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 APIܦ༝ͰͷStg؀ڥͷσϓϩΠ  ɾStg؀ڥͷσϓϩΠ ɹɾgithub flow ɹɾγΣϧεΫϦϓτ ɹɹɾ೚ҙͷϒϥϯνΛࢦఆ ɾૉૣ͘σϓϩΠ͕Մೳ

    ɹɾ։ൃޮ཰͕Ξοϓ ɾMasterϚʔδͰຊ൪؀ڥϦϦʔε ɾTerraform CI؀ڥΛ࣮૷ $ sh deploy.sh ԼهͷΑ͏ʹϒϥϯνΛࢦఆ࣮ͯ͠ߦ͍ͯͩ͘͠͞ɻ (ྫ) sh deploy.sh ϒϥϯν໊ $ sh deploy.sh fix-nginx { "number" : 74, "state" : "pending", "id" : "xxxxxx-xxxxx-xxxxx-xxx-xxxxxxxx", "created_at" : "2020-08-27T06:14:43.973Z" } ϒϥϯν໊/ fix-nginx ͷStgσϓϩΠΛ։࢝͠·ͨ͠!
  4. 2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ECS Scheduled TasksʹΑΔόον࣮૷ʹ͍ͭͯ  ɾࠓ·Ͱ ɹɾCron ɾݱࡏ ɹɾECS

    Scheduled Tasks ɹɹɾCloudWatchͷΠϕϯτϧʔϧ ɹɹɾTerraformԽ { "containerOverrides": [ { "name": "prosheet-app", "command": [ "php", "/var/www/prosheet/cake/app/Console/cake.php", "-app", "/var/www/prosheet/cake/app", "mail", "exec" ] } ]
  5. 2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ϩά/ίϯςφ؂ࢹʹ͍ͭͯ  ɾΞΫηε/ΞϓϦϩάɺRDS؂ࠪ/Τϥʔϩά ɹɾCloudWatch Logsʹ ɹɾࠓ·Ͱ ɹɹɾLambdaͰS3ʹγϯΫɹɹ ɹɹɾPythonͰ࣮૷͍ͯͨͨ͠Ίӡ༻ίετΞοϓ

    ɹɾࠓճ ɹɹɾAmazon Kinesis Data FirehoseͰS3ʹू໿ ɹɹɾTerraformԽ ɾ؂ࢹ ɹɾMackerel→DatadogʹҠߦ ɹɾλεΫఆٛʹdatadog-agentΛಈ࡞ͤ͞ΔΑ͏ʹ ɹɾcpu:10ɺmemory:256 TerraformԽ
  6. 2020/9/25 ʲϥϯαʔζࣾ߹ಉษڧձʳίωώτϚϧγΣΦϯϥΠϯʮࣄۀΛࢧ͑ΔWeb։ൃʯvol.2 ·ͱΊ  ɾImmutableͳαʔόʔͷӡ༻ ɹɾ҆ఆӡ༻ɺӡ༻ޮ཰ͷΞοϓ ɾϗετΠϯελϯεͷ؅ཧ͕ল͚Δ ɾλεΫ୯ҐͰࣗ༝ʹϦιʔεมߋՄೳ ɾॳΊͯίϯςφຊ൪ӡ༻͢Δʹ͸͔ͳΓϋϚΔ ɹɾϔϧενΣοΫ͕௨Βͳ͍ͱίϯςφ͕མͪΔ

    ɹɾLinuxྗ͕ࢼ͞ΕΔ ɹɾσϓϩΠͷ࣮૷͕େม͕ͩલͷܦݧ͕͋ͬͨ ɹɹɾ͙͢ʹ࣮૷Ͱ͖ͨ ɾσόοά͕ͮ͠Β͍ ɾλεΫͷىಈ଎౓͕஗Ί ɹɾόον࣮ߦ΋਺෼஗͘ͳΔ ɾྉ͕͓ۚߴΊ ɹɾEC2ΑΓׂߴʢ1ׂʙ2ׂʣ ɾࠓޙ ɹɾ·ͣ͸དྷ݄தʹҠߦ ɹɾPHP/CakePHPͷόʔδϣϯΞοϓ ɹɾίϯςφͷ੬ऑੑݕ஌ (Trivy) ɹɾDatadogͰϩά࿈ܞ ɹɾChatOpsʹΑΔσϓϩΠ ɹɾPHP CI؀ڥͷ࣮૷ ɹɾϥϯαʔζຊՈ΋ίϯςφҠߦʹνϟϨϯδ