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

Laravelを本番環境にデプロイするまで

0e8b27d56fef57343f62e9510e6d1446?s=47 yukure
March 18, 2019

 Laravelを本番環境にデプロイするまで

0e8b27d56fef57343f62e9510e6d1446?s=128

yukure

March 18, 2019
Tweet

Transcript

  1. LaravelΛ ຊ൪؀ڥʹ σϓϩΠ͢Δ·Ͱ @yukure3

  2. ࣗݾ঺հ • ໊લɿߚྛ ༏ (@yukure3) • ॴଐɿגࣜձࣾ͏ΔΔ • ܦྺɿ৽ଔ̍೥໨ΤϯδχΞ •

    ࠷ۙ΍͍ͬͯΔ͜ͱɿLaravel / Vue.js • ͓఻͑ͨ͜͠ͱɿࠓճͷLT͕ਓੜॳొஃͰ͢…!!
  3. ࣗݾ঺հ • ໊લɿߚྛ ༏ (@yukure3) • ॴଐɿגࣜձࣾ͏ΔΔ • ܦྺɿ৽ଔ̍೥໨ΤϯδχΞ •

    ࠷ۙ΍͍ͬͯΔ͜ͱɿLaravel / Vue.js • ͓఻͑ͨ͜͠ͱɿࠓճͷLT͕ਓੜॳొஃͰ͢…!!
  4. ͜Μͳํʹ • ʮͳΜ͔LaravelΑͦ͞͏͔ͩΒ࢖ͬͯΈ͍ͨͳ͊ɻʯ • ʮ։ൃ؀ڥͲ͏্ཱͪ͛Δͷָ͔ͳͷ͔ͳ͊ɻʯ • ʮຊ൪ӡ༻΋ߟ͑ͳ͍ͱ͍͚ͳ͍͚ͲָͰ͖ͳ͍͔ͳ͊ɻʯ

  5. ͜Μͳ͜ͱΛ఻͍͑ͨ Laravel ʹूதͰ͖Δํ๏ ※Laravelࣗମͷྑ͞͸ଞͷํʑ͕ͨ͘͞Μઆ໌ͯ͘͠Ε·͢ʂʂ

  6. ΞδΣϯμ • ࣮ݱ͍ͨ͜͠ͱ • ։ൃ؀ڥͱӡ༻؀ڥʹखؒΛ͔͚ͣʹߏங͢Δ • ඞཁͳ΋ͷ • ্هΛ࣮ݱ͢ΔͨΊʹඞཁͳ΋ͷΛ঺հ •

    ·ͱΊ
  7. ࣮ݱ͍ͨ͜͠ͱ

  8. ࣮ݱ͍ͨ͜͠ͱ

  9. ඞཁͳ΋ͷ

  10. ϩʔΧϧ։ൃ؀ڥ => Laradock ຊ൪؀ڥ => AWS Elastic Beanstalk CI/CDύΠϓϥΠϯ =>

    CircleCI όʔδϣϯ؅ཧ => GitHub ඞཁͳ΋ͷ
  11. ϩʔΧϧ։ൃ؀ڥ

  12. ϩʔΧϧ։ൃ؀ڥ ͜͜Λ࡞͍͖ͬͯ·͢ʂ

  13. ϩʔΧϧ։ൃ؀ڥ # σΟϨΫτϦ࡞੒ & ͦͷσΟϨΫτϦʹҠಈ $ mkdir project && cd

    project # laradockΛΫϩʔϯ $ git clone https://github.com/Laradock/laradock.git # laravel(࠷৽൛)ΛΠϯετʔϧ $ composer create-project --prefer-dist laravel/laravel src # LaradockσΟϨΫτϦҠಈ & .envΛ࡞੒ $ cd laradock $ cp env-example .env # σΟϨΫτϦߏ଄ project !"" laradock ←ΠϚίίʂʂ #"" src
  14. .env(laradock)ͷमਖ਼ # nginx ͷport & mysqlͷ version มߋ - APP_CODE_PATH_HOST=../

    + APP_CODE_PATH_HOST=../src - NGINX_HOST_HTTP_PORT=80 + NGINX_HOST_HTTP_PORT=8001 - MYSQL_VERSION=latest + MYSQL_VERSION=5.7
  15. .env(laravel)ͷमਖ਼ # ઀ଓઌͷDBมߋ - DB_HOST=127.0.0.1 + DB_HOST=mysql - DB_DATABASE=homestead +

    DB_DATABASE=default - DB_USERNAME=homestead + DB_USERNAME=root - DB_PASSWORD=secret + DB_PASSWORD=root
  16. ϩʔΧϧ։ൃ؀ڥΛ্ཱͪ͛Δ # ΠϝʔδΛϏϧυͯ͠ىಈ͢Δ docker-compose up -d nginx mysql workspace MPDBMIPTUʹΞΫηε

  17. ຊ൪؀ڥ

  18. ຊ൪؀ڥ ͜͜Λ࡞͍͖ͬͯ·͢ʂ

  19. ίϯιʔϧͰBeanstalkΛݕࡧ

  20. ৽͍͠ΞϓϦέʔγϣϯͷ࡞੒

  21. ΞϓϦέʔγϣϯ໊Λઃఆ

  22. ΞϓϦέʔγϣϯ಺ʹ؀ڥΛ࡞੒

  23. ΢Σϒαʔόʔ؀ڥΛߏங

  24. ؀ڥ৘ใͷઃఆ

  25. ؀ڥ৘ใͷઃఆ

  26. DB(RDS)ͷઃఆ

  27. DB(RDS)ͷઃఆ

  28. ΢Σϒαʔόʔ؀ڥ࡞੒

  29. Ͱ͖·ͨ͠ʂ

  30. όʔδϣϯ؅ཧ

  31. όʔδϣϯ؅ཧ ͜͜Λ࡞͍͖ͬͯ·͢ʂ

  32. ϦϞʔτϦϙδτϦ࡞੒

  33. ϦϞʔτϦϙδτϦ࡞੒ ΫϦοϓϘʔυʹίϐʔ

  34. ϦϞʔτϦϙδτϦ΁push # src΁Ҡಈ cd src # gitϦϙδτϦ࡞੒ git init #

    ઌ΄Ͳ࡞੒ͨ͠ϦϞʔτϦϙδτϦͷ௥Ճ git remote add upstream git@github.com:yukure/laravel-vue.git # first commit ͸͔ΒίϛοτͰʂ git commit --allow-empty -m "first commit!!" # laravelΛόʔδϣϯ؅ཧͷର৅ͱͯ͠௥Ճ git add . # ίϛοτ git commit -m "add: laravel app" # ϦϞʔτϦϙδτϦʹΞοϓϩʔυ git push upstream master
  35. ϦϞʔτϦϙδτϦ΁push

  36. σϑΥϧτϒϥϯνΛมߋ

  37. σϑΥϧτϒϥϯνΛมߋ

  38. σϑΥϧτϒϥϯνΛมߋ

  39. CI/CDύΠϓϥΠϯ

  40. CI/CDύΠϓϥΠϯ ͜͜Λ࡞͍͖ͬͯ·͢ʂ

  41. σϓϩΠ༻ͷIAMͷ࡞੒

  42. σϓϩΠ༻ͷIAMͷ࡞੒

  43. σϓϩΠ༻ͷIAMͷ࡞੒

  44. σϓϩΠ༻ͷIAMͷ࡞੒

  45. σϓϩΠ༻ͷIAMͷ࡞੒

  46. σϓϩΠ༻ͷIAMͷ࡞੒

  47. EB CLIͷΠϯετʔϧ # EB CLIͷΠϯετʔϧ brew install awsebcli # EB

    CLI͕Πϯετʔϧ͞Ε͍ͯΔ͔֬ೝ eb --version
  48. # srcσΟϨΫτϦ಺Ͱߦ͍ͬͯͩ͘͞ # ॳظઃఆ(.elasticbeanstalk/config.ymlͷ࡞੒) eb init # ͜Μͳײ͡Ͱ౴͍͖͑ͯ·͢ Select a

    default region 1) us-east-1 : US East (N. Virginia) 2) us-west-1 : US West (N. California) 3) us-west-2 : US West (Oregon) 4) eu-west-1 : EU (Ireland) 5) eu-central-1 : EU (Frankfurt) 6) ap-south-1 : Asia Pacific (Mumbai) 7) ap-southeast-1 : Asia Pacific (Singapore) 8) ap-southeast-2 : Asia Pacific (Sydney) 9) ap-northeast-1 : Asia Pacific (Tokyo) 10) ap-northeast-2 : Asia Pacific (Seoul) 11) sa-east-1 : South America (Sao Paulo) 12) cn-north-1 : China (Beijing) 13) cn-northwest-1 : China (Ningxia) 14) us-east-2 : US East (Ohio) 15) ca-central-1 : Canada (Central) 16) eu-west-2 : EU (London) 17) eu-west-3 : EU (Paris) (default is 3): 9 Select an application to use 1) laravel-vue 2) [ Create new Application ] (default is 1): 1 Select the default environment. You can change this later by typing "eb use [environment_name]". 1) laravel-vue (default is 1): 1 Note: Elastic Beanstalk now supports AWS CodeCommit; a fully-managed source control service. To learn more, see Docs: https://aws.amazon.com/codecommit/ Do you wish to continue with CodeCommit? (y/N) (default is n): n Ϧʔδϣϯͷબ୒ ͲͷΞϓϦέʔγϣϯΛ࢖͏͔ Ͳͷ؀ڥʹσϓϩΠ͢Δ͔ $PEF$PNNJU࢖͏͔
  49. config.global.ymlͷઃఆ # ઃఆϑΝΠϧ࡞੒ vim .elasticbeanstalk/config.global.yml # ͜ͷΑ͏ʹઃఆ͢Δ global: application_name: laravel-vue

    default_region: ap-northeast-1 ͖͞΄Ͳ࡞੒ͨ͠&#ͷΞϓϦέʔγϣϯ໊
  50. CircleCIͷઃఆ

  51. .circleci/config.ymlͷઃఆ # ※srcσΟϨΫτϦ಺Ͱ↓Λߦ͍ͬͯͩ͘͞ # .circleciσΟϨΫτϦ࡞੒ & σΟϨΫτϦʹҠಈ mkdir .circleci &&

    cd .circleci # ઃఆϑΝΠϧΛ࡞੒ vim config.yml
  52. version: 2 defaults: &defaults working_directory: ~/app docker: - image: circleci/php:7.1-node-browsers

    - image: circleci/mysql:5.7 environment: - AWS_REGION: ap-northeast-1 - APP_DEBUG: true - APP_ENV: testing - APP_KEY: base64:cNWYphm1YWH+RGYFLZpn6MBKj/TRiMm46KbuWA8Ei8c= - DB_DATABASE: circle_test - DB_USERNAME: root - MYSQL_ALLOW_EMPTY_PASSWORD: true jobs: build: <<: *defaults steps: - checkout - run: name: install pdo_mysql command: | sudo apt update sudo docker-php-ext-install pdo_mysql sudo docker-php-ext-enable pdo_mysql # Download and cache dependencies - restore_cache: keys: - v1-dependencies-{{ checksum "composer.json" }} # fallback to using the latest cache if no exact match is found - v1-dependencies- - run: composer install -n --prefer-dist - save_cache: paths: - ./vendor key: v1-dependencies-{{ checksum "composer.json" }} # run seeding - run: php artisan migrate - run: php artisan db:seed # run test - run: ./vendor/bin/phpunit deploy: <<: *defaults steps: - checkout - run: name: Install awsebcli command: | sudo apt-get -y -qq update sudo apt-get install python-pip python-dev build-essential sudo pip install awsebcli --upgrade - run: name: eb deploy command: eb deploy laravel-vue workflows: version: 2 build_and_deploy: jobs: - build - deploy: filters: branches: only: - master ίϯςφͷΠϝʔδ΍ ؀ڥม਺Λఆٛ Ϗϧυɾςετͷ࣮ߦ 8PSLqPX δϣϒͷॱ൪ ӡ༻؀ڥ΁σϓϩΠ
  53. .circleci/config.ymlͷઃఆ deploy: <<: *defaults steps: - checkout - run: name:

    Install awsebcli command: | sudo apt-get -y -qq update sudo apt-get install python-pip python-dev build-essential sudo pip install awsebcli --upgrade - run: name: eb deploy command: eb deploy laravel-vue &#ͷ؀ڥ໊ &#$-*Πϯετʔϧ HJUIVC͔ΒίʔυΛνΣοΫΞ΢τ
  54. ͳΜͷઃఆΛͨ͠ͷ͔ • PR͕࡞੒͞ΕͨΒɺϏϧυɾςετΛ࣮ߦɻ • masterϒϥϯνʹPR͕Ϛʔδ͞ΕͨΒ 
 eb deployίϚϯυΛ࣮ߦɻ

  55. CircleCIͷઃఆ

  56. CircleCIͷઃఆ

  57. CircleCIͷઃఆ

  58. CircleCIͷઃఆ

  59. ؀ڥม਺ͷઃఆ

  60. ؀ڥม਺ͷઃఆ

  61. ؀ڥม਺ͷઃఆ $47ʹهࡌͷ͋ΔΩʔΛೖྗ $47ʹهࡌͷ͋Δ஋Λೖྗ

  62. σϓϩΠͷςετ # ϒϥϯνͷ੾Γସ͑ git checkout -b edit_readme # readme.mdΛฤू͢Δ vim

    readme.md # Laravel/Vue.jsษڧձ#8 Φʔϧελʔζ **Let's Enjoy Laravel!!!!!!!!!!!!!!!!!!!!!!!!!!** readme.md
  63. github΁push git add . git commit -m "edit: readme.md" git

    push upstream edit_readme
  64. PR࡞੒

  65. PRΛϚʔδ

  66. CircleCIͷδϣϒΛ֬ೝ workflow

  67. CircleCIͷδϣϒΛ֬ೝ workflow

  68. ϖʔδΛ֬ೝͯ͠ΈΔ

  69. ͋Εɺɺɺ

  70. υΩϡϝϯτϧʔτͷઃఆ

  71. APP_KEYͷઃఆ TSDFOWͷ"11@,&:Λίϐϖ͍ͯͩ͘͠͞

  72. None
  73. None
  74. ·ͱΊ

  75. ·ͱΊ • ։ൃ؀ڥ͸LaradockΛ࢖ͬͯ؆୯ʹߏஙͰ͖Δʂ • ӡ༻؀ڥ͸EBΛ࢖ͬͯ؆୯ʹߏஙͰ͖Δ! • CIʗCDύΠϓϥΠϯͰ͓ؾܰӡ༻ʂ

  76. Let’s Enjoy Laravel Life!!!

  77. ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂʂ#