Coder Social home page Coder Social logo

capify-ec2's Introduction

Capify Ec2

capify-ec2 is used to generate capistrano namespaces using ec2 tags.

eg: If you have three servers on amazon's ec2.

server-1 Tag: Roles => "web", Options => "cron,resque"
server-2 Tag: Roles => "db"
server-3 Tag: Roles => "web,db"

Installing

gem install capify-ec2

In your deploy.rb:

require "capify-ec2/capistrano"
ec2_roles :web

Will generate

task :server-1 do
  role :web, {server-1 public dns fetched from Amazon}, :cron=>true, :resque=>true
end

task :server-3 do
  role :web, {server-1 public dns fetched from Amazon}
end

task :web do
  role :web, {server-1 public dns fetched from Amazon}, :cron=>true, :resque=>true
  role :web, {server-3 public dns fetched from Amazon}
end

Additionally

require "capify-ec2/capistrano"
ec2_roles :db

Will generate

task :server-2 do
  role :db, {server-2 public dns fetched from Amazon}
end

task :server-3 do
  role :db, {server-3 public dns fetched from Amazon}
end

task :db do
  role :db, {server-2 public dns fetched from Amazon}
  role :db, {server-3 public dns fetched from Amazon}
end

Running

cap web date

will run the date command on all server's tagged with the web role

Running

cap server-1 ec2:register_instance -s loadbalancer=elb-1

will register server-1 to be used by elb-1

Running

cap server-1 ec2:deregister_instance

will remove server-1 from whatever instance it is currently registered against.

Running

cap ec2:status

will list the currently running servers and their associated details (public dns, instance id, roles etc)

Running

cap ec2:ssh #

will launch ssh using the user and port specified in your configuration. The # argument is the index of the server to ssh into. Use the 'ec2:status' command to see the list of servers with their indices.

More options

In addition to specifying options (e.g. 'cron') at the server level, it is also possible to specify it at the project level. Use with caution! This does not work with autoscaling.

ec2_roles {:name=>"web", :options=>{:cron=>"server-1"}}

Will generate

task :server-1 do
  role :web, {server-1 public dns fetched from Amazon}, :cron=>true
end

task :server-3 do
  role :web, {server-1 public dns fetched from Amazon}
end

task :web do
  role :web, {server-1 public dns fetched from Amazon}, :cron=>true
  role :web, {server-3 public dns fetched from Amazon}
end

Which is cool if you want a task like this in deploy.rb

task :update_cron => :web, :only=>{:cron} do
  Do something to a server with cron on it
end

ec2_roles :name=>:web, :options=>{ :default => true }

Will make :web the default role so you can just type 'cap deploy'. Multiple roles can be defaults so:

ec2_roles :name=>:web, :options=>{ :default => true }
ec2_roles :name=>:app, :options=>{ :default => true }

would be the equivalent of 'cap app web deploy'

Ec2 config

This gem requires 'config/ec2.yml' in your project. The yml file needs to look something like this:

:aws_access_key_id: "YOUR ACCESS KEY"
:aws_secret_access_key: "YOUR SECRET"
:aws_params:
  :region: 'eu-west-1'
:load_balanced: true
:project_tag: "YOUR APP NAME"

aws_access_key_id, aws_secret_access_key, and region are required. Other settings are optional.

If :load_balanced is set to true, the gem uses pre and post-deploy hooks to deregister the instance, reregister it, and validate its health. :load_balanced only works for individual instances, not for roles.

The :project_tag parameter is optional. It will limit any commands to running against those instances with a "Project" tag set to the value "YOUR APP NAME".

Development

Source hosted at GitHub. Report Issues/Feature requests on GitHub Issues.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2012 Forward. See LICENSE for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.