160
Pablo Godel @pgodel https://joind.in/12199 Rock Solid Deployment of Symfony Applications Photo: Alvaro Videla

Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps

Embed Size (px)

DESCRIPTION

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.

Citation preview

Page 1: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Pablo Godel !@pgodel!https://joind.in/12199

Rock Solid Deployment of Symfony Applications

Photo: Alvaro Videla

Page 2: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Hi, I am Pablo.

Page 3: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Hi, I am Pablo. !

@pgodel

Page 4: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 5: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

?

Page 6: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

Software deployment is all of the activities that !make a software system available for use.

http://en.wikipedia.org/wiki/Software_deployment

Page 7: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

A very important part of the application life-cycle

Page 8: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

A very important critical part of the application life-cycle

Page 9: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

It should not be an !after thought

Page 10: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

It should be predictable

Page 11: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment

The more you do it the better it goes

Page 12: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 13: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 14: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 15: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 16: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment in the PaaS era

Page 17: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

1. Open an account

Page 18: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

2. Create app

Page 19: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

3. Push code

Page 20: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

4. Voilà!

Page 21: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 22: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

composer.json !!

Procfile

Page 23: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

$ heroku create!

Page 24: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

$ git push heroku master!

Page 25: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Page 26: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

$ heroku ps:scale web=5!

Page 27: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

That’s it! ;-)

Page 28: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Questions?

Slides: http://slideshare.net/pgodel Twitter: @pgodel

Page 29: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

But…

Page 30: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment for the rest of us

Page 31: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Goals

Page 32: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

One-click deploys

Deployment Goals

Page 33: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

One-click deploys

Deployment Goals

Page 34: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Continuous deploys

Deployment Goals

Page 35: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Continuous deploys

Deployment Goals

Page 36: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Anytime & Anywhere

Deployment Goals

Page 37: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Anytime & Anywhere

Deployment Goals

Page 38: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Anyone

Deployment Goals

Page 39: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Anyone

Deployment Goals

Page 40: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Reliable

Deployment Goals

Page 41: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Reliable

Deployment Goals

Page 42: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Rollbacks

Deployment Goals

Page 43: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Rollbacks

Deployment Goals

Page 44: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

No downtime

Deployment Goals

Page 45: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

No downtime

Deployment Goals

Page 46: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Reusable

Deployment Goals

Page 47: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Reusable

Deployment Goals

Page 48: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Reusable

Deployment Goals

Page 49: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Scalable

Deployment Goals

Page 50: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Scalable

Deployment Goals

Page 51: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Facts

Page 52: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment starts with the developer

Deployment Fact #1

Page 53: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment starts with the developer

• Development environment must be as close as possible to productions servers!

Deployment Fact #1

Page 54: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment starts with the developer

• Development environment must be as close as possible to productions servers!

• Setup test/qa/staging servers!

Deployment Fact #1

Page 55: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 56: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 57: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 58: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Success depends on server OS setup

Deployment Fact #2

Page 59: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Success depends on server OS setup

• Automate installation/configuration with Ansible/Puppet/Chef !

Deployment Fact #2

Page 60: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Automate installation/configuration with Ansible/Puppet/Chef !

• Create OS packages for 3rd party software

Deployment Fact #2

Success depends on server OS setup

Page 61: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• 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

Page 62: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Monitoring is uptime

Deployment Fact #3

Page 63: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Monitoring is uptime

• Use tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)!

Deployment Fact #3

Page 64: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Monitoring is uptime

• Use tools to know what is going on with your servers (Ganglia, Cacti, Zabbix, etc.)!

Deployment Fact #3

Page 65: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 66: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 67: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

Page 68: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style

Page 69: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads

Page 70: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads

Page 71: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads!• Rsync

Page 72: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads!• Rsync!• Source control (GIT, SVN)

Page 73: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads!• Rsync!• Source control (GIT, SVN)!• Build tools (Ant, Phing, Jenkins)!

Page 74: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads!• Rsync!• Source control (GIT, SVN)!• Build tools (Ant, Phing, Jenkins)!• Package based (RPM, DEB, …) !

Page 75: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Methodologies

• VIM-style!• FTP uploads!• Rsync!• Source control (GIT, SVN)!• Build tools (Ant, Phing, Jenkins)!• Package based (RPM, DEB, …) !• Specialized tools (Capifony, Deployer, …)!

Page 76: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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, …)

Page 77: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment: Steps overview

Page 78: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment: First time

• Copy files to server(s)!• Set server-side configurations!• Load DB fixtures!• Process and install assets!• Warm up cache!• Enable site

Page 79: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 80: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

We can automate!

Page 81: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Challenges

Page 82: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: Secure

Deployment Challenges

Page 83: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• use ssh based connections!

Challenge: Secure

Deployment Challenges

Page 84: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• use ssh based connections!• don’t store passwords on source control

Challenge: Secure

Deployment Challenges

Page 85: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• use ssh based connections!• don’t store passwords on source control!• use environment variables for sensitive data

Challenge: Secure

Deployment Challenges

Page 86: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: Static assets

Deployment Challenges

Page 87: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: Static assets

• Minimize/combine JS and CSS files!

Deployment Challenges

Page 88: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: Static assets

• Minimize/combine JS and CSS files!• Enable web server compression!

Deployment Challenges

