Deploy like a Pro
Damián Serrano Thode
@dsthode
MalagaMakers GeekBeers (20150115)
What is deployment?
Copy source files to the server
What is deployment?
Copy source files to the server
Not just that!
What is deployment?
✔ Optimize assets
What is deployment?
✔ Optimize assets✔ Run database migrations
What is deployment?
✔ Optimize assets✔ Run database migrations
✔ Restart dependent services
What is deployment?
✔ Optimize assets✔ Run database migrations
✔ Restart dependent services
Provide rollback functionality
What is deployment?
Optimize assetsEnter Grunt → http://gruntjs.com
Optimize assets
Combine and minify javascript
Optimize assetsCombine and minify javascript
You can use grunt-contrib-uglify
Optimize assets
Preprocess, combine and minify styles
Optimize assetsPreprocess, combine and minify styles
You can use grunt-contrib-sass & grunt-contrib-cssmin
Optimize assets
Optimize and combine images
Optimize assetsOptimize and combine images
You can use grunt-spritesmith &grunt-contrib-imagemin
Optimize assets
Optimize and combine font files (SVG only)
Optimize assetsOptimize and combine font files (SVG only)
You can use the same grunt-contrib-imagemin
Database migrations,
deployment & rollback
Enter Capistrano → http://capistranorb.com
“A remote server automation and deployment tool written in Ruby.”
“Capistrano is written in Ruby, but it can easily be used to deploy any language.”
Run “cap install” on your project folder
Capfile defines requirements for your deployment tasks→
config/deploy.rb shared configuration for all the stages→
config/deploy/*.rb defines multiple stage deployment→
lib/capistrano/tasks where your custom tasks are defined→
Lots of tasks off-the-shelf that integrate with the Ruby on Rails framework
bundler, assets, migrations, Passenger, etc...
You just need to include the gems in your Gemfile and uncomment the require in the Capfile
Sample config/deploy.rb
Sample config/deploy/production.rb
Different roles available:
app, web, db
Also, you can define several servers at once, eg:
Deployment
Run 'cap <stage> deploy' on your console
Rollback
Run 'cap <stage> deploy:rollback' on your console
You can attach to any step to run custom commands using 'before' and 'after' from Capistrano DSL, eg:
Not a Rails shop?
You might need manual work creating your recipes,although there is some hope in certain cases:
capistrano-node-deploy Node.js apps→capistrano-virtualenv virtualenv python apps→
capistrano-django Django apps→capistrano-go Go apps →
Caveat emptor! Might be old, untested or unsuitable
Where to go from here?
Infrastructure management tools like Chef or Puppet for server provisioning
Continuous integration hooks for automated deployment to staging servers
Talk deployedQuestions?
Damián Serrano Thode
@dsthode
MalagaMakers GeekBeers (20150115)