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

はてなにおけるGitHub Actions活用事例 / GitHub Actions in Hatena

120b74af626c2b23f954926ef68ac5d6?s=47 papix
January 26, 2021

はてなにおけるGitHub Actions活用事例 / GitHub Actions in Hatena

120b74af626c2b23f954926ef68ac5d6?s=128

papix

January 26, 2021
Tweet

Transcript

  1. ͸ͯͳͰͷ GitHub Actions׆༻ࣄྫ CI/CD׆༻ࣄྫˍTIPSൃදձ id:papix (גࣜձࣾ͸ͯͳ)

  2. ࣗݾ঺հ • papix (id:papix / @__papix__) • גࣜձࣾ͸ͯͳ WebΞϓϦέʔγϣϯΤϯδχΞ (2017೥ʙ)

    • ϒϩάMediaνʔϜ → ϚϯΨνʔϜ • Ұൠࣾஂ๏ਓJapan Perl Associationཧࣄ • ϒϩά: https://papix.hatena(blog.(com|jp)|diary.jp)
  3. ࠓ೔࿩͢͜ͱ • ň͸ͯͳͰͷGitHub Actions׆༻ࣄྫʼn • 2ͭͷαʔϏεΛ୊ࡐʹͯ͠, ҎԼʹ͍ͭͯ࿩͠·͢: • GitHub Actions΁ͷҠߦ,

    ͦͷதͷ޻෉, ίετܭࢉ • GitHub ActionsͷϝϦοτ/σϝϦοτ • ͓΋͠ΖςΫ
  4. ୊ࡐ

  5. ͸ͯͳϒϩά

  6. ͸ͯͳϒϩάMedia

  7. GigaViewer • ࣾ಺Ͱ։ൃ͍ͯ͠ΔϚϯΨϏϡʔϫ • ϒϥ΢βͰອըΛಡΉͨΊͷػೳΛఏڙ • Ϗϡʔϫ / τοϓϖʔδ /

    ݕࡧը໘ / ؅ཧը໘ ... • ग़൛༷ࣾ޲͚ʹఏڙ • 11ࣾ / 13ͷαΠτͰ࠾༻
  8. গ೥δϟϯϓʴ גࣜձࣾूӳ༷ࣾ (https://shonenjumpplus.com/)

  9. ίϛοΫDAYS גࣜձࣾߨஊ༷ࣾ (https://comic-days.com/)

  10. ίϛοΫϒγϩʔυ WEB גࣜձࣾϒγϩʔυϝσΟΞ༷ (https://comicbushi-web.com/)

  11. ͜Ε·Ͱͷ͋Β͢͡

  12. ैདྷͷCI؀ڥ • EC2্ʹߏஙͨ͠Jenkins • ։ൃʹؾΛऔΒΕͯ, Ͳ͏ͯ͠΋อक؅ཧ͕ޙճ͠ʹ͞Ε͕ͪ.. • ྺ࢙తܦҢʹΑΓ, ಉ࣌ʹ࣮ߦͰ͖ͳ͍ςετ •

    ಉ࣌ʹͨ͘͞Μͷpush͕ߦΘΕΔͱ, ςετ͕ऴΘΔ·Ͱ਺े෼ ଴ͭඞཁ΋...
  13. GitHub.comԽͱGitHub Actionsͷొ৔ • ͦͷࠒ, GitHub EnterpriseΛGitHub.comʹஔ͖׵͑Δಈ͖͕͋ͬͨ • ͦͷྲྀΕͷதͰ, GitHub Actions΋ొ৔͖ͯͨ͠

    • ň͜Ε͸࢖͏͔͠ͳ͍!!!ʼn • ...ͱ͍͏͜ͱͰ, ࠷େͷωοΫͩͬͨňςετʼnͷGitHub ActionsԽ 
 ͔ΒऔΓ૊Ή͜ͱʹͨ͠
  14. GitHub Actionsͱ͸?

  15. GitHub Actions • GitHub͕ఏڙ͢ΔCI/CD؀ڥ • Linux, macOS, Windows؀ڥʹରԠ • GitHub

    ActionsͰͷॲཧ͸ϫʔΫϑϩʔΛॻ͘ࣄͰఆٛ • ϦϙδτϦͷ .github/work f l ow σΟϨΫτϦʹYAMLͰهड़
  16. GitHub Actions • GitHubͱ"ྑ͍ҙຯͰ"ີ݁߹͍ͯ͠Δ • pushͨ͠Βଈ࠲ʹॲཧΛ࣮ߦͯ͘͠ΕΔ • ྉۚ • Linuxͷ৔߹,

    1෼͋ͨΓ $0.008 • GitHub Enterprise CloudͳΒ݄50,000෼ͷແྉ࿮΋͋Γ
  17. ςετͷGitHub ActionsԽ

  18. ։ൃ؀ڥͷDockerԽ • ࠷ॳʹ։ൃ؀ڥΛDockerԽ͓͖ͯ͠·͠ΐ͏ • ࣗ෼ͷPCͰςετ͕DockerͰ׬݁͢Ε͹, GitHub ActionsͰ΋ 
 ςετ͸ͪΌΜͱಈ͘͸ͣ! •

    docker-compose.yml ʹඞཁͳϛυϧ΢ΣΞͳͲͷఆٛΛॻ͍ͯ, 
 docker-compose run ͰςετΛ࣮ߦͰ͖ΔΑ͏ʹ͢Δ
  19. ϫʔΫϑϩʔͷߏங • ։ൃ؀ڥͷDockerԽ͕׬͍ྃͯ͠Ε͹, ͦ͏೉͘͠͸ͳ͍͸ͣ • ΠϝʔδΛϏϧυͯ͠, docker-compose runͰςετΛ࣮ߦͯ͠...

  20. GitHub ActionsԽ ʙ׬ʙ

  21. ...ͱ, ؆୯ʹ͸͍͔ͳ͍ • ͍Ζ͍Ζߟ͑Δࣄ͕͋Δ! • ςετͷ࣌ؒΛͳΔ΂͘୹͘͢Δ • ίετͷࢼࢉ • Jenkins͔Βͷஔ͖׵͑࡞ઓ

    • etc...
  22. ࣮ߦ࣌ؒͷ࡟ݮ

  23. DockerͷΠϝʔδ͸౎౓Ϗϧυ͠ͳ͍ • ňͦΓΌͦ͏ͩ!ʼnͱ͍͏ײ͡Ͱ͕͢... • ։ൃ؀ڥͷdocker imageΛECRʹొ࿥ͯ͠, ςετ͢Δ͝ͱʹ 
 ౎౓pull͢Δͱ͍͏࡞ઓ͕࢖͑Δ

  24. ECR͔Β pull͢Δྫ name: tes t on : pull_request : jobs

    : test : - uses: actions/checkout@v2.3. 4 - name: Configure AWS Credential s uses: aws-actions/configure-aws- credentials@v1.5. 5 with: .. . - name: Login to Amazon EC R uses: aws-actions/amazon-ecr-login@v1.3. 1 - name: Pull from EC R run: docker pull ...
  25. ςετͦͷ΋ͷʹ͕͔͔࣌ؒΔ • GitHub Actions͸AzureͷStandard_DS2_v2্Ͱಈ࡞͢Δ • εϖοΫ͸vCPU 2, ϝϞϦ 7GB •

    ී௨ʹςετΛճ͢ͱ, 1࣌ؒܦաͯ͠΋ऴΘΒͳ͍...
  26. ࡞ઓ • ͦ͜Ͱ, ࣍ͷΑ͏ͳ࡞ઓΛߟ͑·ͨ͠: • self-hosted runnerΛ࢖͏ • AWS CodeBuildΛ࢖͏

  27. self-hosted runner • ࣗ෼͕࡞ͬͨ؀ڥͰGitHub ActionsͷॲཧΛ࣮ߦͰ͖Δ࢓૊Έ • ඞཁͳ؀ڥΛߏஙͯ͠, GitHubʹొ࿥͢Δͱར༻Ͱ͖Δ • ϦϙδτϦ/Organization/EnterpriseͷϨϕϧͰڞ༗Ͱ͖Δ

    • ੲ͸ϦϙδτϦ୯ҐͰ͔͠ొ࿥͕ग़དྷͳ͔ͬͨهԱ͕͋Δ
  28. self-hosted runner • self-hosted runner͸جຊతʹىಈͬ͠ͺͳ͠ • = ॲཧΛ͍ͯ͠ͳͯ͘΋ίετ͕͔͔Δ • self-hosted

    runner 1୆ʹ͖ͭ1ͭͷॲཧ͔͠ग़དྷͳ͍ • ෳ਺ͷॲཧΛ͚ͨ͠Ε͹, ෳ਺୆ͷself-hosted runner͕ඞཁ
  29. AWS CodeBuild • AWS CodeBuildͳΒ, vCPU 32, ϝϞϦ144GBͷ؀ڥ͕͋Δ! • self-hosted

    runnerͱҧ͍, ౎౓࣮ߦ/౎౓՝ۚ • ͨͩ, ňGitHub Actions͔ΒAWS CodeBuildΛىಈʼn͸Ͳ͏ͳͷ͔? • ͩͬͨΒňJenkins͔ΒAWS CodeBuildΛىಈʼnͰ΋ྑ͘ͳ͍? • ߋʹݴ͑͹ňAWS CodePipelineʼnͰྑ͘ͳ͍???
  30. ΋͏1ͭͷબ୒ࢶ • ňTravisCI ͰૈࡶʹςετΛ෼ׂ࣮ߦ͢Δʼn • https://ssig33.com/text/distributed_test_on_TravisCI • ͭ·ΓͲ͏͍͏͜ͱ͔ͱݴ͏ͱ...

  31. ςετΛ16෼ׂ!!!!!

  32. ϏϧυϚτϦοΫεͷ׆༻ • GitHub Actionsʹ͸ňϏϧυϚτϦοΫεʼnͱ͍͏֓೦͕͋Δ • ຊདྷ͸, Perlͷ5.32ܥ, 5.30ܥ, 5.28ܥ... ͷΑ͏ʹ,

    ෳ਺ͷ؀ڥͰಉ࣌ ʹςετΛ࣮ߦ͢ΔͨΊͷ΋ͷ • ͜ΕΛ࢖ͬͯ, ςετΛ16෼ׂ࣮ͯ͠ߦ͢Δ!!! • ίετ͸౰વ16ഒ͕ͩ, ͦͷ෼ૉૣ͘ऴΘΔͷͰे෼ʹϖΠ͢Δ
  33. ϏϧυϚτϦοΫεͷ׆༻ • ϏϧυϚτϦοΫεͱͯ͠࿈൪Λࢦఆ • = ࿈൪ͷ਺͚ͩςετΛ෼ׂ࣮ͯ͠ߦ͢Δ • ྫ͑͹1͔Β16·Ͱͷ࿈൪ͳΒ, 16෼ׂ •

    f i ndΛ࢖ͬͯςετର৅ͷҰཡΛऔಘ → splitͰ෼ׂ → ࣮ߦ • ஫ҙ఺ͱͯ͠, ςετΛ෼ׂ͢Δ݁Ռ͸ႈ౳Ͱͳ͚Ε͹ͳΒͳ͍
  34. ϫʔΫϑϩʔͷ ༷ࢠ jobs : test : strategy : # ෼ׂͨ͠ςετͷ͏ͪ,

    1͕ͭίέͯ΋ଞͷશͯΛcancel͠ͳ͍Α͏ʹ͢Δ fail-fast: fals e matrix : test_id: ["01", "02", "03"] # ࿈൪Λࢦఆ steps : ... ॾʑͷ४උ .. . # findͱsplitΛ࢖ͬͯ, ςετର৅ͱͳΔϑΝΠϧ໊͕ॻ͔Εͨ # test01, test02, test03 ͱ͍͏ϑΝΠϧΛ࡞੒ - name: Split tests into chunk s run: | find t -name "*.t" -not -type d > test_files.tx t split -n r/${{ strategy.job-total }} \ --numeric-suffixes=1 \ --elide-empty-files test_files.txt tes t # ↑Ͱ࡞ͬͨ test01, test02, test03ͷ͍ͣΕ͔Λର৅ͱͯ͠ # ςετΛ࣮ߦ͢Δ - name: tes t run: | docker-compose run --rm --no-deps app \ carton exec -- prove < test${{ matrix.test_id }} ※ 3෼ׂͷྫ
  35. prepareδϣϒͷ༻ҙ • ςετΛ࣮ߦ͢Δʹ͋ͨͬͯඞཁͳॲཧ͸prepareδϣϒʹԡ͠ࠐΉ • 16෼ׂͨ͠ςετͦΕͧΕͰ࣮ߦ͢Δͱඇޮ཰ͳͨΊ • ςετ͸prepareϑΣΠζޙʹ࣮ߦ͢ΔΑ͏ʹ͢Δ • prepareδϣϒͰ༻ҙͨ͠ϑΝΠϧ͸, ଞͷδϣϒͰͦͷ··࢖͑ͳ͍

    • ͋Δδϣϒͱผͷδϣϒ͸, ผͷ؀ڥͰॲཧ͕࣮ߦ͞ΕΔͨΊ • prepareδϣϒͰΩϟογϡͯ͠, ͦΕΛར༻͢ΔΑ͏ʹ͢Δ
  36. ϫʔΫϑϩʔͷ ༷ࢠ jobs : prepare : runs-on: ubuntu-20.0 4 steps

    : - uses: actions/checkout@v2.3. 4 - name: Configure AWS Credential s uses: aws-actions/configure-aws- credentials@v1.5. 5 with: .. . # path-to-cache ͱ͍͏ϑΝΠϧΛ # Ωϟογϡ͢Δྫ - uses: papix/action-cache-s3@v0.0. 3 env: .. . with : bucket: ${{ env.cache-bucket } } key: ${{ hashFiles('path-to-cache') } } path: path-to-cach e
  37. ϫʔΫϑϩʔͷ ༷ࢠ jobs : prepare : ... prepareͷॲཧ .. .

    test : needs: prepare # needs Ͱ prepare ʹґଘ͢Δ͜ͱΛఆٛ strategy : fail-fast: fals e matrix : id: ["01", "02", "03" ] steps : ... ςετͷॲཧ ...
  38. actions/cache • ΩϟογϡपΓ͸ެࣜͷactions/cache͕͋Δ • ͦͦ͜͜ͷස౓ͰΩϟογϡͷऔಘʹࣦഊ͢Δ͜ͱ͕͋ͬͨ • 16෼ׂ͍ͯ͠Δͱ, ݁ߏͳ֬཰Ͱऔಘʹࣦഊ͢Δ • ߋʹ,

    ň16෼ׂͨ͠͏ͪͷࣦഊͨ͠1ͭʼnΛ࣮ߦ͢Δͷ͸ෆՄೳ • 16෼ׂ෼શͯ࠶࣮ߦ͠ͳ͚Ε͹ͳΒͳ͍...
  39. papix/action-cache-s3 • https://github.com/papix/action-cache-s3 • ͦ͜Ͱ, S3Λར༻ͨ͠Ωϟογϡͷ࢓૊ΈΛ࡞ͬͨ • ͜ΕͰ, ΩϟογϡΛऔಘग़དྷͣʹࣦഊ͢Δྫ͸͍ͩͿݮͬͨ

  40. ͜͏ͯ͠... • ϒϩάͷςετ͸push͔ͯ͠Β7ʙ10෼Ͱऴྃ͢ΔΑ͏ʹͳΓ·ͨ͠ • ͔͠΋, GitHub Actionsͷδϣϒ͸εέʔϧ͢ΔͷͰ, ෳ਺ͷpush͕ ͋ͬͯ΋ৗʹಉ࣌ʹ૸ͬͯ͘ΕΔ! •

    ΄΅ϝϯςφϯεϑϦʔͰ, ։ൃମݧ͕େ෯ʹ޲্!!! • Jenkins࣌୅ͱൺ΂Δͱ, ࢼࢉͰ͸ίετ΋໿2/3ʹͳΓ·ͨ͠ • ※ ແྉ࿮Λߟྀ͠ͳ͍৔߹
  41. σϝϦοτ • ϫʔΫϑϩʔ΍actionͷσόοά͕೉͍͠ • JenkinsͷΑ͏ʹ, ࣮ࡍʹαʔόʔʹೖͬͯڍಈΛݟΔ... ͱ͍͏ͷ͕ ೉͍͠ • σόοάϩΪϯάΛݩʹ,

    ϩά͔Βௐࠪ͢Δඞཁ͕͋Δ • tmuxͷηογϣϯΛੜ΍͢tmateͱaction-tmateΛ࢖ͬͯ 
 SSH઀ଓ͢Δ͜ͱ͸Մೳ͕ͩ...
  42. GitHub Actions ͓΋͠ΖςΫ

  43. Linter/Formatter + reviewdog • reviewdog • https://github.com/reviewdog/reviewdog • GitHubͳͲͷίʔυʹίϝϯτΛ࢒͢͜ͱ͕Ͱ͖Δ •

    Linterͷ݁ՌΛ౉͢ͱ, ܯࠂΛग़ͯ͘͠ΕΔ • ྫ rubocop: https://github.com/reviewdog/action-rubocop • work f l ow commandͰΞϊςʔγϣϯΛ෇͚Δํ๏΋͋Γ·͢
  44. Perl::Critic + reviewdog • Perl::Critic • PerlͷߏจΛղੳ͠, ฆΒΘ͍͠ߏจΛࢦఠͯ͘͠ΕΔπʔϧ • Perl::CriticʹରԠͨ͠reviewdogͷaction͸ଘࡏ͠ͳ͍͕...

    • Perl::Criticͷग़ྗΛreviewdogʹରԠͨ͠΋ͷʹมߋ͢Ε͹OK
  45. Perl::Critic + reviewdog • ৄ͘͠͸... • ňreviewdog x perlcritic x

    Jenkins Ͱ࠷ߴͷ GitHub ϨϏϡʔϥΠ ϑʼn • https://tech.mirrativ.stream/entry/reviewdog-perlcritic-jenkins-for-github-reviewing
  46. GitHub ActionsͰ Perl::CriticΛ࢖͏ name: criti c on : pull_request :

    critic : runs-on: ubuntu-lates t steps : - uses: actions/checkout@v2.3. 4 - name: Setup reviewdo g uses: reviewdog/action-setup@v1.0. 2 - name: Criticiz e run: | perlcritic --profile .perlcriticrc --verbose '%f:%l:%c:**%m**, near <code>%r</code>.<br>(Ref: [%p] (https://metacpan.org/pod/Perl::Critic::Policy::%p))\n' lib t | reviewdog -efm=%f:%l:%c:%m -name=perlcritic -reporter=github-pr-review
  47. Perl::Critic + reviewdog

  48. misspell + reviewdog • misspell: https://github.com/client9/misspell • GoͰॻ͔Εͨ, ϛεεϖϧΛൃݟͯ͘͠ΕΔπʔϧ •

    ίʔυதͷtypoΛڭ͑ͯ͘ΕΔ • reviewdog/action-misspell • Pull Requestʹࣗಈతʹίϝϯτͯ͘͠ΕΔ
  49. GitHub ActionsͰ misspellΛ࢖͏ name: misspel l on : pull_request :

    jobs : misspell : runs-on: ubuntu-lates t steps : - uses: actions/checkout@v2.3. 4 - name: misspel l uses: reviewdog/action-misspell@v1.7. 0 with : reporter: 'github-pr-review '
  50. reviewdog/action-misspell

  51. ϥϕϧͷνΣοΫ • Pull RequestʹϥϕϧΛ͚ͭΔӡ༻ϑϩʔ • ྫ: ϦϦʔεʹΑͬͯϢʔβʔ΁ͷӨڹ͕͋Δ࣌͸ňӨڹ͋Γʼn, 
 ͦ͏Ͱͳ͍࣌͸ňӨڹͳ͠ʼnͷϥϕϧΛ͚ͭΔ •

    GitHub ActionsͰ, ϥϕϧͷ͚ͭ๨Εʹܯࠂ͢Δ͜ͱ΋Մೳ • https://github.com/danielchabr/pr-labels-checker
  52. ϥϕϧͷ ࣗಈνΣοΫ name: label-chec k on : pull_request : jobs

    : check-labels : runs-on: ubuntu-lates t steps : - uses: danielchabr/pr-labels-checker@v2. 2 with : hasSome: Өڹ͋Γ,Өڹͳ͠
  53. ·ͱΊ

  54. ·ͱΊ • ͸ͯͳͰͷGitHub Actionsͷ׆༻ࣄྫΛ঺հ͠·ͨ͠ • Jenkins͔ΒGitHub ActionsʹҠߦ͢Δ͜ͱͰ, ϝϯςφϯεϑϦʔ ͳCI؀ڥΛैདྷΑΓ΋௿ίετͰ࣮ݱग़དྷΔΑ͏ʹͳΓ·ͨ͠ •

    GitHub ActionsͷศརͳactionΛ׆༻͢Δ͜ͱͰ, ༷ʑͳޮ཰ԽΛ 
 ࣮ݱ͢Δ͜ͱ΋ՄೳͰ͢
  55. We are hiring! ͸ͯͳͰ͸, CI/CD, ͦͯࣗ͠ಈԽʹڵຯͷ͋Δ ΤϯδχΞΛืू͍ͯ͠·͢!!!! https://hatenacorp.jp/recruit/engineer