Page 89: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 90: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 91: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 92: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: File permission conflicts

Deployment Challenges

Page 93: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: File permission conflicts

• Run Apache/PHP with same user!

Deployment Challenges

Page 94: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Challenge: File permission conflicts

• Run Apache/PHP with same user!• Use php-fpm instead of mod_php!

Deployment Challenges

Page 95: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 96: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 97: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 98: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Common Pitfalls

Page 99: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!

Common Pitfalls

Page 100: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!!

src/Acme/ClassName !!= !src/Acme/Classname.php

Common Pitfalls

Page 101: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!!

src/Acme/ClassName !!= !src/Acme/Classname.php

Common Pitfalls

Page 102: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!• Configuration differences!

Common Pitfalls

Page 103: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!• Configuration differences!• Outdated 3rd party software

Common Pitfalls

Page 104: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!• Configuration differences!• Outdated 3rd party software!• Github down

Common Pitfalls

Page 105: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• 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

Page 106: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Case sensitive filesystems!• Configuration differences!• Outdated 3rd party software!• Github down

Common Pitfalls

Page 107: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Examples

Page 108: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Simplest continuous deployment ever!

<?php !!exec(‘/usr/bin/env -i HOME=/var/www git pull’);!echo “All done!”;

hook.php

Deployment Examples

Page 109: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

<?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!

Page 110: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Capistrano!!

+ !!

Capifony

Deployment Examples

Page 111: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Capistrano / Capifony

• Ruby based!• Very extensible!• Large number of extensions!• Simple client side installation

Deployment Examples

Page 112: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

• Ruby based!• Very extensible!• Large number of extensions!• Simple client side installation

$ gem install capistrano!

Deployment Examples

Capistrano / Capifony

Page 113: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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, "[email protected]:user/repo.git" !role :web, "server.example.com", “server2.example.com”

Deployment Examples

Capistrano / Capifony

Page 114: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

$ cap deploy:setup

Deployment Examples

Capistrano / Capifony

Page 115: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

!

|-- releases!`-- shared! |-- logs! `-- uploads!

Deployment Examples

Capistrano / Capifony

Page 116: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

$ cap deploy!$ cap deploy:migrations!$ cap deploy:rollback!

Deployment Examples

Capistrano / Capifony

Page 117: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

!

|-- current (symlink to releases/20130112)!|-- releases!| `-- 20130112!`-- shared! |-- logs! `-- uploads!

Deployment Examples

Capistrano / Capifony

Page 118: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Examples

Deploying with

Page 119: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Examples!

!

Define hosts in inventory file[webservers] foo.example.com bar.example.comwww[01:50].example.com ![dbservers] one.example.com two.example.com three.example.com

Page 120: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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 service: name=httpd state=started

Page 121: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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 }

Page 122: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Examples!

!

Run process

$ ansible-playbook -i inventories/servers \ playbook.yml -v

Page 123: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Examples!

!

Run process

Page 124: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment: Other options

• Fabric (Python) • Idephix (PHP) • Magellanes (PHP) • Deployer (PHP) • Laravel / envoy (PHP) • Rocketeer (PHP)

Page 125: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Complement Tools

Page 126: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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

Page 127: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

App Metrics: StatsD & Graphite

Deployment Complement Tools

Page 128: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

App Metrics: liuggio/statsd-php-client

Deployment Complement Tools

$ composer require liuggio/statsd-php-client:dev-master

Page 129: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

App Metrics: liuggio/statsd-php-client

Deployment Complement Tools

$sender = new SocketSender(/*'localhost', 8126, 'udp'*/); !$client = new StatsdClient($sender); $factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData'); !// 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);

Page 130: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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);

Page 131: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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);

Page 132: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

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);

Page 133: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

App Metrics: StatsD & Graphite

Deployment Complement Tools

App

StatsD Graphite

Grafana

App App

Page 134: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Complement Tools

App Metrics: Grafana

Page 135: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Complement Tools

App Metrics: Grafana

Page 136: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Logging: LogstashShip 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 } }

Page 137: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Configure Apache to log jsonLogFormat "{ \"@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

Page 138: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Configure Apache to log jsonLogFormat "{ \"@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

Page 139: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Logging: KibanaKibana is a user friendly way to view, search and visualize your log data

Deployment Complement Tools

Page 140: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Logging: KibanaKibana is a user friendly way to view, search and visualize your log data

Deployment Complement Tools

Page 141: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Logging: Logstash + ElasticSearch + Kibana

Deployment Complement Tools

App / Logstash

Redis Logstash filter/processor

ElasticSearch Kibana

App / Logstash App / Logstash

Page 142: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Deployment Summary

Page 143: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 144: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 145: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 146: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 147: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 148: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 149: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 150: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 151: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 152: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 153: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Developer Tests

build artifact

Ansible Production

GitHub

Jenkins QA deploy

Integration Tests

Notifications

Deployment Summary

Page 154: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Stop using FTP

Page 155: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Plan early

Page 156: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Practice

Page 157: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Monitor

Page 158: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

AUTOMATE!

Page 159: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Now, we did finish! !

Questions?

Slides: http://slideshare.net/pgodel Twitter: @pgodel

Page 160: Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps

Thank you!

Slides: http://slideshare.net/pgodel Twitter: @pgodel

https://joind.in/12199Feedback please!