ChatBotの重いタスクをCircleCIに持っていってみた / How to move heavy tasks on ChatBot to CircleCI

B5582ce2d9959dfcff0384a07003e188?s=47 mackee
January 16, 2020

ChatBotの重いタスクをCircleCIに持っていってみた / How to move heavy tasks on ChatBot to CircleCI

CircleCI ユーザーコミュニティミートアップ#8
https://circleci.connpass.com/event/157469/

B5582ce2d9959dfcff0384a07003e188?s=128

mackee

January 16, 2020
Tweet

Transcript

  1. ChatBotͷॏ͍λεΫΛ CircleCIʹ͍࣋ͬͯͬͯΈͨ CircleCIϢʔβʔίϛϡχςΟϛʔ τΞοϓ#8 2020-01-16 ໘ന๏ਓΧϠοΫ @mackee_w 1

  2. ୭ • macopy, twitter: @mackee_w, GitHub: @mackee • ໘ന๏ਓΧϠοΫ •

    αʔόαΠυΤϯδχΞ 2
  3. ͓࿩͍ͨ͜͠ͱ CircleCIͷδϣϒ Ͳ͔͜ΒτϦΨʔ͢Δ͔ 3

  4. Ұൠతʹ͸ϦϙδτϦ΁ͷpush 4

  5. ChatBot͔ΒδϣϒΛΩοΫ͍ͨ͠ 5

  6. ͳͥ => pushʹඥ෇͔ͳ͍λεΫ͕͋Δ • PullRequestͷϨϏϡʔΞαΠϯΨνϟ • Google Spreadsheet͔ΒCSVΛग़ྗͯ͠pushͯ͠ Pull Requestʹ͢Δ

    • ςετ͕ΊͪΌॏ͍ͷͰ೚ҙͷλΠϛϯάͰςετΛ τϦΨʔ͍ͨ͠ 6
  7. ैདྷ͸ChatBotࣗ਎͕΍͍ͬͯͨ • Bot͸PerlͰॻ͔ΕͨSlack RTMΛ͠Ό΂Δ܅ • ΠϕϯτۦಈͰಈ͘ϑϨʔϜϫʔΫ্ʹ৐͍ͬͯΔ • ίϚϯυ͕དྷΔͱλεΫ͕ॻ͔ΕͨεΫϦϓτΛىಈ ͢Δ •

    ͏͔ͬΓϒϩοΩϯάIOͳίʔυΛॻ͘ͱɺδϣϒ ΛฒߦͰड͚ΒΕͳ͘ͳͬͨΓɺ٧·ͬͯࢮΜͩ 7
  8. ChatBot͕ͦͷ··λεΫΛ࣮ߦ͢Δࡍͷ໰୊఺ • ॏ͍λεΫ͕͋Δͱ٧·Δ • ผϓϩηεʹͨ͠Βσόοά͕ҟৗʹ೉͘͠ͳͬͨ • εέʔϧ͠ͳ͍ SPOF • ChatBot͕ॅΉαʔόΛۀ຿࣌ؒதʹམͱͤͳ͍

    • ϒϥϯν͝ͱͷλεΫͷඇޓ׵ͷରԠ͕ΊΜͲ͍͘͞ • chatbotͷίʔυͱϒϥϯνͷதͷίʔυͷඇޓ׵ 8
  9. CircleCIʹ͍࣋ͬͯ͘ͱ... • λεΫ͕ॏ͍৔߹͸Ωϡʔ͕٧·Δ͕Ωϡʔʹ͸ೖΔ • ແࢹ͞Εͳ͍ • εέʔϧ => ͓ۚΛ෷͑͹͢Δ •

    ฐࣾ͸Performance PlanΛܖ໿͓ͯ͠Γ·͢ • ϒϥϯν͝ͱͷλεΫඇޓ׵ੑ • ϒϥϯνͷεΫϦϓτΛ࣮ߦ͢Δ͔Βղܾ 9
  10. ΍Γ͍ͨ͜ͱΛ·ͱΊΔͱ ೚ҙͷλεΫΛ CircleCIͰ ޷͖ͳͱ͖ʹ࣮ߦ͍ͨ͠ʂ 10

  11. ͜͜ʹAPI͕͋Γ·͢ 11

  12. ͕ɺ͔͠͠ɺv1.1 API͸... • CircleCI 2.1ʹ͸ະରԠ • workflow΋ະରԠ • ͦ΋ͦ΋3/1ʹ࢖͑ͳ͘ͳΔͦ͏Ͱ͢ •

    https://circleci.com/blog/a-deprecation-notice- on-job-triggering-with-api-v1-1/ 12
  13. ͜͜ʹv2 API͕͋Γ·͢ 13

  14. v2 APIͷಛ௃ • pipeline parametersͷಋೖ • 2.1 config͔Βಋೖ͞Εͨparametersͷworkflow ʹద༻Ͱ͖Δ൛ •

    workflow಺ͰjobΛىಈ͢Δͱ͖ͷparametersʹ ࢖͑ͨΓɺpipeline parametersͷঢ়ଶΛݟͯ workflowΛىಈ͢Δ͔ܾΊΒΕΔ 14
  15. config.ymlൈਮ workflows: version: 2.1 test: when: << pipeline.parameters.do_test >> jobs:

    - app_test: filters: branches: only: - /^feature\/.*/ run_task: when: << pipeline.parameters.do_daiku >> jobs: - do_task: taskname: << pipeline.parameters.daiku_task >> 15
  16. APIΛ౤͛ͯΈ·͠ΐ͏ my $base_uri = "https://circleci.com/api/v2/project/gh/kayac/project_name/pipeline"; my $circleci_token = $ENV{CIRCLECI_TOKEN}; my

    $body = encode_json({ branch => $branch, parameters => { do_test => bool(0), do_daiku => bool(1), daiku_task => escape_task_name($job, @args), }, }); http_post "${base_uri}?circle-token=${circleci_token}", $body, headers => { "content-type" => "application/json" }, $cb; 16
  17. ·ͱΊ • ChatBot͕΍ͬͯͨॏͦ͏ͳλεΫΛCircleCIʹ࣋ͬ ͍ͯͬͨΑ • ͦ΋ͦ΋ChatBot͕΍Δͷʹෆద੾ͳλεΫͩͬͨ Ͷ • CircleCI v2Λ࢖͑͹APIͰworkflowΛenqueueͰ͖Δ

    Α 17
  18. ·ͱΊ • ϒϩάͰΞφ΢ϯε͕͋ͬͨΑ https://circleci.com/ blog/introducing-circleci-api-v2/ • ΋ͬͱৄ͍͠࿩͸ͪ͜Β https:// techblog.kayac.com/circleci-api-v2 18