CI/CD TestNight #3 で発表したスライドです
GitHub ͱ࿈ܞ͢Δ CI Λ࡞ΔCI/CD Test Night2019.02.21 [THU]Shunsuke Maeda (@duck8823)
View Slide
ࣗݾհ• @duck8823• ॴଐ• גࣜձࣾΤεɾΤϜɾΤε• ιϑτΣΞΤϯδχΞ• झຯ• duck8823/duci
GitHub ͱ࿈ܞ͢Δ CI Λ࡞Δ• https://github.com/duck8823/duci
طଘͷCIͷਏ͍ͱ͜Ζ• ઃఆϑΝΠϧ• CircleCI / TravisCI / Jenkins..• *.yml / Jenkinsfile (= Groovy based DSL)• ϩʔΧϧͰͷ࠶ݱͷ͞05443d6 Fix ci settingce8332d Fix ci setting8c155fa Fix ci settinge6c24e0 Fix ci setting
Continuous Integration
Continuous Integration• ఆظతʹ• ϏϧυςετΛ࣮ߦ ͢Δ͜ͱͰ• ૣظʹ ϑΟʔυόοΫ Λಘͯόά͕ຊ൪ڥʹࠞೖ͢ΔͷΛ͙
CIͰߟ͑Δඞཁ͕͋Δ͜ͱ• ఆظతʹ• ࣮ߦλΠϛϯά• ϏϧυςετΛ࣮ߦ• ࣮ߦڥ• ϑΟʔυόοΫ• ࣮ߦ݁Ռ
CIͷߏ• ࣮ߦλΠϛϯά• ࣮ߦڥ• ࣮ߦ݁ՌΛૄͳ࡞Γʹ͓ͯ͘͠ͱॊೈ
CIͷߏ(ࠓճ• ࣮ߦλΠϛϯά• GitHub ͷ Webhook• ࣮ߦڥ• Docker x λεΫϥϯφʔ• ࣮ߦ݁Ռ• GitHub ͷ Commit Status / ϩάUI
࣮ߦλΠϛϯά
࣮ߦλΠϛϯά• GitHub ͷ Webhookhttps://github.com///settings/hooks• ҙͷλΠϛϯάͰ Payload Λඈ͢• ඇಉظͰϨεϙϯεΛฦ͞ͳ͍ͱ Timeout
GitHub ͷ Webhook• Event ͱ Action ͷΈ߹ΘͤͰλΠϛϯά੍ޚ• Event• Webhookͷछྨ (Header: X-GitHub-Event)ྫ. push, issue_comment, pull_request• Action• Eventຖͷࡉ͔͍छྨ (JSON payload)ྫ. created, opened, synchronize
Fork ͨ͠ϦϙδτϦ͔Βͷ Pull Request• push ΠϕϯτͰऔಘͰ͖ͳ͍=> pull_request Πϕϯτͷ synchronize Ͱऔಘ
Pull Request ͷίϝϯτ• issue_comment ͰऔಘՄೳ• Payload ʹ pull_request ͷใ͕ͳ͍(※ head branch/commit ͳͲ)=> GitHub API Ͱऔಘ
࣮ߦڥ
࣮ߦڥ• Docker• ϗετΛԚ͞ͳ͍• ϩʔΧϧ / CI Ͱͷಈ࡞ʹ࠶ݱੑΛͱΓ͍͢• ϦϙδτϦ্ͷ Dockerfile Λར༻
DockerfileFROM golang:1.11.5-alpineRUN apk --update add --no-cache alpine-sdkCOPY . .ENTRYPOINT ["make"] # λεΫϥϯφʔͷίϚϯυ ྫ. ./gradlew, mvnCMD ["test"] # σϑΥϧτͷλεΫ• docker build ͱ docker run Λ࣮ߦ• issue_comment ͷ߹ CMD ΛࢦఆՄೳ
ϩʔΧϧͰͷ࣮ߦಉ͡ Dockerfile ͰϩʔΧϧͰಈ࡞֬ೝ͕Ͱ͖Δdocker build -t job -f path/to/Dockerfile .docker run --rm job [CMD]
ϗετͷϦιʔε༗ݶ• ฒྻͱλΠϜΞτ• Golang ͷ goroutine ͱ context ͕૬ੑ͕Α͍(࣮͕ؾʹͳΔํ)https://github.com/duck8823/duci/blob/master/application/service/executor/executor.go
࣮ߦ݁Ռ
࣮ߦ݁Ռ• GitHub ͷ Commit Status
݁Ռͷৄࡉϩάͷอଘͱදࣔ- Commit Status ʹৄࡉϦϯΫΛ͚ͭΔ͜ͱ͕Ͱ͖Δ
Έͳ͞Μ͕։ൃ͠ɺGitHubͰ࣮ߦhttps://github.blog/jp/2018-10-24-action-demos/
Why not using GitHub Actions?A. ͍ͬͯ·͢
GitHub Actions ͷΠέͯΔͱ͜ΖGITHUB_TOKEN Λ͍ग़ͯ͘͠ΕΔ= Personal Access Token (Bot Account) ͕͍Βͳ͍
GitHub Actions ͷ࣮ߦλΠϛϯά (Event• Event ͷछྨ Webhook ͱجຊతʹಉ͡• GitHub Actionshttps://developer.github.com/actions/creating-workflows/workflow-configuration-options/#events-supported-in-workflow-files• Webhookshttps://developer.github.com/webhooks/#events
GitHub Actions ͷ࣮ߦλΠϛϯά (Action• Webhook ͷ Payload ͱಉͷ JSON ͕ஔ͞ΕΔڥม GITHUB_EVENT_PATH• ެࣜͷ Filter• action Ͱ filteractions/bin
·ͱΊ• CI࡞ΕΔ• ࣮ߦλΠϛϯά / ࣮ߦڥ / ࣮ߦ݁Ռ• GitHub Actions ͍͍ͧ• CIΛ࡞ͬͨࣝ͑Δ
CIΛ࡞ͬͯΈΑ͏
͓·͚Danger Λ GitHub Actions Ͱ͑ΔΑ͏ʹ͠·ͨ͠• Pull Request ͷνΣοΫΛࣗಈԽ͢ΔͨΊͷج൫= Pull Request ϧʔϧͷίʔυԽ