Starter project for automating deployment of a roadrunner-rails (Rails + rbenv) project in two steps:
- Automates installation of an application to an instance (local Vagrant, EC2, or any other system).
- Automates deployment of application instances to the AWS cloud environment by creating a production-ready AMI image.
- Launch a new instance
- Deploy your rails application to the instance as a puma server (automatically detects and installs proper ruby version).
- Configure application user and upstart script
- Configure CloudWatch logs agent
- Configure mechanism to pass environment variables to application via EC2 tags so the same image can be deployed to multiple environments without modification.
- Take a production-ready snapshot of the instance
- Create a new launch configuration with the newly created AMI
- Modify existing auto-scaling group to use the newly created launch configuration.
- Replace old instances in the auto-scaling group with new instances on a rolling basis (with configurable batch size).
Deploy a roadrunner application to Vagrant instance(s). Prerequisites:
- Vagrant
- Virtualbox
- Start vargrant
- SSH to "jumpbox" driving the ansible process
- Run ansible from local files (via default Vagrant
synced_folder
)
> vagrant up
> vagrant ssh ansible_host
$ ansible-playbook -i /vagrant/hosts.vagrant /vagrant/roadrunner-empty.yml -e "skip_update=true"
To verify,
- reboot an instance
- SSH into the instance
- Verify puma is running on desired port (or visit forwarded port on localhost)
$ curl localhost:3000
<!DOCTYPE html>
<html>
<head>
<title>Ruby on Rails: Welcome aboard</title>
...
...
Create an AMI image of a roadrunner application. Prerequisites:
- Ansible to drive the process;
- An AWS environment with
- Subnet
- Security group
- Keypair
- ELB
- Auto-scaling group
- Edit the
roadrunnner-empty-aws.yml
file and modify the AWS-related variables. - Run ansible
$ ansible-playbook -i localhost, roadrunner-empty-aws.yml --private-key [PATH TO YOUR KEY]
This project deploys a sample Rails application but the conventions can be used on any application:
- Configure base OS:
centos
role - Install and configure dependencies:
ruby
- Assemble application artifacts:
git
andrails-build
- Configure application:
process
- Update OS
- Install required packages
- Configure OS for production use
- Time zone,
ntpd
service - Appropriate
ulimit
, e.g., open files (sockets) - Create user accounts for sysadmins with keys
- Time zone,
- Obtain latest application, either
- Download pre-assembled from a central repository like S3
- Assemble from source by checking out and compiling
- Copy environment-specific variables
- Add
upstart
script - Install logging and monitoring agents (production)
- "Bake" AMI of newly packaged instance (from above)
- Previously provisioned
auto-scaling group
is running and behind ELB - The new
launch configuration
is applied to the existing auto-scaling group. - Instances are replaced in batches.