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

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

mackee
January 16, 2020

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

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

mackee

January 16, 2020
Tweet

More Decks by mackee

Other Decks in Programming

Transcript

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

    View full-size slide


  2. • macopy, twitter: @mackee_w, GitHub: @mackee
    • ໘ന๏ਓΧϠοΫ
    • αʔόαΠυΤϯδχΞ
    2

    View full-size slide

  3. ͓࿩͍ͨ͜͠ͱ
    CircleCIͷδϣϒ
    Ͳ͔͜ΒτϦΨʔ͢Δ͔
    3

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  6. ͳͥ => pushʹඥ෇͔ͳ͍λεΫ͕͋Δ
    • PullRequestͷϨϏϡʔΞαΠϯΨνϟ
    • Google Spreadsheet͔ΒCSVΛग़ྗͯ͠pushͯ͠
    Pull Requestʹ͢Δ
    • ςετ͕ΊͪΌॏ͍ͷͰ೚ҙͷλΠϛϯάͰςετΛ
    τϦΨʔ͍ͨ͠
    6

    View full-size slide

  7. ैདྷ͸ChatBotࣗ਎͕΍͍ͬͯͨ
    • Bot͸PerlͰॻ͔ΕͨSlack RTMΛ͠Ό΂Δ܅
    • ΠϕϯτۦಈͰಈ͘ϑϨʔϜϫʔΫ্ʹ৐͍ͬͯΔ
    • ίϚϯυ͕དྷΔͱλεΫ͕ॻ͔ΕͨεΫϦϓτΛىಈ
    ͢Δ
    • ͏͔ͬΓϒϩοΩϯάIOͳίʔυΛॻ͘ͱɺδϣϒ
    ΛฒߦͰड͚ΒΕͳ͘ͳͬͨΓɺ٧·ͬͯࢮΜͩ
    7

    View full-size slide

  8. ChatBot͕ͦͷ··λεΫΛ࣮ߦ͢Δࡍͷ໰୊఺
    • ॏ͍λεΫ͕͋Δͱ٧·Δ
    • ผϓϩηεʹͨ͠Βσόοά͕ҟৗʹ೉͘͠ͳͬͨ
    • εέʔϧ͠ͳ͍ SPOF
    • ChatBot͕ॅΉαʔόΛۀ຿࣌ؒதʹམͱͤͳ͍
    • ϒϥϯν͝ͱͷλεΫͷඇޓ׵ͷରԠ͕ΊΜͲ͍͘͞
    • chatbotͷίʔυͱϒϥϯνͷதͷίʔυͷඇޓ׵
    8

    View full-size slide

  9. CircleCIʹ͍࣋ͬͯ͘ͱ...
    • λεΫ͕ॏ͍৔߹͸Ωϡʔ͕٧·Δ͕Ωϡʔʹ͸ೖΔ
    • ແࢹ͞Εͳ͍
    • εέʔϧ => ͓ۚΛ෷͑͹͢Δ
    • ฐࣾ͸Performance PlanΛܖ໿͓ͯ͠Γ·͢
    • ϒϥϯν͝ͱͷλεΫඇޓ׵ੑ
    • ϒϥϯνͷεΫϦϓτΛ࣮ߦ͢Δ͔Βղܾ
    9

    View full-size slide

  10. ΍Γ͍ͨ͜ͱΛ·ͱΊΔͱ
    ೚ҙͷλεΫΛ
    CircleCIͰ
    ޷͖ͳͱ͖ʹ࣮ߦ͍ͨ͠ʂ
    10

    View full-size slide

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

    View full-size slide

  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

    View full-size slide

  13. ͜͜ʹv2 API͕͋Γ·͢
    13

    View full-size slide

  14. v2 APIͷಛ௃
    • pipeline parametersͷಋೖ
    • 2.1 config͔Βಋೖ͞Εͨparametersͷworkflow
    ʹద༻Ͱ͖Δ൛
    • workflow಺ͰjobΛىಈ͢Δͱ͖ͷparametersʹ
    ࢖͑ͨΓɺpipeline parametersͷঢ়ଶΛݟͯ
    workflowΛىಈ͢Δ͔ܾΊΒΕΔ
    14

    View full-size slide

  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

    View full-size slide

  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

    View full-size slide

  17. ·ͱΊ
    • ChatBot͕΍ͬͯͨॏͦ͏ͳλεΫΛCircleCIʹ࣋ͬ
    ͍ͯͬͨΑ
    • ͦ΋ͦ΋ChatBot͕΍Δͷʹෆద੾ͳλεΫͩͬͨ
    Ͷ
    • CircleCI v2Λ࢖͑͹APIͰworkflowΛenqueueͰ͖Δ
    Α
    17

    View full-size slide

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

    View full-size slide