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

EC2 & 手動デプロイから ECS& CodePipeline に変えてみた

IshinShibata
July 13, 2021
900

EC2 & 手動デプロイから ECS& CodePipeline に変えてみた

IshinShibata

July 13, 2021
Tweet

Transcript

  1. ΞδΣϯμ ❏ ܦҢ ❏ &$4ͷ֓ཁ ❏ &$4࡞੒·Ͱͷ͋Ε͜Ε ❏ ٧·ͬͨͱ͜Ζᶃ ❏

    ٧·ͬͨͱ͜Ζᶄ ❏ $PEFQJQFMJOFಋೖ ❏ ·ͱΊ d&$खಈσϓϩΠ͔Β &$4ˍ $PEF1JQFMJOFʹม͑ͯΈͨ d
  2. Pipeline Transition Stage Action Action Stage Action Action Action 1JQFMJOF

    $PEFQJQFMJOFͷ࠷্Ґ֓೦ɻ֤ϓϩηε Λ·ͱΊͨ΋ͷ 4UBHF 1JQFMJOFͷҰ࿈ͷϓϩηεɻϏϧυɺςε τɺσϓϩΠ͕͜Εʹ͋ͨΔ "DUJPO 4UBHF্ͷ۩ମతͳλεΫɻ৽͍͠ίϯ ςφͷλεΫʹஔ͖׵͑Δͱ͔ɺ%PDLFS CVJMEɺ%PDLFSQVTIͳͲ 5SBOTJUJPO ࣍ͷεςʔδʹҠΔॲཧ
  3. Action Category(アクション内容) Action Providers(どのサービスが行うか) Souce Amazon S3, Amazon ECR, CodeCommit,

    Github, Bitbucket Build CodeBuild, Jenkins Test CodeBuild, Jenkins Deploy Amazon S3, Amazon ECS, CodeDeploy
  4. Pipeline Souce Deploy Build docker build, ECRへの docker-push git pushをトリガーにpipeline

    の実行し、ソースを取得 古いコンテナを新しいコンテ に差し替える Transition Transition buildspec.yml imagedefinitions .json version: 0.2 phases: pre_build: commands: - $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email) 環境変数定義ができる build: commands: - docker build -t $AWS_ACCOUNT_ID.dkr.ecr.ap-northeast-1.amazonaws.com/rails:latest . post_build: commands: - docker push $AWS_ACCOUNT_ID.dkr.ecr.ap-northeast-1.amazonaws.com/rails:latest - echo Writing image definitions file... - printf '[{"name":"rails","imageUri":"%s"}]' - $AWS_ACCOUNT_ID.dkr.ecr.ap-northeast-1.amazonaws.com/rails:latest > imagedefinitions.json artifacts: files: imagedefinitions.json [ {"name":"rails","imageUri":"AWS_ACCOUNT_ID.dkr.ecr.ap-northeast- 1.amazonaws.com/rails:latest"} ]
  5. $PEFγϦʔζͰ࢝ΊΔ͸͡Ίͯͷ$*$% IUUQTEFWDMBTTNFUIPEKQBSUJDMFTDJDEXJUIDPEFTFSJFTBUIJHPCBTIJBXT ϙʔτϑΥϦΦΛ&$4Ͱʂʳ3BJMTº/HJOYΞϓϦΛ'BSHBUFʹσϓϩΠ͢Δ·ͰΛஸೡʹઆ໌ͯ͠Έͨ 71$࡞੒ʙ$JSDMF$*ʹΑΔࣗಈσϓϩΠ·Ͱ લฤ IUUQTRJJUBDPNNBSVJUFNTFEBCBEFEBEC ʲ"84ೖ໳ʳ&$4 'BSHBUF ͱ&$3Ͱָʑίϯςφ͔Β)FMMP8PSME͠Α͏ʂ IUUQTXXXZPVUVCFDPNXBUDI

    W@'Y-QYHNP ॳ৺ऀͰ΋Ͱ͖Δʂ &$4º &$3º $JSDMF$*Ͱ3BJMTΞϓϦέʔγϣϯΛίϯςφσϓϩΠ IUUQTRJJUBDPNTBPOHUYJUFNTGEEC ࢀߟࢿྉ "84$PEF1JQFMJOFͰ $*$%ͷ࢓૊ΈΛߏங͓ͨ͠࿩ IUUQTCMPHTQBDFNBSLFUDPNDPEFDJDEDPEFQJQFMJOF "NB[PO&$$POUBJOFS4FSWJDF &$4 ͷ֓೦੔ཧ IUUQTRJJUBDPN/FX(ZVJUFNTFEFEBCEE