CircleCI の歩き方 / CircleCI #phpstudy

CircleCI の歩き方 / CircleCI #phpstudy

第123回PHP勉強会@東京の資料です

42305fafd669602e3865a9ac99313257?s=128

TAKAHASHI Kunihiko

February 28, 2018
Tweet

Transcript

  1. $JSDMF$* ͷา͖ํ ୈճ1)1ษڧձ!౦ژ LVOJU

  2. ࣗݾ঺հ ✓  !LVOJU ✓ߴڮ๜඙ ✓OFDPNPSJ--$ ✓ʮ1)1ϚχϡΞϧΛಡ΋͏ʯQPEDBTU ✓IUUQQIQNBOVBMOFDPNPSJBTJB ✓QIQPOEPD

  3. ຊ೔ͷൃද͸ɾɾɾ ✓߃ྫˍ͓໿ଋʹͳͬͯ·͕͢ɾɾɾ ✓ࠓ͓࢓ࣄͰ͓ੈ࿩ʹͳ͍ͬͯΔ #"4&͞ΜͰͷܦݧ͕ɺ͔ͳΓੜ͔͞ ͍ͯ·͢ ✓IUUQTUIFCBTFJO ✓ઈࢍ։ൃऀืूதͱͷ͜ͱͰ͢ͷͰɺ ڵຯͷ͋Δํ͸ͥͻͥͻ͓໰͍߹ΘͤΛʂ

  4. ຊ೔ͷൃදͷલʹ ✓1)1FS,BJHJ ✓ ✓ࢲ͸$BLF1)1ͷ*OUFSBDUJWF 3PVOE5BCMFͱ͍͏΍ͭͷ࢘ձΛ ͠·͢

  5. օ͞Μ$*ճͯ͠·͔͢ʁ ✓KFOLJT ✓ESPOFJP ✓(JU-BC$* ✓5SBWJT$* ✓$JSDMF$* ✓ͦͷଞ

  6. ຊ೔͸ɾɾɾ ✓ൃදλΠτϧ௨Γɺ $JSDMF$*Λ࢖͍͖ͬͯ·͢ ✓$JSDMF$*ʹ͸ͱ ͕͋Γɺࠓ೔͸Λ ϝΠϯʹ࿩͠·͢

  7. $JSDMF$* ✓6CVOUV͕ೖͬͨ7.্Ͱ֤ϛυϧ΢ΣΞΛ-JOVY ίϯςφͱͯ͠ಈ͔ͯ͠ςετΛߦ͏ ✓ϦϙδτϦ௚ԼʹDJSDMFZNMͱ͍͏ઃఆϑΝΠϧΛ ഑ஔ ✓σϑΥϧτͷڍಈ͕ܾ·͍ͬͯͯɺͦͷڍಈΛඞཁʹ Ԡ্ͯ͡ॻ͖͍ͯ͘͠ ✓1)1ͷόʔδϣϯͷ੾Γସ͑͸಺෦తʹQIQFOW Λ࢖༻͍ͯ͠Δ ✓5SBWJTͷQIQFOWΛ࢖͍ͬͯΔͷͰɺQIQFOW

    ͸ҙ֎ͱ$*αʔϏεͰ࢖ΘΕ͍ͯΔ
  8. $JSDMF$*ͷਏ͍ͱ͜Ζ ✓σϑΥϧτͰೖ͍ͬͯΔQIQFOWʹ͸ೖͬͯͳ ͍֦ு͕͋Δ৔߹͸ɺͦͷ֦ுͷCVJME΋΍Βͳ͍ ͱߦ͚ͳ͍ ✓UJNFDPQ֦ுͱ͔ ✓SVOLJU֦ுͱ͔ ✓ͦͷଞɺಛघͳϛυϧ΢ΣΞΛςετͰ࢖͏৔߹ ΋ɺͦΕͷCVJMEΛຖճδϣϒ࣮ߦͷҰ؀ͱͯ͠ߦ Θͳ͍ͱ͍͚ͳ͍ ✓$*͕࣌ؒ௕͘ͳΔ

  9. $JSDMF$*ͷਏ͍ͱ͜Ζ ✓ݱ࣌఺ͰҰ൪ͭΒ͍ͷ͸ ✓ʹͷػೳఏ ڙ͸ऴྃ͢Δ ✓IUUQTDJSDMFDJDPNTVOTFU ✓ͦΕ·ͰʹʹҠߦ͠ͳ͚Ε͹ ͳΒͳ͍

  10. EFNP

  11. $JSDMF$* ✓ʹ("ʹͳͬͨ ✓೥͔ΒͣͬͱЌΛ΍͍ͬͯͨ ✓ϦϙδτϦ௚ԼʹDJSDMFDJ DPOpHZNMͱ͍͏ઃఆϑΝΠϧΛ഑ஔ ✓%PDLFSϕʔεͷ࣮ߦ͕ਪ঑ͱͳͬͨ ✓ಉ༷ͷ7.ϕʔεͷ࣮ߦ΋·ͩ Մೳ

  12. $JSDMF$* ✓%PDLFSJNBHFΛ࢖͏ͨΊɺඍົʹ %PDLFSͷ஌͕ࣝ͋ͬͨ΄͏͕ཧղ͕ਐΉ ✓7.ϕʔεͷ࣮ߦ؀ڥ΋ఏڙ͞Ε͍ͯΔ͕ক དྷతʹϓϥεΞϧϑΝͷ՝ۚର৅ʹͳΔͱ༧ࠂ ͞Ε͍ͯΔ $JSDMF$*తʹ͸%PDLFSϕʔε ʹҠߦͯ͠ཉ͕ͬͯ͠ΔΜͩͱࢥ͏  ✓࠷ۙ͸%PDLFSΛ։ൃ؀ڥͱͯ͠࢖͏͜ͱ΋

    ;͖͑ͯͯΔ͔Βɺ͜ΕΛػձʹ%PDLFS͝ͱ ֶश͢Δͷ͕͍͍͔΋
  13. $JSDMF$* ✓ҎԼͷΑ͏ͳڍಈͱͳΔ %PDLFSΛ͔ͭͬͨ΋ͷ  ✓%PDLFS)VC౳ͷ3FHJTUSZαʔϏε͔Β %PDLFSJNBHFΛऔಘ͠ɺίϯςφىಈ ✓͜͜Ҏ߱͸ͦͷ%PDLFSJNBHFΛ΋ͱʹىಈ͠ ͨίϯςφ಺ͷಈ࡞ͱͳΔ ✓HJUIVC͔ΒιʔεΛDMPOF ✓DPNQPTFSJOTUBMM౳ͷςετͷલ४උ

    ✓QIQVOJU౳Λ࢖ͬͯςετ ✓݁ՌΛTMBDL౳ͱ࿈ܞͯ͠௨஌
  14. $JSDMF$* ✓ઃఆϑΝΠϧ͸ɺϦϙδτϦͷτο ϓʹDJSDMFDJͱ͍͏σΟϨΫτ ϦΛ࡞ΓɺͦͷதʹDPOpHZNM ͱ͍͏ϑΝΠϧΛஔ͘ͱͦΕΛ࢖ͬ ͯ$*͕࣮ߦ͞ΕΔ ✓DPOpHZNMͷॻ͖ํΛ؆୯ʹ આ໌͍͖ͯ͠·͢

  15. DJSDMFDJDPOpHZNM version: 2 jobs: build: docker: - image: circleci/php:7.1-apache-browsers working_directory:

    /var/www/html steps: - checkout - restore_cache: keys: - composer-{{ arch }}—{{ checksum "composer.lock" }} - composer-{{ arch }}— - run: composer install - save_cache: key: composer-{{ arch }}—{{ checksum "composer.lock" }} paths: - ~/.composer/cache - run: ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml - store_test_results: path: ~/phpunit - store_artifacts: path: ~/phpunit
  16. DJSDMFDJDPOpHZNM ✓ઃఆ͢ΔηΫγϣϯ ✓KPCT ✓ෳ਺ͷδϣϒΛઃఆ͢Δ ✓XPSLqPXT ✓ෳ਺ͷδϣϒΛͲͷΑ͏ʹ࣮ߦ ͢Δ͔Λઃఆ͢Δ

  17. DJSDMFDJDPOpHZNM version: 2 jobs: build: docker: - image: circleci/php:7.1-apache-browsers working_directory:

    /var/www/html steps: - checkout - restore_cache: keys: - composer-{{ arch }}—{{ checksum "composer.lock" }} - composer-{{ arch }}— - run: composer install - save_cache: key: composer-{{ arch }}—{{ checksum "composer.lock" }} paths: - ~/.composer/cache - run: ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml - store_test_results: path: ~/phpunit - store_artifacts: path: ~/phpunit
  18. KPCT ✓δϣϒΛઃఆ͢Δ ✓δϣϒ໊ σϑΥϧτ͸CVJME  ✓ޙ΄Ͳग़ͯ͘ΔXPSLqPXͰ࢖༻͢Δ ✓FYFDVUPSΛઃఆ ✓EPDLFS ✓NBDIJOF ಉ༷ͷ7.؀ڥ

     ✓NBDPT ✓XPSLJOH@EJSFDUPSZ ✓࣮ߦσΟϨΫτϦΛࢦఆ͢Δ ✓TUFQTͰࡉ͔͍࣮ߦ಺༰Λઃఆ͢Δ
  19. DJSDMFDJDPOpHZNM version: 2 jobs: build: docker: - image: circleci/php:7.1-apache-browsers working_directory:

    /var/www/html steps: - checkout - restore_cache: keys: - composer-{{ arch }}—{{ checksum "composer.lock" }} - composer-{{ arch }}— - run: composer install - save_cache: key: composer-{{ arch }}—{{ checksum "composer.lock" }} paths: - ~/.composer/cache - run: ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml - store_test_results: path: ~/phpunit - store_artifacts: path: ~/phpunit
  20. TUFQT ✓DIFDLPVU ✓ιʔεΛDIFDLPVU͢Δ ✓SVO ✓ίϚϯυΛ࣮ߦ͢Δ ✓SFTUPSF@DBDIFTBWF@DBDIF ✓DPNQPTFS΍CVOEMFSΛຖճ΍͍ͬͯΔͱ࣌ؒ ͷΉͩͳͷͰɺద౰ͳΩʔΛ࢖ͬͯΩϟογϡ͢Δ ✓TUPSF@BSUJGBDUTTUPSF@UFTU@SFTVMUT ✓ςετ݁ՌΛ$*ͷ݁Ռදࣔʹ൓өͤ͞Δ

  21. DJSDMFDJDPOpHZNM version: 2 jobs: build: docker: - image: circleci/php:7.1-apache-browsers working_directory:

    /var/www/html steps: - checkout - restore_cache: keys: - composer-{{ arch }}—{{ checksum "composer.lock" }} - composer-{{ arch }}— - run: composer install - save_cache: key: composer-{{ arch }}—{{ checksum "composer.lock" }} paths: - ~/.composer/cache - run: ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml - store_test_results: path: ~/phpunit - store_artifacts: path: ~/phpunit
  22. SVO ✓ίϚϯυΛ࣮ߦ͢Δ΋ͷͩ ͕ɺ࣮ߦը໘Ͱදࣔ͢Δจࣈ ྻΛઃఆͰ͖Δ - run: ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml -

    run: name: run tests command: ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml - run: name: run tests command: | ./vendor/bin/phpunit --log-junit ~/phpunit/junit.xml
  23. ෳ਺ͷ%PDLFSΠϝʔδΛ࢖͏ ✓EPDLFSFYFDVUPSͷઃఆͰෳ਺ͷJNBHFΛࢦఆ͢Δ ✓ͭ໨ʹࢦఆͨ͠JNBHF͕ϓϥΠϚϦΠϝʔδʹͳΓɺ TUFQTҎ߱ͷίϚϯυ͸ͦͷΠϝʔδʹର࣮ͯ͠ߦ͞ΕΔ ✓ͦͷଞͷίϯςφͷϓϩηεʹ͸ɺ ϙʔτ൪ ߸ ͰΞΫηεͰ͖Δ version: 2

    jobs: build: docker: - image: php:7.1-apache - image: circleci/mysql:5.7 environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: test_app MYSQL_USER: test MYSQL_PASSWORD: test - image: redis:3.2
  24. 1SJWBUF3FHJTUSZͷ%PDLFSΠϝʔδΛ࢖͏ ✓ೝূ͕ඞཁͳ৔߹͸͍͔ͭ͘ࢦఆํ๏͕͋Δ ✓"84&$3ͷࢦఆํ๏͕ಛघ ✓&$3͕௨ৗͷEPDLFSMPHJOΛ͢ΔܗͰ͸ͳ͍ͨΊ version: 2 jobs: build: docker: -

    image: private/sample:1.0 auth: username: DOCKER_HUB_USERNAME password: DOCKER_HUB_PASSWORD - image: account-id.dkr.ecr.us-east-1.amazonaws.com/org/repo:0.1 aws_auth: aws_access_key_id: ECS_AWS_ACCESS_KEY aws_secret_access_key: ECS_AWS_SECRET_ACCESS_KEY
  25. $JSDMF$*ఏڙͷJNBHF ✓ݴޠ͓Αͼϛυϧ΢ΣΞʹؔͯ͠ɺ$JSDMF$*ࣗମ ͕%PDLFS)VCͰ഑෍͞Ε͍ͯΔΦϑΟγϟϧͷ JNBHFΛ࢖ͬͯɺΧελϜJNBHFΛ഑෍͍ͯ͠Δ ✓%#ͷJNBHF౳͸ɺνϡʔχϯά͕͔ͳΓߦΘ Ε͍ͯΔͷͰςετ͕࣌ؒ୹ॖ͞ΕΔ౳ͷϝϦο τʹܨ͕Δ ✓ಛʹ໰୊͕ͳ͍ݶΓɺ$JSDMF$*഑෍ͷJNBHF Λࢼͯ͠ΈΔ͜ͱΛ͓͢͢Ί͢Δ ✓IUUQTIVCEPDLFSDPNVDJSDMFDJ

  26. EPDLFSJNBHFͷஔ͖৔ॴ ✓$JSDMF$*͸͓ͦΒ͘"84ͷVTFBTUͰಈ ͍͍ͯΔ ✓%PDLFS)VC΋͓ͦΒ͘"84ͷVTFBTU Ͱಈ͍͍ͯΔ ✓JNBHFͷQVMM͕ૣ͍ ✓"84ͷ&$3Λ࢖͏৔߹ɺಉ༷ʹVTFBTU ʹ͓͍ͨ΄͏͕ྑ͍ ✓౦ژϦʔδϣϯʹஔ͘ͱJNBHFͷऔಘʹ༨ܭ ͳ͕͔͔࣌ؒΔͨΊɺ$*ͷ͕࣌ؒ௕͘ͳΔ

  27. XPSLqPX ✓$JSDMF$*ͷ৽ػೳ ✓ෳ਺ͷδϣϒΛͲͷΑ͏ͳґଘؔ܎ ॱ ൪ Ͱ࣮ߦ͢Δ͔ΛఆٛͰ͖Δ ✓ྫ͑͹ɺQIQDTͰΤϥʔ͕ͳ͍৔߹ ͷΈɺQIQVOJUΛ૸Β͍ͤͨͱ͔ ✓࠷ۙೖͬͨػೳͱͯ͠ɺܾ·ͬͨ࣌ؒ ʹδϣϒΛ࣮ߦ͢Δػೳ͕௥Ճ͞Εͨ

  28. DJSDMFDJDPOpHZNM workflows: version: 2 phpcs_test_deploy_workflow: jobs: - phpcs - test:

    requires: - phpcs - deploy filters: branches: only: - master requires: - test cron_workflow: triggers: - schedule: cron: “0 18 * * *” filters: branches: only: - develop jobs: - daily_job
  29. $JSDMF$*ͷϝϦοτ ✓%PDLFSϕʔεʹͳͬͨͷͰɺςετͰඞཁͳ؀ڥ Λ͍Εͨ%PDLFSJNBHFΛ࡞͓͚ͬͯ͹ɺCVJME࣌ ؒ͸ඞཁͳ͘ͳΔ ✓%PDLFSJNBHFͷαΠζΛେ͖͘͢ΔͱQVMMͷ ͕࣌ؒ$*ͷ࣮ߦ࣌ؒʹ௚݁͢ΔͷͰ஫ҙ ✓ தͷਓᐌ͘ ͷࠒ͸ɺδϣϒͷ࣮ߦΛTTI઀ଓ Ͱແཧ΍Γ΍͍ͬͯͨͷͰɺมͳΤϥʔ͕౓ʑൃੜ͠

    ͍͕ͯͨɺʹͳ͔ͬͯΒ͸ɺδϣϒ࣮ߦ͸H31$ ܦ༝ʹͳͬͨͷͰɺ࣮ߦ΋ૣ͘ͳΓɺ৴པੑ΋্͕ͬ ͨ
  30. ࠷ۙ͸҆ఆ͖͍ͯͯ͠Δ ✓("ʹͳͬͨ೥݄Ҏ߱ɺ͸͠ ͹Β͘͸݁ߏෆ҆ఆͳঢ়ଶͩͬͨ ✓ͷϫʔΫϑϩʔ͚ͩམ͍ͪͯΔͱ͔ ✓ͷδϣϒ͚ͩ΍ͨΒ଴ͨ͞ΕΔͱ͔ ✓͜͜਺ϲ݄͸݁ߏຊମ͸མͪண͍͍ͯΔ ✓%PDLFS)VCͱͷ࿈ܞͱ͔ɺ)FSPLV ͱͷ࿈ܞͱ͔ɺ֎෦ͷ࿈ܞ͕࣌ʑམͪͯΔ͜ ͱ͕͋Δ

  31. ͝ਗ਼ௌ ͋Γ͕ͱ͏ ͍͟͝·ͨ͠