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

AWS CodeBuild introduction

664b6e8ebe272fcfa5dbd6070eaf3cd4?s=47 Yusuke Wada
February 10, 2017

AWS CodeBuild introduction

AWS CodeBuild introduction - AWS CodeBuildのご紹介。re:Invent2016で発表されたAWSの新サービス、AWS CodeBuildについての紹介と、使い方の説明をしています。

664b6e8ebe272fcfa5dbd6070eaf3cd4?s=128

Yusuke Wada

February 10, 2017
Tweet

Transcript

  1. AWS CodeBuild

  2. ΋͘͡ • AWS CodeBuildͱ͸ • ͳʹ͕͏Ε͍͠ͷ͔ʁ • ϏϧυαʔϏεൺֱ • ࢼ͢

    • Ϣʔεέʔε • ஫ҙ఺ 2
  3. AWS CodeBuild ͱ͸

  4. ͱ͋ΔΞϓϦέʔγϣϯͷϏϧυϓϩηε 1. Unit TestͷͨΊʹϞοΫαʔϏεΛΠϯετʔϧ͢Δ 2. ςετΛ࣮ߦ͢Δ 3. ੒Ռ෺Λੜ੒͢ΔεΫϦϓτ͕RakefileͳͷͰrubyΛΠϯετʔϧ 4. rake࣮ߦ

    5. ੜ੒͞Εͨ੒Ռ෺ΛS3ʹΞοϓϩʔυ͢ΔͨΊawsΫϥΠΞϯτΛಋೖ 6. S3΁ͷΞοϓϩʔυͷͨΊʹΞΫηεΩʔΛઃఆ 7. S3΁Ξοϓϩʔυ 4
  5. 1. Unit TestͷͨΊʹϞοΫαʔϏεΛΠϯετʔϧ͢Δ 2. ςετΛ࣮ߦ͢Δ 3. ੒Ռ෺Λੜ੒͢ΔεΫϦϓτ͕RakefileͳͷͰrubyΛΠϯετʔϧ 4. rake࣮ߦ 5.

    ੜ੒͞Εͨ੒Ռ෺ΛS3ʹΞοϓϩʔυ͢ΔͨΊawsΫϥΠΞϯτΛಋೖ 6. S3΁ͷΞοϓϩʔυͷͨΊʹΞΫηεΩʔΛઃఆ 7. S3΁Ξοϓϩʔυ ͱ͋ΔΞϓϦέʔγϣϯͷϏϧυϓϩηε 5 Ϗϧυϓϩηεͷ ଟ༷ԽɾෳࡶԽ
  6. Ұํ

  7. — Martin Fowler, Continuous Integration, 01 May 2006 ΑΓͻΜͺΜʹΠϯςάϨʔγϣ ϯΛߦ͏΄͏͕ɺ·Εʹ͔͠ߦ

    Θͳ͍ΑΓ΋๬·͍͠ ” “
  8. ܧଓతΠϯςάϨʔ γϣϯͷͨΊͷ ϏϧυαʔϏεɾπʔ ϧ͕ొ৔

  9. AWS͸ɺϏϧυαʔϏε͚͕ͩͳ͔ͬͨ AWS CodePipeline: How to Create a Custom Action –

    Linux Academy Blog https://linuxacademy.com/blog/amazon-web-services-2/aws-codepipeline-how-to-create-a-custom-action/
  10. AWS͸ɺϏϧυαʔϏε͚͕ͩͳ͔ͬͨ AWS CodePipeline: How to Create a Custom Action –

    Linux Academy Blog https://linuxacademy.com/blog/amazon-web-services-2/aws-codepipeline-how-to-create-a-custom-action/
  11. ͳʹ͕͏Ε͍͠ͷ͔ʁ

  12. AWSͰ ׬݁͢Δ ͱ͍͏͜ͱ • Ϗϧυϓϩηεʹ͓͍ ͯΞΫηεΩʔͰ͸ͳ ͘IAMϩʔϧͰAWSϦ ιʔε΁ΞΫηεՄೳ • ඞཁͳ෼͚ͩ࢖͍ɺ࢖ͬ

    ͨ෼͚ͩ՝ۚ • ϏϧυϘϦϡʔϜʹԠ ͯࣗ͡ಈεέʔϧ 12
  13. ϏϧυαʔϏεൺֱ

  14. ఏڙܗࣜ • ύοέʔδΠϯετʔϧܕ 14 • ϑϧϚωʔδυαʔϏεܕ • ϑϧϚωʔδυαʔϏεܕ

  15. ྉۚମܥ • ແྉɻͨͩ͠ΠϯετʔϧઌαʔόͷՔಇඅ͸ඞཁɻ 15 • GitHubެ։ϦϙδτϦͷ৔߹ɺແྉɻ • GitHubϓϥΠϕʔτͷ৔߹ɺֹ݄/೥ֹ ՝ۚɺఆ੍ֹɻ •

    ֹ݄՝ۚɺैྔ੍ɻ
  16. ΢Ϧ • ߴΧελϚΠζੑɻଟ͘ͷϓϥάΠϯ͕ެ։͞Ε͍ͯΔɻ • Ϗϧυ͚ͩͰͳ͘ςετͷϨϙʔςΟϯά΋Մೳɻ 16 • GitHubͱͷ਌࿨ੑɺMac / iOSΞϓϦͷϏϧυ΋Մɻ

    • ϏϧυαʔόͷࣗಈεέʔϧɺIAMʹΑΔΞΫηε؅ཧɻ
  17. ͲΜͳͱ͖ʹ࢖͏ʁ • ࣾ಺ʹJenkins͓͡͞Μ͕ډΔɻ • ςετ݁ՌͷϨϙʔςΟϯάۀ຿Λߦ͍͍ͨɻ 17 • ΦʔϓϯιʔεϓϩδΣΫτΛςετ͍ͨ͠ɻ • iOSΛϏϧυ͍ͨ͠ɻ

    • AWSϦιʔεʹΞΫηεͯ͠౷߹ςετΛ͍ͨ͠ɻ • σϓϩΠઌ͕AWSͰɺCodeDeployΛ࢖͍ͬͯΔɻ
  18. 1ϲ݄ͷྉۚࢼࢉ • 5ਓνʔϜʢWebΞϓϦɺAndroidΞϓϦɺAPIɺCMSΛ։ൃʣԾఆ • GitHubͷϓϥΠϕʔτϦϙδτϦΛར༻ʢͳͷͰTravisCI͸༗ྉʣ • ൟ๩ظ͸1೔͋ͨΓ100ͷϏϧυ͕૸Δ • ൟ๩ظ͸ಉ࣌ʹ5ͭͷϏϧυ͕૸Δ͜ͱ͕͋Δ •

    ൟ๩ظ͸Ұϲ݄ଓ͘ 18
  19. 1ϲ݄ͷྉۚࢼࢉ - TravisCI • Small Business Λબ୒ • $249 per

    month 19
  20. 1ϲ݄ͷྉۚࢼࢉ - CodeBuild • medium Λબ୒ • 0.01$/min × (

    5mim × (100 * 30) ) = 150 $ • $150 per month 20
  21. ࢼ͢

  22. CodeBuildΛಈ࡞ͤ͞Δखॱ 1. ϏϧυϓϩδΣΫτΛ࡞੒͢ΔʢAWSଆʣ 2. buildspec.ymlΛϓϩδΣΫτϧʔτʹ༻ҙ͢Δʢιʔείʔυଆʣ 3. ϏϧυΛ࣮ߦ͢ΔʢAWSଆʣ 4. ݁ՌΛ֬ೝ͢Δ 22

  23. ϏϧυϓϩδΣΫτΛ࡞੒͢Δ • Sourceɿ
 GitHubͱ࿈ܞ͢Δ͜ͱͰɺϓ ϥΠϕʔτϦϙδτϦͷιʔε ίʔυΛϏϧυ͢Δ͜ͱ΋Մ ೳ 23

  24. ϏϧυϓϩδΣΫτΛ࡞੒͢Δ • Environmentɿ
 ϏϧυίϚϯυ͕ϓϦΠϯε τʔϧ͞Εͨαʔό·ͨ͸ Dockerίϯςφ্Ͱ࣮ࢪ 24 Build Environment Reference

    for AWS CodeBuild http://docs.aws.amazon.com/ ja_jp/codebuild/latest/userguide/build- env-ref.html • Artifactsɿ
 ੒Ռ෺ΛS3ʹஔ͘Α͏ʹ͢Δ
  25. ϏϧυϓϩδΣΫτΛ࡞੒͢Δ • Service roleɿ
 Ϗϧυ࣮ߦ࣌ͷIAMϩʔϧΛ બ୒ • Advances settingsɿ
 λΠϜΞ΢τ


    ܭࢉػλΠϓ
 ؀ڥม਺
 ͳͲΛઃఆ͢Δ • ͜ΕͰϏϧυϓϩδΣΫτ͕ ׬੒ 25
  26. buildspec.yml • ιʔεϦϙδτϦʹίϛοτ ͢ΔϓϩδΣΫτͷϧʔτʹ ༻ҙ • Ϗϧυ࣌ɺAWS CodeBuild͕ buildspec.ymlΛΈ࣮ͯࢪ͢Δ ΂͖಺༰Λղऍ͢Δ

    • ௥ՃͰඞཁͳ΋ͷͷΠϯετʔ ϧ΍ɺϏϧυίϚϯυ࣮ߦͷ ࢦࣔॻ 26
  27. buildspec.yml • installɿ
 ςετͰར༻͢ΔɺϩʔΧϧαʔϏ εͳͲΛΠϯετʔϧ͢Δ • pre_buildɿ
 ϏϧυલͷαʔϏεىಈॲཧ • buildɿ


    Ϗϧυɾςετ࣮ߦ • post_buildɿ
 ੒Ռ෺ͷ࡞੒΍௨஌ͳͲ • buildspec.yml΋ҰॹʹϦϙδτϦ ΁PUSH 27
  28. Ϗϧυ࣮ߦ • ํ๏͸େ͖͘;ͨͭ • AWSίϯιʔϧ͔ΒϏϧυ Λ࣮ߦ͢Δ • AWS ίϚϯυΫϥΠΞϯτ ΍SDKΛ༻͍ͯϩʔΧϧϚ

    γϯ͔Β࣮ߦ 28
  29. ݁ՌΛ֬ೝ͢Δ

  30. Ϣʔεέʔε

  31. Q. ϩʔΧϧ؀ڥͰͷςετͷͨΊʹɺ͢Ͱʹνʔ ϜͷͨΊʹ༻ҙͨ͠DockerΠϝʔδ͕͋Δ • AWS CodeBuildͰ͸ςετ࣮ߦ؀ڥͱͯ͠DockerΛબ୒Ͱ͖Δɻ༻ ҙͨ͠DockerΠϝʔδΛDockerHubʹΞοϓϩʔυ͠ɺAWS CodeBuildͷϓϩδΣΫτ࡞੒ஈ֊ͰϏϧυ؀ڥͱͯ͠Ξοϓϩʔυ ͨ͠DockerΠϝʔδΛࢦఆ͢Δɻbuildspec.ymlʹ͸ύοέʔδͷΠ ϯετʔϧॲཧ͸ඞཁͳ͘ͳΔɻ

    31
  32. Q. ಛఆͷϒϥϯνʹϓογϡʗϚʔδ͞Εͨͱ͖ɺ ࣗಈͰσϓϩΠ͞ΕΔΑ͏ʹ͍ͨ͠ • AWS CodePipelineΛηοτΞοϓ͢Δɻ Sourceͱͯ͠GitHubͷϒϥϯνΛબ୒͠ɺ BuildʹCodeBuildΛ࢖͏ɻੜ੒͞ΕͨΞʔςΟ ϑΝΫτΛCodeDeployΛ༻͍ͯಛఆͷEC2 Π

    ϯελϯεʹσϓϩΠ͢Δɻ 32
  33. AWS CodeBuildͷ஫ҙ఺ • ౦ژϦʔδϣϯະରԠ 
 EU (Ireland), US East (N.Virginia),

    US East (Ohio)US, West (Oregon) • iOS / MacΞϓϦ ͷϏϧυ͸ະରԠ • ແྉར༻࿮ 100෼ ͸ build.general.small ͷλΠϓͷΈ • Ϗϧυ؀ڥʹ Docker ΠϝʔδΛࢦఆͨ͠৔߹ɺENTRYPOINT, CMD ͕ಈ࡞͠ͳ͍ʢແࢹ͞ΕΔʁʣ 33
  34. ݁࿦1ɿTravisCI, CircleCI͔Β৐Γ׵͔͑ͯͭ͏ • ·ͩ͋ΘͯΔΑ͏ͳ࣌ؒ͡Όͳ͍ • ΍ΔͳΒνʔϜશһΛ׬શʹ৐Γ׵͍͑ͨ • Mac, iOS ϏϧυʹରԠ͢ΔͱҰؾʹՃ଎ͦ͠͏

    • ϏϧυεςʔλεͷύϒϦοΫAPI͕ཉ͍͠ʢAPI Gateway + AWS Lambda + AWS CodeBuild API + S3 Ͱ΍Ζ͏ͱࢥ͑͹Ͱ͖Δʁʣ • ౦ژϦʔδϣϯʹ͖ͨΒຊؾͩ͢ 34
  35. ݁࿦2ɿTravisCI, CircleCIͱॅΈ෼͚͔ͯͭ͏ • ΞʔΩςΫνϟ͕AWSͰ׬͍݁ͯ͠Δ৔߹͸࠾༻Ձ஋͕ߴ͍ • Unit Test ໨తͰͳ͘ɺ࣮ࡍʹAWSϦιʔεʹΞΫηεͯ͠ͷςετ ͸CodeBuild͕΍Γ΍͍͢ •

    ΠϯςάϨʔγϣϯςετ • ෛՙςετ • ηΩϡϦςΟςετ 35
  36. ࢀߟ • AWS CodeBuild Documentation - https://aws.amazon.com/jp/ documentation/codebuild/ • CodeBuild

    ʛ ಛूΧςΰϦʔ ʛ Developers.IO http:// dev.classmethod.jp/referencecat/aws-codebuild/ 36