continuous deployment of rails apps on aws opsworks
DESCRIPTION
A short overview of how Codeable team uses OpsWorks to host their applicationTRANSCRIPT
![Page 1: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/1.jpg)
Continuous deployment of Rails apps on AWS OpsWorks
Slovenia Ruby User group meetup Monday, June 23rd, 2014
![Page 2: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/2.jpg)
Text
$ whoamiTomaž Zaman, founder of Codeable, @TomazZaman, http://zaman.ioGeek, father of four, skydiver
![Page 3: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/3.jpg)
SCRUM FTW!
Sprints (14 days)
Dailys (15 min each day)
User stories (1:1:1)
Only way to do CI!
![Page 4: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/4.jpg)
Git workflowMaster -> Staging
Master -> Feature
Feature -> Staging
Feature -> Master (pull request, once feature done)
Master always deployable!
![Page 5: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/5.jpg)
Gemnasium
One simple task: Report outdated gems
via email
![Page 6: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/6.jpg)
CodeClimateAutomated code review
HipChat + Emails
Foreman (Uncle Bob, cleancoders.com)
SOLID + other principles
recommendations on refactoring
![Page 7: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/7.jpg)
Travis CI.travis.yml - Instructions how to build a testing instance, how to run tests, matrices,…
HipChat webhook
Email web hook
Deploys to staging env.
pings CodeClimate
A bit expensive
![Page 8: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/8.jpg)
Text
AWS OpsWorksMakin’ it easy to deploy stuff
![Page 9: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/9.jpg)
How it compares to Heroku
A bit more work to get started
more moving parts you’re responsible for
similar pricing
Much more control (with great power comes great responsibility, Peter)
More complex CLI
Same integration with other services
Documentation is overly complex, lacking examples
Having all services under the same roof can be good or bad
Doesn’t enforce 12 factors, but not hard to follow them on your own
Primary elements:
![Page 10: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/10.jpg)
Text
StacksA primary entity in OpsWorks, holding all other like Layers, Apps
![Page 11: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/11.jpg)
Text
LayersLayer is a “box” for ordinary EC2 instances that perform the same role, such as host Rails apps.
![Page 12: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/12.jpg)
Text
AppsRepresent an individual app which is also a repo on GitHub
![Page 13: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/13.jpg)
ChefYour worst nightmare.But it’s awesome!
Written in Ruby, it’s an “automation platform”
![Page 14: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/14.jpg)
Deployments (how they work)
A set of instructions to be ran on CLI or Webhook call
All application instances pull application from GitHub
Chef takes over to call deployment hooks (even custom ones)
Unicorn forks without downtime
If any step of the deployment goes wrong, the old app keeps being served (again, no downtime!)
deploy/before_restart.rb & co.
![Page 15: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/15.jpg)
Other AWS toolsAmazon RDS
ElastiCache
Route 53
Virtual Cloud
Elastic IPs
Elastic Load Balancers (with health checking)
S3
![Page 16: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/16.jpg)
Text
LoggingNeed to use external service such as Loggly, Papertrail, so logs need to go into Syslog (not 100% mandatory, but easier)
![Page 17: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/17.jpg)
AsyncMany possibilities to solve this
OpsWorks doesn’t have a dedicated Worker layer
Possibility: Custom Chef recipe
Solution: Rake tasks + deployment hook
bundle exec rake sidekiq:start
![Page 18: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/18.jpg)
ConfigurationCan be tricky, many possible approaches
Hook into Stack JSON and create a YML file on deployment, via deployment hook (tutorial: http://zaman.io)
![Page 19: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/19.jpg)
Recapmerge into staging triggers Travis and Gemnasium
Travis runs tests, reports green or red
Travis reports to HipChat, CodeClimate
Manually run deployment rake task which initiates deployment via CLI
OpsWorks pulls latest master on servers in the layer that app is being deployed to
If no errors, Unicorn forks itself and runs rake tasks that restart async (Sidekiq) workers
Everything visible on Papertrail
![Page 20: Continuous deployment of Rails apps on AWS OpsWorks](https://reader038.vdocuments.site/reader038/viewer/2022102804/53f909c18d7f7253318b49fd/html5/thumbnails/20.jpg)
Questions?