$30 off During Our Annual Pro Sale. View Details »

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

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

TAKAHASHI Kunihiko

November 25, 2017
Tweet

More Decks by TAKAHASHI Kunihiko

Other Decks in Technology

Transcript

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

    View Slide

  2. ࣗݾ঺հ


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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  7. σϞ
    ✓ͳʹ͸ͱ΋͋Εಈ͘ͱ͜Ζ
    ΛΈ͍ͯͩ͘͞

    View Slide

  8. EFNP

    View Slide

  9. DJSDMFZNM
    ✓ઃఆ͢ΔηΫγϣϯ
    ✓NBDIJOF
    ✓DIFDLPVU
    ✓EFQFOEFODJFT
    ✓EBUBCBTF
    ✓DPNQJMF
    ✓UFTU
    ✓EFQMPZNFOU
    ✓ͦΕͧΕͷηΫγϣϯͷઃఆʹରͯ͠ɺQSFPWFSSJEFQPTUͱ
    ͍ͬͨ΋ͷΛ௥Ճͯ͠ࣄલʹಈ͔͢΋ͷࣄޙʹಈ͔͢΋ͷͱ͍ͬͨ΋
    ͷΛઃఆ͍ͯ͘͠

    View Slide

  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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  14. EFNP

    View Slide

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

    View Slide

  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/

    View Slide

  17. KPCT
    ✓δϣϒΛઃఆ͢Δ
    ✓δϣϒ໊ σϑΥϧτ͸CVJME

    ✓ޙ΄Ͳग़ͯ͘ΔXPSLqPXͰ࢖༻͢Δ
    ✓FYFDVUPSΛઃఆ
    ✓EPDLFS
    ✓NBDIJOF ಉ༷ͷ7.؀ڥ

    ✓NBDPT
    ✓XPSLJOH@EJSFDUPSZ
    ✓࣮ߦσΟϨΫτϦΛࢦఆ͢Δ
    ✓TUFQTͰࡉ͔͍࣮ߦ಺༰Λઃఆ͢Δ

    View Slide

  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/

    View Slide

  19. TUFQT
    ✓DIFDLPVU
    ✓ιʔεΛDIFDLPVU͢Δ
    ✓SVO
    ✓ίϚϯυΛ࣮ߦ͢Δ
    ✓SFTUPSF@DBDIFTBWF@DBDIF
    ✓DPNQPTFS΍CVOEMFSΛຖճ΍͍ͬͯΔͱ࣌ؒ
    ͷΉͩͳͷͰɺద౰ͳΩʔΛ࢖ͬͯΩϟογϡ͢Δ
    ✓TUPSF@BSUJGBDUTTUPSF@UFTU@SFTVMUT
    ✓ςετ݁ՌΛ$*ͷ݁Ռදࣔʹ൓өͤ͞Δ

    View Slide

  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/

    View Slide

  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

    View Slide

  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

    View Slide

  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

    View Slide

  24. $JSDMF$*ఏڙͷJNBHF
    ✓ݴޠ͓Αͼϛυϧ΢ΣΞʹؔͯ͠ɺ$JSDMF$*ࣗମ
    ͕%PDLFS)VCͰ഑෍͞Ε͍ͯΔΦϑΟγϟϧͷ
    JNBHFΛ࢖ͬͯɺΧελϜJNBHFΛ഑෍͍ͯ͠Δ
    ✓%#ͷJNBHF౳͸ɺνϡʔχϯά͕͔ͳΓߦΘ
    Ε͍ͯΔͷͰςετ͕࣌ؒ୹ॖ͞ΕΔ౳ͷϝϦο
    τʹܨ͕Δ
    ✓ಛʹ໰୊͕ͳ͍ݶΓɺ$JSDMF$*഑෍ͷJNBHF
    Λࢼͯ͠ΈΔ͜ͱΛ͓͢͢Ί͢Δ
    ✓IUUQTIVCEPDLFSDPNVDJSDMFDJ

    View Slide

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

    View Slide

  26. XPSLqPX
    ✓$JSDMF$*ͷ৽ػೳ
    ✓ෳ਺ͷδϣϒΛͲͷΑ͏ͳґଘؔ܎ ॱ

    Ͱ࣮ߦ͢Δ͔ΛఆٛͰ͖Δ
    ✓ྫ͑͹ɺQIQDTͰΤϥʔ͕ͳ͍৔߹
    ͷΈɺQIQVOJUΛ૸Β͍ͤͨͱ͔
    ✓࠷ۙೖͬͨػೳͱͯ͠ɺܾ·ͬͨ࣌ؒ
    ʹδϣϒΛ࣮ߦ͢Δػೳ͕௥Ճ͞Εͨ

    View Slide

  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

    View Slide

  28. $JSDMF$*ͷϝϦοτ
    ✓%PDLFSϕʔεʹͳͬͨͷͰɺςετͰඞཁͳ؀ڥ
    Λ͍Εͨ%PDLFSJNBHFΛ࡞͓͚ͬͯ͹ɺCVJME࣌
    ؒ͸ඞཁͳ͘ͳΔ
    ✓%PDLFSJNBHFͷαΠζΛେ͖͘͢ΔͱQVMMͷ
    ͕࣌ؒ$*ͷ࣮ߦ࣌ؒʹ௚݁͢ΔͷͰ஫ҙ
    ✓ தͷਓᐌ͘
    ͷࠒ͸ɺδϣϒͷ࣮ߦΛTTI઀ଓ
    Ͱແཧ΍Γ΍͍ͬͯͨͷͰɺมͳΤϥʔ͕౓ʑൃੜ͠
    ͍͕ͯͨɺʹͳ͔ͬͯΒ͸ɺδϣϒ࣮ߦ͸H31$
    ܦ༝ʹͳͬͨͷͰɺ࣮ߦ΋ૣ͘ͳΓɺ৴པੑ΋্͕ͬ
    ͨ

    View Slide

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

    View Slide

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

    View Slide