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

20191002_CircleCIMeetupFukuoka#2

Yohei Kawahara
October 02, 2019
540

 20191002_CircleCIMeetupFukuoka#2

【福岡】CircleCI ユーザーコミュニティミートアップ#2 にてお話させていただく予定の資料です.

Yohei Kawahara

October 02, 2019
Tweet

Transcript

  1. CircleCI ݕఆ
    ϓϨΠόοΫ
    ʙ CircleCI ݕఆͷͦͷޙ ʙ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2
    @inokappa
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 1

    View Slide

  2. ࣗݾ঺հ
    • ͔ͬͺ (@inokappa)
    • גࣜձࣾ YAMAP
    • ΠϯϑϥΤϯδχΞͰ͢
    • ࠓ೔ͷ൅ܕ͸, DA PUMP ͷ ISSA ͞Μ
    ͷ൅Λഈआ͓ͯ͠Γ·͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 2

    View Slide

  3. YAMAP ʹ͍ͭͯ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 3

    View Slide

  4. YAMAP ʹ͍ͭͯ ʙΈ·΋Γػೳʙ1
    1 ࢁͰ“ਓͱ͢Εҧ͏”͜ͱͰɺ୭͔ͷ໋Λٹ͑Δ͔΋͠Εͳ͍ػೳΛͭ͘Γ·ͨ͠ (https://note.yamap.com/n/ndbe23b7e7bf0)
    ΑΓҾ༻
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 4

    View Slide

  5. CircleCI ͱ YAMAP
    • શͯͷγεςϜ͓͍ͯ, ςετ΍σϓϩΠͰ CircleCI ͕ϑϧʹ
    ׆༻͞Ε͍ͯ·͢
    • ࣾ಺ΤϰΝϯδΣϦετͷ @morygonzalez ͞Μ (΋Γ͝Μ͞
    Μ) ͷೖࣾͱڞʹಋೖ͞Ε·ͨ͠
    • ࣗ෼͕ೖࣾͨ࣌͠ʹ͸طʹ YAMAP ͷ։ൃγεςϜͷதͰ͸
    ͳͯ͘͸ͳΒͳ͍ଘࡏʹͳ͍ͬͯ·ͨ͠
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 5

    View Slide

  6. CircleCI ͱࢲ
    • YAMAP ʹೖࣾ͢Δલ͸ Hello World ϨϕϧͰͨ͠
    • YAMAP ͷ QA ؀ڥͷ؅ཧΛ೚͞Εͨ͜ͱΛػձʹ, վΊͯ
    CircleCI Λษڧ͠௚͢Α͏ʹ
    • ࠓͰ΋ॳ৺ऀͷ··Ͱ͕͢...
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 6

    View Slide

  7. ͯ͞, ຊ୊
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 7

    View Slide

  8. CircleCI ݕఆͱ͸
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 8

    View Slide

  9. CircleCI ݕఆͱ͸ (1)
    • CircleCI ͷεΩϧΛূ໌͢ΔՍۭͷೝఆࢼݧ੍౓Ͱ͢
    • डݧྉ͸ແྉ (CircleCI ʹ͸ແྉϓϥϯ͕͋Γ·͢)
    • ͍ͭͰ΋, Ͳ͜Ͱ΋, Πϯλʔωοτ͕ແͯ͘΋डݧग़དྷ·͢
    (CircleCI ͸ϩʔΧϧ PC Ͱ΋࣮ߦग़དྷ·͢)
    • ӳޠ, ೔ຊޠ, YAML Ͱडݧ͢Δ͜ͱ͕ग़དྷ·͢ (೔ຊޠͷυ
    Ωϡϝϯτ͕ॆ࣮͍ͯ͠·͢)
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 9

    View Slide

  10. CircleCI ݕఆͱ͸ (2)2
    2 CircleCI ݕఆެࣜαΠτ (https://kentei.circleci.com/ja/ ※ ࣮ࡏ͍ͯ͠·ͤΜ) ΑΓҾ༻
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 10

    View Slide

  11. CircleCI ݕఆͱ͸ (3)
    • 1 ڃ͸શੈքͰ໿ 40 ਓڧ (CircleCI ͷࣾһ਺ͱಉ౳)3
    • 2 ڃҎԼ͸໿ 10 ສਓڧ (CircleCI ͷϢʔβʔ਺ͱಉ౳)3
    3 2018 ೥ 10 ݄ௐ΂, CircleCI ݕఆެࣜαΠτ (Ծ) ΑΓҾ༻, ͔ͳΓ৘ใ͕ݹ͍Ͱ͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 11

    View Slide

  12. CircleCI ݕఆͱ͸ (4)
    • ݕఆࢼݧͷग़୊ൣғ͸ CircleCI 2.0 ͱ 2.1
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 12

    View Slide

  13. ͱ͍͏͜ͱͰ...
    ໳֎ෆग़ͷݕఆࢼݧରࡦ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 13

    View Slide

  14. ஫ҙʂʂ
    ͔͜͜Β͸໳֎ෆग़ͳ಺༰͕ଓ͖·͢ͷͰ, εϥΠυͷࣸਅࡱӨ
    ΍͓࿩͢Δ಺༰ͷ SNS ΁ͷ౤ߘ͸ʮ͝ԕྀ͠ͳ͍ͰʯԼ͍͞.
    ୠ͠, શͯͷ಺༰͕ެࣜυΩϡϝϯτ΍Πϯλʔωοτ্ʹଘࡏ
    ͓ͯ͠Γ·͢ͷͰ͝஫ҙԼ͍͞
    !
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 14

    View Slide

  15. CircleCI Λ࢝ΊΔ (9 ڃ)
    ઃ໰ 1. ҎԼͷ ( ) ͷதʹ౰ͯ͸·Δݴ༿ΛຒΊͳ͍͞.4
    • CircleCI Λ࢝ΊΔʹ͸, ( (1) ) ຢ͸ ( (2) ) ͷΞΧ΢ϯτ͕ඞཁ
    ʹͳΓ·͢
    • ϦϙδτϦͱ CircleCI ͷ ( (3) ) Λ࿈ܞͤ͞Δඞཁ͕͋Γ·͢
    4 (1)Github, (2)BitBucket, (3)࿈ܞ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 15

    View Slide

  16. CircleCI Λ࢝ΊΔ (ղઆ)
    CircleCI Λ࢝ΊΔʹ͸, Github ຢ͸ BitBucket ͷΞΧ΢ϯτ͕ඞ
    ཁʹͳΓ·͢ͷͰ, Github ΍ BitBucket ͷΞΧ΢ϯτ͸औಘͯ͠
    ͓͖·͠ΐ͏. CircleCI ݕఆࢼݧΛडݧ͢Δҝʹઈରʹඞཁͳ४
    උͰ͢. ๨Εͳ͍Α͏ʹ͠·͠ΐ͏.
    ΞΧ΢ϯτΛऔಘͨ͠Β, ϦϙδτϦΛ CircleCI ϓϩδΣΫτͱ
    ࿈ܞͤ͞·͠ΐ͏. શͯͷϦϙδτϦͱϓϩδΣΫτ͕࿈ܞग़དྷ
    Δͱ͸ݶΓ·ͤΜͷͰ஫ҙ͕ඞཁͰ͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 16

    View Slide

  17. ॳΊͯͷ .circleci/config.yml (9 ڃ)
    ઃ໰ 2. ҎԼ͸, ੈքͰ࠷΋γϯϓϧͳ .circleci/config.yml Ͱ͢.
    ( ) ͷதʹೖΔΩʔϫʔυΛ౴͑ͳ͍͞.5
    version: ( (1) )
    jobs:
    ( (2) ):
    docker:
    - image: docker:18.06.0-ce-git
    ( (3) ):
    - run:
    name: Hello world
    command: |
    echo "Hello CircleCI!!"
    5 (1)2, (2)jobs, (3)steps
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 17

    View Slide

  18. ॳΊͯͷ .circleci/config.yml (ղઆ)
    ϦϙδτϦʹ .circleci/config.yml ͱ͍͏ YAML ϑΥʔϚοτͷ
    ઃఆϑΝΠϧΛ௥Ճ͢Δඞཁ͕͋Γ·͢. ओཁͳΩʔ͸, ҎԼͷ
    ௨ΓͰ͢.
    • version
    • jobs
    • steps
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 18

    View Slide

  19. ϩʔΧϧϚγϯͰϏϧυΛ࣮ߦ͢Δ (8 ڃ)
    ઃ໰ 3. ઃ໰ 2 ͷ .circleci/config.yml Λ༻͍ͯ, ϩʔΧϧϚγϯ
    ্ͰߏจͷνΣοΫͱϏϧυΛ࣮ߦ͠ͳ͍͞.
    • CircleCI Ͱ͸, circleci ͱ͍͏ίϚϯυϥΠϯπʔϧΛఏڙ͠
    ͍ͯ·͢
    • macOS Ͱ͸, Homebrew Λ࢖ͬͯΠϯετʔϧ͢Δͱྑ͍Ͱ
    ͠ΐ͏
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 19

    View Slide

  20. ϩʔΧϧϚγϯͰϏϧυΛ࣮ߦ͢Δ (σϞ 1)
    • config validate ΦϓγϣϯͰߏจͷνΣοΫ
    $ circleci config validate
    Config file at .circleci/config.yml is valid.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 20

    View Slide

  21. ϩʔΧϧϚγϯͰϏϧυΛ࣮ߦ͢Δ (σϞ 2)
    • local execute ΦϓγϣϯͰϏϧυΛ࣮ߦ
    $ circleci local execute
    Docker image digest: sha256:5eb8cb710920f567403cc4cbd2de16d5ab8fc9a1b4c6357d2e7137fa5f1a4f62
    ====>> Spin up Environment
    ... தུ ...
    ====>> Hello world
    #!/bin/sh -eo pipefail
    echo "Hello CircleCI!!"
    Hello CircleCI!!
    Success!
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 21

    View Slide

  22. CircleCI ͰϏϧυΛ࣮ߦ͢Δ (8 ڃ)
    ઃ໰ 4. ઃ໰ 3 Ͱ֬ೝͨ͠ .circleci/config.yml Λ༻͍ͯ, CircleCI
    ্ͰϏϧυΛ࣮ߦ͠ͳ͍͞.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 22

    View Slide

  23. CircleCI ͰϏϧυΛ࣮ߦ͢Δ (ղઆ)
    ϦϙδτϦͱͷ࿈ܞ͕ਖ਼͘͠ߦΘΕ͍ͯΔ৔߹, ϦϙδτϦʹ
    push ͢ΔͱϏϧυ͕࣮ߦ͞Ε·͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 23

    View Slide

  24. Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ (8 ڃ)
    ઃ໰ 5. Ϗϧυ؀ڥʹ SSH Λ࢖ͬͯϩάΠϯ͠ͳ͍͞. ϩάΠϯ
    ͨ͠Β, hello.txt ͕࡞੒͞Ε͍ͯΔ͜ͱΛ֬ೝ͠ͳ͍͞.
    • Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ͜ͱͰ, Ϗϧυͷσόοά౳
    ͕ߦ͑·͢
    • ࣄલʹ Github ্ʹ SSH ͷެ։伴Λొ࿥͓͖ͯ͠·͠ΐ͏
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 24

    View Slide

  25. Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ (8 ڃ)
    ࣄલʹ, .circleci/config.yml ΛҎԼͷΑ͏ʹमਖ਼͓͖ͯ͠·͢.
    version: 2
    jobs:
    build:
    docker:
    - image: docker:18.06.0-ce-git
    steps:
    - run:
    name: Hello world
    command: |
    echo "Hello CircleCI!!" > hello.txt
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 25

    View Slide

  26. Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ (σϞ)
    δϣϒը໘ͷ Rerun workflow ͔Β Rerun job with SSH Λબ
    ୒ͯ͠δϣϒΛ࠶࣮ߦ͠·͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 26

    View Slide

  27. Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ (σϞ)
    $ ssh -p 64536 xxx.xxx.xxx.xxx
    ... ུ ...
    ~ # ls -al
    total 16
    drwx------ 3 root root 4096 Apr 16 22:02 .
    drwxr-xr-x 43 root root 4096 Apr 16 22:01 ..
    -rw------- 1 root root 7 Apr 16 22:02 .ash_history
    drwxr-xr-x 2 root root 4096 Apr 16 22:01 project
    ~ # cd project/
    ~/project # ls
    hello.txt
    ~/project # cat hello.txt
    Hello CircleCI!!
    ~/project #
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 27

    View Slide

  28. ͪΐͬͱϒϨΠΫ
    ʙᕒ਎ͷϞϊϚωʙ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 28

    View Slide

  29. ϞϊϚω A ͞Μ
    ϏϏοτͷऴྃΛελοϓʹࠂ͛ΒΕͯ...
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 29

    View Slide

  30. ϞϊϚω B ͞Μ
    ੈք཮্ͷ MC ͷҝ, υʔϋʹ౸ணͯ͠Ұݴ...
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 30

    View Slide

  31. workflows Λ࢖͏ (7 ڃ)
    ઃ໰ 6. workflows Λ࢖ͬͯ, master ϒϥϯνҎ֎Ͱ build ͕࣮
    ߦ͞ΕΔΑ͏ʹ͠ͳ͍͞.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 31

    View Slide

  32. workflows Λ࢖͏ (ղઆ)
    • workflows Ͱ͸, ֤εςοϓΛδϣϒͱ͍͏୯ҐͰѻ͍·͢
    • workflows Λ࢖͏͜ͱͰ, ௚ྻͳεςοϓ࣮ߦ͚ͩͰͳ͘, ৚
    ݅ʹԠͯ͡δϣϒΛ࣮ߦͤ͞Δ͜ͱ͕ग़དྷ·͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 32

    View Slide

  33. workflows Λ࢖͏ (ղઆ)
    ͜Ε·Ͱͷ .circleci/config.yml ʹ workflows ͱ͍͏ηΫγϣϯ
    Λ௥Ճ͠·͠ΐ͏.
    ... ུ ...
    workflows:
    version: 2
    pr-build:
    jobs:
    - build:
    filters:
    branches:
    ignore:
    - master
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 33

    View Slide

  34. workflows Λ࢖͏ (ղઆ)
    ผͷϒϥϯνΛ੾্ͬͨͰ commit, push ͯ͠Έ·͠ΐ͏.
    (master)$ git checkout -b development/demo01
    Switched to a new branch 'development/demo01'
    (development/demo01)$ echo 'test' >> README.md
    (development/demo01)$ git add README.md
    (development/demo01)$ git commit -m 'demo'
    [development/demo01 6ef698f] demo
    1 file changed, 1 insertion(+)
    (development/demo01)$ git push -u origin development/demo01
    ...
    Branch 'development/demo01' set up to track remote branch 'development/demo01' from 'origin'.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 34

    View Slide

  35. workflows Λ࢖͏ (ղઆ)
    development/demo01 ϒϥϯνͰ͸, build ͕࣮ߦ͞Ε͍ͯ·
    ͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 35

    View Slide

  36. Ϗϧυͷޮ཰Խ (7 ڃ)
    ઃ໰ 7. ΩϟογϡΛ༻͍ͯ, Ϗϧυ࣌ؒͷ୹ॖΛݕ౼͠ͳ͍͞.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 36

    View Slide

  37. Ϗϧυͷޮ཰Խ (ղઆ)
    • save_cache εςοϓΛར༻͢Δ͜ͱͰ, ϥΠϒϥϦ΍ιʔε
    ίʔυͷΩϟογϡΛอ࣋ग़དྷ·͢
    • restore_cache ʹͯ key Ͱࢦఆͨ͠ΩϟογϡΛ෮ݩ͠·
    ͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 37

    View Slide

  38. Ϗϧυͷޮ཰Խ (ղઆ)
    ҎԼͷΑ͏ʹ .circleci/config.yml Λमਖ਼͠·͠ΐ͏.
    steps:
    - restore_cache:
    key: cache-data-{{ .Branch }}
    ... தུ ...
    echo $n >> data.txt
    sleep 0.3
    done
    fi
    - save_cache:
    key: cache-data-{{ .Branch }}
    paths:
    - data.txt
    ... ࣍ͷϖʔδ΁ ...
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 38

    View Slide

  39. Ϗϧυͷޮ཰Խ (ղઆ)
    ҎԼͷΑ͏ʹ .circleci/config.yml Λमਖ਼͠·͠ΐ͏.
    ... લͷϖʔδΑΓ ...
    - run:
    name: Remove data.txt
    command: |
    rm -rf data.txt && sleep 5 && ls -al
    - restore_cache:
    key: cache-data-{{ .Branch }}
    - run:
    name: Restore data
    command: |
    cat data.txt
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 39

    View Slide

  40. Ϗϧυͷޮ཰Խ (ղઆ)
    • key ʹ͸ {{ .Branch }} ΍ {{ .Revision }} ౳ͷςϯϓ
    Ϩʔτ͕ࢦఆՄೳͰ͢
    • paths ʹ͸ϑΝΠϧ໊΍σΟϨΫτϦͷύεΛࢦఆ͠·͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 40

    View Slide

  41. Ϗϧυͷޮ཰Խ (σϞ 1)
    ΩϟογϡΛ࢓ࠐΜͩ͜ͱͰ, ҎԼͷΑ͏ʹॳճͷϏϧυҎ߱Ͱ
    ܶతʹॲཧ͕࣌ؒ୹ॖ͞Ε͍ͯ·͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 41

    View Slide

  42. Ϗϧυͷޮ཰Խ (ࢼݧʹग़Δ)
    restore_cache Ͱ͸ keys Ͱෳ਺ͷΩϟογϡΩʔΛࢦఆՄೳ
    Ͱ͢.
    - restore_cache:
    keys:
    - cache-data-{{ .Branch }}
    - cache-data
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 42

    View Slide

  43. Ϗϧυͷޮ཰Խ (σϞ 2)
    ҎԼͷΑ͏ʹ, ࢦఆͨ͠ΩʔͷΩϟογϡ͕ଘࡏ͍ͯ͠ͳ͍৔߹
    ʹ͸, restore_cache ͸εΩοϓ͞Ε, طʹΩϟογϡΩʔ͕ଘ
    ࡏ͍ͯ͠Δ৔߹ʹ͸ save_cache ΋εΩοϓ͞Ε·͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 43

    View Slide

  44. Ϗϧυͷޮ཰Խ (ࢼݧʹग़Δ)
    ࠓͷͱ͜Ζ, ΩϟογϡΛফ͢ज़͕͋Γ·ͤΜʂ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 44

    View Slide

  45. ςετͷޮ཰Խ (7 ڃ)
    ઃ໰ 8. ύϥϨϧςετΛར༻ͯ͠ςετ࣌ؒͷ୹ॖΛݕ౼͠ͳ
    ͍͞.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 45

    View Slide

  46. ςετͷޮ཰Խ (ղઆ)
    • ςετΛϑΝΠϧ୯ҐͰ෼ׂ͢Δ͜ͱͰ, ฒߦͯ͠ςετΛ࣮
    ߦ͢Δ͜ͱ͕ՄೳͰ͢
    • ෼ׂ͸ circleci ίϚϯυΛར༻͠·͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 46

    View Slide

  47. ςετͷޮ཰Խ (ղઆ)
    ҎԼͷΑ͏ʹ .circleci/config.yml ʹςετΛ௥Ճ͠·ͨ͠.
    test:
    parallelism: 2
    docker:
    - image: docker:18.06.0-ce-git
    steps:
    - checkout
    - run:
    name: Paralell Test
    command: |
    echo $(circleci tests glob "tests/*" | circleci tests split) | xargs -n 1 sh
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 47

    View Slide

  48. ςετͷޮ཰Խ (ղઆ)
    ςετͱݴ͍ͬͯ·͕͢, ҎԼͷΑ͏ͳγϯϓϧͳγΣϧεΫϦ
    ϓτͰ͢.
    sleep 5
    echo "01"
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 48

    View Slide

  49. ςετͷޮ཰Խ (σϞ 1)
    ී௨ʹςετΛ࣮ߦͨ͠৔߹, ҎԼͷΑ͏ʹ 27 ඵֻ͔͍ͬͯ·
    ͢.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 49

    View Slide

  50. ςετͷޮ཰Խ (σϞ 2)
    ύϥϨϧʹςετΛ࣮ߦͨ͠৔߹, ҎԼͷΑ͏ʹ 16 ඵ·Ͱʹ୹
    ॖ͍ͯ͠·͢
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 50

    View Slide

  51. ͯ͞
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 51

    View Slide

  52. ͜͜Ͱ
    Ԡ༻໰୊
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 52

    View Slide

  53. cron ͸࢖͍ͨ͘...
    ਓྨ͸όονॲཧ͔Β͸ಀΕΒΕͳ͍.
    scheduled-build:
    triggers:
    - schedule:
    cron: "0 23 * * *" # UTC Ͱࢦఆ͢Δඞཁ͕͋Δ
    filters:
    branches:
    only:
    - deployment/packer
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 53

    View Slide

  54. sls deploy ΋ CircleCI Ͱ
    Serverless Framework ͸ฏ੒, ྩ࿨࢈ۀֵ໋Ͱ͢.
    ...
    - run:
    name: Deploy
    command: |
    serverless deploy --conceal
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 54

    View Slide

  55. packer ΋ CircleCI Ͱ
    packer ͰύΧοͱ AMI ࡞੒.
    ...
    - run:
    name: build image
    command: packer build build.json
    no_output_timeout: 120m
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 55

    View Slide

  56. EC2 ηΩϡϦςΟάϧʔϓΛ։์ (1)
    • CircleCI Ͱ EC2 ʹ SSH ΞΫηε͍ͨ͠৔߹ʹආ͚ͯ௨Εͳ
    ͍
    • Job ͷதͰࣗલ࣮૷͚ͨ͠Ͳ...
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 56

    View Slide

  57. EC2 ηΩϡϦςΟάϧʔϓΛ։์ (2)
    Orbs Ͱఏڙ͞Ε͍ͯͨ͜ͱΛ஌Γ·ͨ͠.
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 57

    View Slide

  58. EC2 ηΩϡϦςΟάϧʔϓΛ։์ (3)
    ͔͠͠, ԶόʔδϣϯͰ͸...
    - run:
    name: build specfile for awspec
    command: |
    bundle exec rake aws:security_group:build_spec
    when: always
    - run:
    name: check security group ingress
    command: |
    bundle exec rake aws:security_group:spec
    when: always
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 58

    View Slide

  59. ϫϯόΠφϦ (1)
    command ͸࠷ߴೋߦ͘Β͍Ͱ཈͍͑ͨ೿Ͱ͢.
    - run:
    name: execute remove old amis
    command: |
    # ݹ͍ AMI Λ࡟আ͢ΔϫϯόΠφϦίϚϯυ
    ./tools/amiCtrl --delete --days=3 -batch
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 59

    View Slide

  60. ϫϯόΠφϦ (2)
    - run:
    name: execute remove old amis
    command: |
    # ͜ͷίʔυ͸͋͘·Ͱ΋αϯϓϧͰ͢, ಈ͖·ͤΜ
    AMI_ID=$(aws ec2 describe-images ....) && \
    aws ec2 deregister-image --image-id ${AMI_ID} && \
    aws ec2 delete-snapshot --snapshot-id ${SNAPSHOT_ID}
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 60

    View Slide

  61. ͦΖͦΖ
    ͓࣌ؒͰ͢...
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 61

    View Slide

  62. ͳͥ, CircleCI Λ࢖͏ͷ͔
    • खॱ͕ݟ͍͑ͯΔ
    • ࣮ߦ݁Ռ͕ݟ͍͑ͯΔ
    • ͢΂͕ͯ YAML ͰޠΕΔΜ͡Όͳ͍͔ͬͯࢥ͑Δ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 62

    View Slide

  63. Let's CircleCI ݕఆ
    • CircleCI ݕఆͰࢼݧʹඞͣग़ͦ͏ͳϙΠϯτΛૡ͍ఠΜͰ͓
    ࿩͠·ͨ͠
    • ·ͩ, CircleCI Λ৮ͬͨ͜ͱ͕ແ͍ํ͸ੋඇαΠϯΞοϓͯ͠
    ࢖ͬͯΈ·͠ΐ͏
    • υΩϡϝϯτ΋େมॆ࣮͍ͯ͠ΔͷͰ, υΩϡϝϯτ͸ੋඇ,
    ໨Λ௨͠·͠ΐ͏
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 63

    View Slide

  64. ͍͞͝ʹ
    • CircleCI ৮͍ͬͯΔͱ, ͳΜͰ΋ CircleCI Ͱॲཧ͍ͨ͠ͱ͍͏
    ཉ͕༙͍͖ͯ·͢ΑͶ
    • Բͤͣ৮Γଓ͚Δ͜ͱ͕ঢڃ (্ୡ) ΁ͷۙಓͩͱࢥ͍·͢
    • օ͞Μ΋ੋඇ, ݕఆΛडݧ͠·͠ΐ͏
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 64

    View Slide

  65. ͓ΘΓ
    CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #2 65

    View Slide