CircleCI 2.0 をつかってみよう / CircleCI #phpcondo2017

CircleCI 2.0 をつかってみよう / CircleCI #phpcondo2017

42305fafd669602e3865a9ac99313257?s=128

TAKAHASHI Kunihiko

November 25, 2017
Tweet

Transcript

  1. $JSDMF$* Λ࢖ͬͯΈΑ͏ 1)1ΧϯϑΝϨϯε๺ւಓग़ு൛ Ծ 1)1Φϑձ LVOJU

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

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

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

  5. ຊ೔͸ɾɾɾ ✓ൃදλΠτϧ௨Γɺ $JSDMF$*Λ࢖͍͖ͬͯ·͢

  6. $JSDMF$* ✓6CVOUVͰ࡞ΒΕͨ7.্Ͱ֤ϛυϧ΢ΣΞΛ -JOVYίϯςφͱͯ͠ಈ͔ͯ͠ςετΛߦ͏ ✓ϦϙδτϦ௚ԼʹDJSDMFZNMͱ͍͏ઃఆϑΝΠϧΛ഑ஔ ✓ઃఆ஋ͱͯ͠ɺར༻͢Δݴޠͷόʔδϣϯ΍ϛυϧ΢Σ ΞΛࢦఆͯ͠ɺܾΊΒΕͨηΫγϣϯʹରͯ͠ઃఆΛ௥Ճ ͍ͯ͘͠ ✓1)1ͷόʔδϣϯͷ੾Γସ͑͸಺෦తʹQIQFOWΛ࢖ ༻͍ͯ͠Δ ✓5SBWJTͷQIQFOWΛ࢖͍ͬͯΔͷͰɺQIQFOW͸

    ҙ֎ͱ$*αʔϏεͰ࢖ΘΕ͍ͯΔ
  7. σϞ ✓ͳʹ͸ͱ΋͋Εಈ͘ͱ͜Ζ ΛΈ͍ͯͩ͘͞

  8. EFNP

  9. DJSDMFZNM ✓ઃఆ͢ΔηΫγϣϯ ✓NBDIJOF ✓DIFDLPVU ✓EFQFOEFODJFT ✓EBUBCBTF ✓DPNQJMF ✓UFTU ✓EFQMPZNFOU ✓ͦΕͧΕͷηΫγϣϯͷઃఆʹରͯ͠ɺQSFPWFSSJEFQPTUͱ

    ͍ͬͨ΋ͷΛ௥Ճͯ͠ࣄલʹಈ͔͢΋ͷࣄޙʹಈ͔͢΋ͷͱ͍ͬͨ΋ ͷΛઃఆ͍ͯ͘͠
  10. DJSDMFZNM machine: timezone: Asia/Tokyo php: version: 7.1.9 services: - mysql

    - redis environment: DEBUG: true DATABASE_SERVER: localhost REDIS_SERVER: localhost dependencies: cache_directories: - ~/.composer/cache pre: - echo "memory_limit = 64M" > /opt/circleci/php/$(phpenv global)/etc/conf.d/memory.ini - composer config -g github-oauth.github.com $GITHUB_ACCESS_TOKEN override: - composer install --prefer-dist --no-interaction test: override: - mkdir -p $CIRCLE_TEST_REPORTS/phpunit - vendor/bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
  11. $JSDMF$*ͷਏ͍ͱ͜Ζ ✓σϑΥϧτͰೖ͍ͬͯΔQIQFOWʹ͸ೖͬͯͳ ͍֦ு͕͋Δ৔߹͸ɺͦͷ֦ுͷCVJME΋΍Βͳ͍ ͱߦ͚ͳ͍ ✓UJNFDPQ֦ுͱ͔ ✓SVOLJU֦ுͱ͔ ✓ͦͷଞɺಛघͳϛυϧ΢ΣΞΛςετͰ࢖͏৔߹ ΋ɺͦΕͷCVJMEΛຖճδϣϒ࣮ߦͷҰ؀ͱͯ͠ߦ Θͳ͍ͱ͍͚ͳ͍ ✓$*͕࣌ؒ௕͘ͳΔ

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

  13. σϞ ✓ઌఔͷ΋ͷΛ$JSDMF$* Խͯ͠Έ·͢

  14. EFNP

  15. DJSDMFDJDPOpHZNM ✓ઃఆ͢ΔηΫγϣϯ ✓KPCT ✓ෳ਺ͷδϣϒΛઃఆ͢Δ ✓XPSLqPXT ✓ෳ਺ͷδϣϒΛͲͷΑ͏ʹ࣮ߦ ͢Δ͔Λઃఆ͢Δ

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

    ~/repo steps: - checkout - restore_cache: keys: - v1-dependencies-{{ checksum "composer.json" }} - v1-dependencies- - run: composer install -n --prefer-dist - save_cache: paths: - ./vendor key: v1-dependencies-{{ checksum "composer.json" }} - run: ./vendor/bin/phpunit --log-junit ~/reports/phpunit/junit.xml - store_artifacts: path: ~/reports/ - store_test_results: path: ~/reports/
  17. KPCT ✓δϣϒΛઃఆ͢Δ ✓δϣϒ໊ σϑΥϧτ͸CVJME  ✓ޙ΄Ͳग़ͯ͘ΔXPSLqPXͰ࢖༻͢Δ ✓FYFDVUPSΛઃఆ ✓EPDLFS ✓NBDIJOF ಉ༷ͷ7.؀ڥ

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

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

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

    ~/repo steps: - checkout - restore_cache: keys: - v1-dependencies-{{ checksum "composer.json" }} - v1-dependencies- - run: composer install -n --prefer-dist - save_cache: paths: - ./vendor key: v1-dependencies-{{ checksum "composer.json" }} - run: ./vendor/bin/phpunit --log-junit ~/reports/phpunit/junit.xml - store_artifacts: path: ~/reports/ - store_test_results: path: ~/reports/
  21. SVO ✓ίϚϯυΛ࣮ߦ͢Δ΋ͷͩ ͕ɺ࣮ߦը໘Ͱදࣔ͢Δจࣈ ྻΛઃఆͰ͖Δ - run: ./vendor/bin/phpunit --log-junit ~/reports/phpunit/junit.xml -

    run: name: run tests command: ./vendor/bin/phpunit --log-junit ~/reports/phpunit/junit.xml - run: name: run tests command: | ./vendor/bin/phpunit --log-junit ~/reports/phpunit/junit.xml
  22. ෳ਺ͷ%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
  23. 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
  24. $JSDMF$*ఏڙͷJNBHF ✓ݴޠ͓Αͼϛυϧ΢ΣΞʹؔͯ͠ɺ$JSDMF$*ࣗମ ͕%PDLFS)VCͰ഑෍͞Ε͍ͯΔΦϑΟγϟϧͷ JNBHFΛ࢖ͬͯɺΧελϜJNBHFΛ഑෍͍ͯ͠Δ ✓%#ͷJNBHF౳͸ɺνϡʔχϯά͕͔ͳΓߦΘ Ε͍ͯΔͷͰςετ͕࣌ؒ୹ॖ͞ΕΔ౳ͷϝϦο τʹܨ͕Δ ✓ಛʹ໰୊͕ͳ͍ݶΓɺ$JSDMF$*഑෍ͷJNBHF Λࢼͯ͠ΈΔ͜ͱΛ͓͢͢Ί͢Δ ✓IUUQTIVCEPDLFSDPNVDJSDMFDJ

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

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

  27. DJSDMFDJDPOpHZNM version: 2 jobs: தུ workflows: version: 2 phpcs_test_deploy_workflow: jobs:

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

    ͍͕ͯͨɺʹͳ͔ͬͯΒ͸ɺδϣϒ࣮ߦ͸H31$ ܦ༝ʹͳͬͨͷͰɺ࣮ߦ΋ૣ͘ͳΓɺ৴པੑ΋্͕ͬ ͨ
  29. ͨͩ͠ɾɾɾ ✓("ʹͳͬͨ೥݄Ҏ߱ɺ͸݁ ߏෆ҆ఆͳঢ়ଶ ✓ͷϫʔΫϑϩʔ͚ͩམ͍ͪͯΔͱ͔ ✓ͷδϣϒ͚ͩ΍ͨΒ଴ͨ͞ΕΔͱ͔ ✓͓ͦΒ͘ࢥͬͨҎ্ʹ͔ΒͷҎ͓߱Αͼ ৽نͷར༻͕૿͑ͨͷͰ͸ͳ͍͔ʁ ✓ڙڅ͕धཁʹ௥͍͍ͭͯͳͯ͘ɺݱ࣌఺Ͱ ͸݁ߏෆ҆ఆɾɾɾ

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