Skip to content

Instantly share code, notes, and snippets.

@xntrik
Last active December 20, 2015 13:09
Show Gist options
  • Save xntrik/6136703 to your computer and use it in GitHub Desktop.
Save xntrik/6136703 to your computer and use it in GitHub Desktop.
Deploying Rails to EC2
http://railscasts.com/episodes/347-rubber-and-amazon-ec2?view=asciicast
https://github.com/rubber/rubber/wiki/Commands
cap rubber:create #creates instances - but - sometimes, depending on the AMI, and the *mood* of the EC2 gods, you can't establish that initial SSH session ..
Eventually though, they should be setup.
Good trick, if, you can start the instance creation, but, it times out. You can kill that process, and restart the instance a few times until you can SSH to it standalone.
THEN, just hit it with a:
cap rubber:refresh
For new instances, you have to install all the deps, so you need to give it:
cap rubber:bootstrap #This takes a while - as it builds Ruby from scratch, and a few other bits and bobs.
Finally, to push the code up:
cap deploy #This is native capistrano logic at this point.
Now, for some tricky stuff - say you don't want to use their haproxy but ELB instead.. when you create an instance, only give it the app,db roles. Apache will be configured to listen on port 7000/7001.
You need to then start constructing an ELB. Once it's done, it'll give you a a security group. You need to ensure that the 'app' servers are accessible to 7000/7001 from that security group.
By default, rubber publishes on HTTP a /httpchk.txt - this can be used for the heartbeat check in the ELB.
I've found if the ELB doens't pick up the instance, you need to remove and add it - especially if you just changed the security groups
If you need to stop instances and start them, you pretty much need to go through the
cap rubber:refresh (if cap rubber:start doesn't work)
cap rubber:bootstrap (will be faster this time)
cap deploy
If you want to add a new instance, use the rubber:create - but - as soon as the instance has started creation at EC2 - kill the process. Wait until you can view it's log in the EC2 console and can SSH to the instance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment