2019-04-18 CircleCI Meetup Fukuoka #1

26c17d2f70a57a8fd9a70885682fcd74?s=47 Yohei Kawahara
April 18, 2019
4.5k

2019-04-18 CircleCI Meetup Fukuoka #1

2019 年 4 月 18 日に行われた CircleCI Meetup Fukuoka #1 でお話させて頂いた死霊です.

26c17d2f70a57a8fd9a70885682fcd74?s=128

Yohei Kawahara

April 18, 2019
Tweet

Transcript

  1. 1.

    CircleCI ݕఆ 9 ڃ͔Β 8 ڃʹͳΓ·ͨ͠ ʙ ໳֎ෆग़ͷݕఆࢼݧରࡦ ʙ CircleCI

    ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 @inokappa CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 1
  2. 2.

    ࣗݾ঺հ • ͔ͬͺ (@inokappa) • גࣜձࣾ YAMAP (2019 ೥ 1

    ݄ೖࣾ, ·ͩࢼ༻ظؒத) • ΠϯϑϥΤϯδχΞͰ͢ • ޷͖ͳ͏ͲΜ͸͝΅ఱ͏ͲΜͰ͢ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 2
  3. 5.

    CircleCI ͱ YAMAP • શͯͷγεςϜ͓͍ͯ, ςετ΍σϓϩΠͰ CircleCI ͕ϑϧʹ ׆༻͞Ε͍ͯ·͢ •

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

    CircleCI ͱࢲ • YAMAP ʹೖࣾ͢Δલ͸ Hello World ϨϕϧͰͨ͠ • YAMAP

    ͷ ϑΟʔνϟʔ؀ڥ (QA ΍ ϨϏϡʔ, ৽ػೳͷ͓ࢼ ͠Ͱར༻) ͷ؅ཧΛ೚͞Εͨ͜ͱΛػձʹ, վΊͯ CircleCI Λ ษڧ͠௚͢Α͏ʹ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 6
  5. 9.

    CircleCI ݕఆͱ͸ (1) • CircleCI ͷεΩϧΛূ໌͢ΔҝͷՍۭͷೝఆࢼݧ੍౓Ͱ͢ • डݧྉ͸ແྉ (CircleCI ʹ͸ແྉϓϥϯ͕͋Γ·͢)

    • ͍ͭͰ΋, Ͳ͜Ͱ΋, Πϯλʔωοτ͕ແͯ͘΋डݧग़དྷ·͢ (CircleCI ͸ϩʔΧϧ PC Ͱ΋࣮ߦग़དྷ·͢) • ӳޠ, ೔ຊޠ, YAML Ͱडݧ͢Δ͜ͱ͕ग़དྷ·͢ (೔ຊޠͷυ Ωϡϝϯτ΋͋Γ·͢) CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 9
  6. 11.

    CircleCI ݕఆͱ͸ (3) • 1 ڃ͸શੈքͰ໿ 40 ਓڧ (CircleCI ͷࣾһ਺ͱಉ౳)2

    • 2 ڃҎԼ͸໿ 10 ສਓڧ (CircleCI ͷϢʔβʔ਺ͱಉ౳)2 2 2018 ೥ 10 ݄ௐ΂, CircleCI ݕఆެࣜαΠτ (Ծ) ΑΓҾ༻ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 11
  7. 15.

    CircleCI Λ࢝ΊΔ (9 ڃ) ઃ໰ 1. ҎԼͷ ( ) ͷதʹ౰ͯ͸·Δݴ༿ΛຒΊͳ͍͞.3

    • CircleCI Λ࢝ΊΔʹ͸, ( (1) ) ຢ͸ ( (2) ) ͷΞΧ΢ϯτ͕ඞཁ ʹͳΓ·͢ • ϦϙδτϦͱ CircleCI ͷ ( (3) ) Λ࿈ܞͤ͞Δඞཁ͕͋Γ·͢ 3 (1)Github, (2)BitBucket, (3)࿈ܞ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 15
  8. 16.

    CircleCI Λ࢝ΊΔ (ղઆ) CircleCI Λ࢝ΊΔʹ͸, Github ຢ͸ BitBucket ͷΞΧ΢ϯτ͕ඞ ཁʹͳΓ·͢ͷͰ,

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

    ॳΊͯͷ .circleci/config.yml (9 ڃ) ઃ໰ 2. ҎԼ͸, ੈքͰ࠷΋γϯϓϧͳ .circleci/config.yml Ͱ͢.

    ( ) ͷதʹೖΔΩʔϫʔυΛ౴͑ͳ͍͞.4 version: ( (1) ) jobs: ( (2) ): docker: - image: docker:18.06.0-ce-git ( (3) ): - run: name: Hello world command: | echo "Hello CircleCI!!" 4 (1)2, (2)jobs, (3)steps CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 17
  10. 19.

    ϩʔΧϧϚγϯͰϏϧυΛ࣮ߦ͢Δ (8 ڃ) ઃ໰ 3. ઃ໰ 2 ͷ .circleci/config.yml Λ༻͍ͯ,

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

    ϩʔΧϧϚγϯͰϏϧυΛ࣮ߦ͢Δ (σϞ 1) • config validate ΦϓγϣϯͰߏจͷνΣοΫ $ circleci config

    validate Config file at .circleci/config.yml is valid. CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 20
  12. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 21
  13. 22.

    CircleCI ͰϏϧυΛ࣮ߦ͢Δ (8 ڃ) ઃ໰ 4. ઃ໰ 3 Ͱ֬ೝͨ͠ .circleci/config.yml

    Λ༻͍ͯ, CircleCI ্ͰϏϧυΛ࣮ߦ͠ͳ͍͞. CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 22
  14. 24.

    Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ (8 ڃ) ઃ໰ 5. Ϗϧυ؀ڥʹ SSH Λ࢖ͬͯϩάΠϯ͠ͳ͍͞.

    ϩάΠϯ ͨ͠Β, hello.txt ͕࡞੒͞Ε͍ͯΔ͜ͱΛ֬ೝ͠ͳ͍͞. • Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ͜ͱͰ, Ϗϧυͷσόοά౳ ͕ߦ͑·͢ • ࣄલʹ Github ্ʹ SSH ͷެ։伴Λొ࿥͓͖ͯ͠·͠ΐ͏ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 24
  15. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 25
  16. 26.

    Ϗϧυ؀ڥʹ SSH ϩάΠϯ͢Δ (σϞ) δϣϒը໘ͷ Rerun workflow ͔Β Rerun job

    with SSH Λબ ୒ͯ͠δϣϒΛ࠶࣮ߦ͠·͢. CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 26
  17. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 27
  18. 31.

    workflows Λ࢖͏ (7 ڃ) ઃ໰ 6. workflows Λ࢖ͬͯ, master ϒϥϯνҎ֎Ͱ

    build ͕࣮ ߦ͞ΕΔΑ͏ʹ͠ͳ͍͞. CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 31
  19. 32.

    workflows Λ࢖͏ (ղઆ) • workflows Ͱ͸, ֤εςοϓΛδϣϒͱ͍͏୯ҐͰѻ͍·͢ • workflows Λ࢖͏͜ͱͰ,

    ௚ྻͳεςοϓ࣮ߦ͚ͩͰͳ͘, ৚ ݅ʹԠͯ͡δϣϒΛ࣮ߦͤ͞Δ͜ͱ͕ग़དྷ·͢ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 32
  20. 33.

    workflows Λ࢖͏ (ղઆ) ͜Ε·Ͱͷ .circleci/config.yml ʹ workflows ͱ͍͏ηΫγϣϯ Λ௥Ճ͠·͠ΐ͏. ...

    ུ ... workflows: version: 2 pr-build: jobs: - build: filters: branches: ignore: - master CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 33
  21. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 34
  22. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 38
  23. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 39
  24. 40.

    Ϗϧυͷޮ཰Խ (ղઆ) • key ʹ͸ {{ .Branch }} ΍ {{

    .Revision }} ౳ͷςϯϓ Ϩʔτ͕ࢦఆՄೳͰ͢ • paths ʹ͸ϑΝΠϧ໊΍σΟϨΫτϦͷύεΛࢦఆ͠·͢ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 40
  25. 42.

    Ϗϧυͷޮ཰Խ (ࢼݧʹग़Δ) restore_cache Ͱ͸ keys Ͱෳ਺ͷΩϟογϡΩʔΛࢦఆՄೳ Ͱ͢. - restore_cache: keys:

    - cache-data-{{ .Branch }} - cache-data CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 42
  26. 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 ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 47
  27. 52.

    ͍͔͕ͩͬͨͰ͠ΐ͏͔ • CircleCI ݕఆͰࢼݧʹඞͣग़ͦ͏ͳϙΠϯτΛૡ͍ఠΜͰ͓ ࿩͠·ͨ͠ • ·ͩ, CircleCI Λ৮ͬͨ͜ͱ͕ແ͍ํ͸ੋඇαΠϯΞοϓͯ͠ ࢖ͬͯΈ·͠ΐ͏

    • υΩϡϝϯτ΋େมॆ࣮͍ͯ͠ΔͷͰ, υΩϡϝϯτ͸ੋඇ, ໨Λ௨͠·͠ΐ͏ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 52
  28. 53.

    ͍͞͝ʹ • CircleCI ৮͍ͬͯΔͱ, ͳΜͰ΋ CircleCI Ͱॲཧ͍ͨ͠ͱ͍͏ ཉ͕༙͍͖ͯ·͢ΑͶ • Բͤͣ৮Γଓ͚Δ͜ͱ͕ঢڃ

    (্ୡ) ΁ͷۙಓͩͱࢥ͍·͢ • օ͞Μ΋ੋඇ, ݕఆΛडݧ͠·͠ΐ͏ CircleCI ϢʔβʔίϛϡχςΟϛʔτΞοϓ #1 53