Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps

2 346 vues

Publié le

Web applications are becoming increasingly more complex, so deployment is not just transferring files with FTP anymore. We will go over the different challenges and how to deploy our PHP applications effectively, safely and consistently with the latest tools and techniques. We will also look at tools that complement deployment with management, configuration and monitoring.

Publié dans : Internet
  • Hey guys! Who wants to chat with me? More photos with me here 👉 http://www.bit.ly/katekoxx
       Répondre 
    Voulez-vous vraiment ?  Oui  Non
    Votre message apparaîtra ici

Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps

  1. 1. Pablo Godel ! @pgodel! https://joind.in/12199 Rock Solid Deployment of Symfony Applications Photo:AlvaroVidela
  2. 2. Hi, I am Pablo.
  3. 3. Hi, I am Pablo. ! @pgodel
  4. 4. Deployment ?
  5. 5. Deployment Software deployment is all of the activities that ! make a software system available for use. http://en.wikipedia.org/wiki/Software_deployment
  6. 6. Deployment A very important part of the application life-cycle
  7. 7. Deployment A very important critical part of the application life-cycle
  8. 8. Deployment It should not be an ! after thought
  9. 9. Deployment It should be predictable
  10. 10. Deployment The more you do it the better it goes
  11. 11. Deployment in the PaaS era
  12. 12. 1. Open an account
  13. 13. 2. Create app
  14. 14. 3. Push code
  15. 15. 4. Voilà!
  16. 16. composer.json ! ! Procfile
  17. 17. 
 $ heroku create!
  18. 18. 
 $ git push heroku master!
  19. 19. 
 $ heroku ps:scale web=5!
  20. 20. That’s it! ;-)
  21. 21. Questions? Slides: http://slideshare.net/pgodel Twitter: @pgodel
  22. 22. But…
  23. 23. Deployment for the rest of us
  24. 24. Deployment Goals
  25. 25. One-click deploys Deployment Goals
  26. 26. One-click deploys Deployment Goals
  27. 27. Continuous deploys Deployment Goals
  28. 28. Continuous deploys Deployment Goals
  29. 29. Anytime & Anywhere Deployment Goals
  30. 30. Anytime & Anywhere Deployment Goals
  31. 31. Anyone Deployment Goals
  32. 32. Anyone Deployment Goals
  33. 33. Reliable Deployment Goals
  34. 34. Reliable Deployment Goals
  35. 35. Rollbacks Deployment Goals
  36. 36. Rollbacks Deployment Goals
  37. 37. No downtime Deployment Goals
  38. 38. No downtime Deployment Goals
  39. 39. Reusable Deployment Goals
  40. 40. Reusable Deployment Goals
  41. 41. Reusable Deployment Goals
  42. 42. Scalable Deployment Goals
  43. 43. Scalable Deployment Goals
  44. 44. Deployment Facts
  45. 45. Deployment starts with the developer Deployment Fact #1
  46. 46. Deployment starts with the developer • Development environment must be as close as possible to productions servers! Deployment Fact #1
  47. 47. Deployment starts with the developer • Development environment must be as close as possible to productions servers! • Setup test/qa/staging servers! Deployment Fact #1
  48. 48. Deployment starts with the developer • Development environment must be as close as possible to productions servers! • Setup test/qa/staging servers! • Use Vagrant to manage VMs! Deployment Fact #1
  49. 49. Deployment starts with the developer • Development environment must be as close as possible to productions servers! • Setup test/qa/staging servers! • Use Vagrant to manage VMs! • Use Containers with Docker! Deployment Fact #1
  50. 50. Deployment starts with the developer • Development environment must be as close as possible to productions servers! • Setup test/qa/staging servers! • Use Vagrant to manage VMs! • Use Containers with Docker! • Automate your development environment setup (Ansible, Homebrew Cask) Deployment Fact #1
  51. 51. Success depends on server OS setup Deployment Fact #2
  52. 52. Success depends on server OS setup • Automate installation/configuration with Ansible/ Puppet/Chef ! Deployment Fact #2
  53. 53. • Automate installation/configuration with Ansible/ Puppet/Chef ! • Create OS packages for 3rd party software Deployment Fact #2 Success depends on server OS setup
  54. 54. • Automate installation/configuration with Ansible/ Puppet/Chef ! • Create OS packages for 3rd party software! • Setup your own package (rpm/deb) repositories Deployment Fact #2 Success depends on server OS setup
  55. 55. Monitoring is uptime Deployment Fact #3
  56. 56. Monitoring is uptime • Use tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)! Deployment Fact #3
  57. 57. Monitoring is uptime • Use tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)! Deployment Fact #3
  58. 58. Monitoring is uptime • Use tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)! • Add metrics to your app (Graphite, StatsD, New Relic)! Deployment Fact #3
  59. 59. Monitoring is uptime • Use tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)! • Add metrics to your app (Graphite, StatsD, New Relic)! • Use your logs wisely (Logstash, Hecka, Kibana) Deployment Fact #3
  60. 60. Deployment Methodologies
  61. 61. Deployment Methodologies • VIM-style
  62. 62. Deployment Methodologies • VIM-style! • FTP uploads
  63. 63. Deployment Methodologies • VIM-style! • FTP uploads
  64. 64. Deployment Methodologies • VIM-style! • FTP uploads! • Rsync
  65. 65. Deployment Methodologies • VIM-style! • FTP uploads! • Rsync! • Source control (GIT, SVN)
  66. 66. Deployment Methodologies • VIM-style! • FTP uploads! • Rsync! • Source control (GIT, SVN)! • Build tools (Ant, Phing, Jenkins)!
  67. 67. Deployment Methodologies • VIM-style! • FTP uploads! • Rsync! • Source control (GIT, SVN)! • Build tools (Ant, Phing, Jenkins)! • Package based (RPM, DEB, …) !
  68. 68. Deployment Methodologies • VIM-style! • FTP uploads! • Rsync! • Source control (GIT, SVN)! • Build tools (Ant, Phing, Jenkins)! • Package based (RPM, DEB, …) ! • Specialized tools (Capifony, Deployer, …)!
  69. 69. Deployment Methodologies • VIM-style! • FTP uploads! • Rsync! • Source control (GIT, SVN)! • Build tools (Ant, Phing, Jenkins)! • Package based (RPM, DEB, …) ! • Specialized tools (Capifony, Deployer, …)! • IT automation tools (Ansible, Puppet, Chef, …)
  70. 70. Deployment: Steps overview
  71. 71. Deployment: First time • Copy files to server(s)! • Set server-side configurations! • Load DB fixtures! • Process and install assets! • Warm up cache! • Enable site
  72. 72. Deployment: Subsequent times • Copy files to server(s)! • Update server-side configurations! • Update DB (migrations)! • Process and install assets! • Warm up cache! • Enable new version
  73. 73. We can automate!
  74. 74. Deployment Challenges
  75. 75. Challenge: Secure Deployment Challenges
  76. 76. • use ssh based connections! Challenge: Secure Deployment Challenges
  77. 77. • use ssh based connections! • don’t store passwords on source control Challenge: Secure Deployment Challenges
  78. 78. • use ssh based connections! • don’t store passwords on source control! • use environment variables for sensitive data Challenge: Secure Deployment Challenges
  79. 79. Challenge: Static assets Deployment Challenges
  80. 80. Challenge: Static assets • Minimize/combine JS and CSS files! Deployment Challenges
  81. 81. Challenge: Static assets • Minimize/combine JS and CSS files! • Enable web server compression! Deployment Challenges
  82. 82. Challenge: Static assets • Minimize/combine JS and CSS files! • Enable web server compression! • Add versioning to static assets links (code.js?v=1)! Deployment Challenges
  83. 83. Challenge: Static assets • Minimize/combine JS and CSS files! • Enable web server compression! • Add versioning to static assets links (code.js?v=1)! • Run utilities locally or in a staging server, create artifact, deploy result! Deployment Challenges
  84. 84. Challenge: Static assets • Minimize/combine JS and CSS files! • Enable web server compression! • Add versioning to static assets links (code.js?v=1)! • Run utilities locally or in a staging server, create artifact, deploy result! • Serve static files from subdomain / CDN Deployment Challenges
  85. 85. Challenge: File permission conflicts Deployment Challenges
  86. 86. Challenge: File permission conflicts • Run Apache/PHP with same user! Deployment Challenges
  87. 87. Challenge: File permission conflicts • Run Apache/PHP with same user! • Use php-fpm instead of mod_php! Deployment Challenges
  88. 88. Challenge: File permission conflicts • Run Apache/PHP with same user! • Use php-fpm instead of mod_php! • Create “deploy” user and add web server to the group Deployment Challenges
  89. 89. Challenge: File permission conflicts • Run Apache/PHP with same user! • Use php-fpm instead of mod_php! • Create “deploy” user and add web server to the group! • Use setfacl to give write access to multiple users! Deployment Challenges
  90. 90. Challenge: File permission conflicts • Run Apache/PHP with same user! • Use php-fpm instead of mod_php! • Create “deploy” user and add web server to the group! • Use setfacl to give write access to multiple users! • Use external services for writing files and create readonly installations Deployment Challenges
  91. 91. Common Pitfalls
  92. 92. • Case sensitive filesystems! Common Pitfalls
  93. 93. • Case sensitive filesystems! ! src/Acme/ClassName ! != ! src/Acme/Classname.php Common Pitfalls
  94. 94. • Case sensitive filesystems! ! src/Acme/ClassName ! != ! src/Acme/Classname.php Common Pitfalls
  95. 95. • Case sensitive filesystems! • Configuration differences! Common Pitfalls
  96. 96. • Case sensitive filesystems! • Configuration differences! • Outdated 3rd party software Common Pitfalls
  97. 97. • Case sensitive filesystems! • Configuration differences! • Outdated 3rd party software! • Github down Common Pitfalls
  98. 98. • Case sensitive filesystems! • Configuration differences! • Outdated 3rd party software! • Github down $ git daemon --base-path=/git/repo/path/ -- export-all! ! $ git clone git://127.0.0.1/repo! http://ozmm.org/posts/when_github_goes_down.html Common Pitfalls
  99. 99. • Case sensitive filesystems! • Configuration differences! • Outdated 3rd party software! • Github down Common Pitfalls
  100. 100. Deployment Examples
  101. 101. Simplest continuous deployment ever! <?php ! ! exec(‘/usr/bin/env -i HOME=/var/www git pull’);! echo “All done!”; hook.php Deployment Examples
  102. 102. <?php ! ! exec(‘/usr/bin/env -i HOME=/var/www git pull’);! echo “All done!”; hook.php screenshot Deployment Examples GitHub hook Simplest continuous deployment ever!
  103. 103. Capistrano! ! + ! ! Capifony Deployment Examples
  104. 104. Capistrano / Capifony • Ruby based! • Very extensible! • Large number of extensions! • Simple client side installation Deployment Examples
  105. 105. • Ruby based! • Very extensible! • Large number of extensions! • Simple client side installation 
 $ gem install capistrano! Deployment Examples Capistrano / Capifony
  106. 106. set :application, "myapp" # Application name set :deploy_to, "/var/www/myapp" ! set :user, "deployer" set :use_sudo, false # sudo isn't required ! set :deploy_via, :remote_cache set :repository, "git@github.com:user/repo.git" ! role :web, "server.example.com",“server2.example.com” Deployment Examples Capistrano / Capifony
  107. 107. 
 $ cap deploy:setup
 
 Deployment Examples Capistrano / Capifony
  108. 108. ! |-- releases! `-- shared! |-- logs! `-- uploads! Deployment Examples Capistrano / Capifony
  109. 109. 
 $ cap deploy! $ cap deploy:migrations! $ cap deploy:rollback! Deployment Examples Capistrano / Capifony
  110. 110. ! |-- current 
 (symlink to releases/20130112)! |-- releases! | `-- 20130112! `-- shared! |-- logs! `-- uploads! Deployment Examples Capistrano / Capifony
  111. 111. Deployment Examples Deploying with
  112. 112. Deployment Examples ! ! Define hosts in inventory file [webservers] foo.example.com bar.example.com
 www[01:50].example.com ! [dbservers] one.example.com two.example.com three.example.com
  113. 113. Deployment Examples ! ! Define tasks / actions in playbook --- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: write the apache config file template: src=/srv/httpd.j2 dest=/etc/httpd.conf notify: - restart apache - name: ensure apache is running
  114. 114. Deployment Examples ! ! Reuse tasks with Roles - hosts: webservers roles: - { role: servergrove.symfony2, symfony2_project_root: /var/www/vhosts/ example.com/, symfony2_project_name: demo, symfony2_project_branch: master , symfony2_project_release: 1 }
  115. 115. Deployment Examples ! ! Run process $ ansible-playbook -i inventories/servers playbook.yml -v
  116. 116. Deployment Examples ! ! Run process
  117. 117. Deployment: Other options • Fabric (Python) • Idephix (PHP) • Magellanes (PHP) • Deployer (PHP) • Laravel / envoy (PHP) • Rocketeer (PHP)
  118. 118. Deployment Complement Tools
  119. 119. Packaging: fpm https://github.com/jordansissel/fpm Build packages for multiple platforms (deb, rpm, etc) with great ease and sanity. $ fpm -s dir -t rpm -n "myapp" -v 1.0 /var/www/myapp ! $ fpm -s dir -t deb -a all -n myapp -v 1.0 /etc/apache2/ conf.d/my.conf /var/www/myapp Deployment Complement Tools
  120. 120. App Metrics: StatsD & Graphite Deployment Complement Tools
  121. 121. App Metrics: liuggio/statsd-php-client Deployment Complement Tools $ composer require liuggio/statsd-php-client:dev-master
  122. 122. App Metrics: liuggio/statsd-php-client Deployment Complement Tools $sender = new SocketSender(/*'localhost', 8126, 'udp'*/); ! $client = new StatsdClient($sender); $factory = new StatsdDataFactory('LiuggioStatsdClientEntityStatsdData'); ! // create the data with the factory $data[] = $factory->timing('usageTime', 100); $data[] = $factory->increment('visitor'); $data[] = $factory->decrement('click'); $data[] = $factory->gauge('gaugor', 333); $data[] = $factory->set('uniques', 765); ! // send the data as array or directly as object $client->send($data);
  123. 123. App Metrics: liuggio/statsd-php-client Deployment Complement Tools $data[] = $factory->timing('usageTime', 100);! ! // send the data as array or directly as object $client->send($data);
  124. 124. App Metrics: liuggio/statsd-php-client Deployment Complement Tools $data[] = $factory->increment('orders');! ! // send the data as array or directly as object $client->send($data);
  125. 125. App Metrics: liuggio/statsd-php-client Deployment Complement Tools $data[] = $factory->gauge('memory', 333);! ! // send the data as array or directly as object $client->send($data);
  126. 126. App Metrics: StatsD & Graphite Deployment Complement Tools App StatsD Graphite Grafana App App
  127. 127. Deployment Complement Tools App Metrics: Grafana
  128. 128. Deployment Complement Tools App Metrics: Grafana
  129. 129. Logging: Logstash Ship logs from any source, parse them, get the right timestamp, index them, and search them Deployment Complement Tools input { file { path => “/var/log/apache2/access_log” } } output { elasticsearch { host => localhost } }
  130. 130. Configure Apache to log json LogFormat "{ "@timestamp": "%{%Y-%m-%dT %H:%M:%S%z}t", "@fields": { "client": "%a", "duration_usec": %D, "status": %s, "request": "%U%q", "method": "%m ", "referrer": "%{Referer}i" } }" logstash_json! ! ! # Write our 'logstash_json' logs to logs/ access_json.log! CustomLog logs/access_json.log logstash_json! Deployment Complement Tools Logging: Logstash
  131. 131. Configure Apache to log json LogFormat "{ "@timestamp": "%{%Y-%m-%dT%H:%M:%S%z}t", "@fields": { "client": "%a", "duration_usec": %D, "status": %s, "request": "%U%q", "method": "%m", "referrer": "% {Referer}i" } }" logstash_json! ! ! # Write our 'logstash_json' logs to logs/access_json.log! CustomLog logs/access_json.log logstash_json! { "@timestamp": "2012-08-22T14:35:19-0700", "client": "127.0.0.1", "duration_usec": 532, "status": 404, "request": "/favicon.ico", "method": "GET", "referrer": "-" }! Result Deployment Complement Tools Logging: Logstash
  132. 132. Logging: Kibana Kibana is a user friendly way to view, search and visualize your log data Deployment Complement Tools
  133. 133. Logging: Kibana Kibana is a user friendly way to view, search and visualize your log data Deployment Complement Tools
  134. 134. Logging: Logstash + ElasticSearch + Kibana Deployment Complement Tools App / Logstash Redis Logstash filter/processor ElasticSearch Kibana App / Logstash App / Logstash
  135. 135. Deployment Summary
  136. 136. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  137. 137. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  138. 138. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  139. 139. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  140. 140. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  141. 141. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  142. 142. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  143. 143. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  144. 144. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  145. 145. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  146. 146. Developer Tests build artifact Ansible Production GitHub Jenkins QA deploy Integration 
 Tests Notifications Deployment Summary
  147. 147. Stop using FTP
  148. 148. Plan early
  149. 149. Practice
  150. 150. Monitor
  151. 151. AUTOMATE!
  152. 152. Now, we did finish! ! Questions? Slides: http://slideshare.net/pgodel Twitter: @pgodel
  153. 153. Thank you! Slides: http://slideshare.net/pgodel Twitter: @pgodel https://joind.in/12199 Feedback please!

×