Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoscaling on EC2 with Rails & Capistrano Deployments

Is there a common strategy for setting up scripts on autoscaling to update the code in a capistrano deploy hierarchy to pull from your repository when the AMI is launched on an autoscaling event to ensure the commit running on the autoscaling machine matches the commit on non-autoscaling instances?

like image 584
Jeremy Gailor Avatar asked Nov 09 '12 07:11

Jeremy Gailor


People also ask

Does EC2 have Auto Scaling?

Amazon EC2 Auto Scaling helps you maintain application availability and allows you to automatically add or remove EC2 instances according to conditions you define. You can use the fleet management features of EC2 Auto Scaling to maintain the health and availability of your fleet.

Is EC2 Auto Scaling free?

Pricing for Amazon EC2 Auto ScalingThere are no additional fees with Amazon EC2 Auto Scaling, so it's easy to try it out and see how it can benefit your AWS architecture. You only pay for the AWS resources (for example, EC2 instances, EBS volumes, and CloudWatch alarms) that you use.

Can Auto Scaling work without load balancer?

Yes, you can use Auto Scaling without Elastic Load Balancing. However, it means that you don't have a common entry point, so it isn't ideal if you will be, say, hosting a website.


Video Answer


2 Answers

I run a setup a bit like this. I chose not to set instances to interact with git when they're booted because:

  • I want instances to come up fast (deploy + bundle install can take a while)
  • I want scaling up/replacing an instance to not depend on GitHub, rubygems etc
  • I want scaling up an instance to be really simple

What I do is that the app I deploy is at /var/www/myapp. This is actually a separate EBS volume, mounted at that location. The filesystem is xfs because you can use xfs_freeze to safely take ebs snapshots of a mounted volume

When the deploy is done, in a capistrano after hook I snapshot the /var/www/myapp volume. I then update the block device mapping of the autoscaling launch configuration to say "when you start an instance, create a new volume from the snapshot and attach it to /dev/sdf.

All the instance has to do on startup is mount that device at /var/www/myapp, either by editing /etc/fstab or by running a super simple boot time script. Bundler is set to save its gems in /var/www/myapp/shared so the gems are taken care of too

like image 145
Frederick Cheung Avatar answered Oct 17 '22 00:10

Frederick Cheung


Just in case anyone falls here, I've just discovered this gem:

https://github.com/lserman/capistrano-elbas

which will (as stated in the Readme):

  • Deploy your code to each running instance connected to a given AutoScale group
  • After deployment, create an AMI from one of the running instances
  • Attach the AMI with the new code to a new AWS Launch Configuration
  • Update your AutoScale group to use the new launch configuration
  • Delete any old AMIs created by ELBAS
  • Delete any old launch configurations created by ELBAS

So it ensures all instances of the autoscaling group (those running and those future) will run the same code.

Hope this helps

like image 34
sonxurxo Avatar answered Oct 16 '22 23:10

sonxurxo