项目作者: fernandocarletti

项目描述 :
Integrates Capistrano with AWS EC2.
高级语言: Ruby
项目地址: git://github.com/fernandocarletti/capistrano-aws.git
创建时间: 2017-05-05T05:32:38Z
项目社区:https://github.com/fernandocarletti/capistrano-aws

开源协议:MIT License

下载


Capistrano AWS Gem Version

This gem is slightly based on cap-ec2, which is not maintained for a while, becoming outdated.

The purpose of this gem is to provide a flexible and simple integration to AWS EC2, exposing the aws-sdk connection in order to allow any customization.

Requirements

  • Capistrano 3

Installation

Add to your Gemfile and run bundler:

  1. gem 'capistrano-aws'

Or install the gem system-wide:

  1. gem install capistrano-aws

In your Capfile:

  1. require 'capistrano/aws'

Configuration

  1. # AWS regions to use.
  2. set :aws_ec2_regions, ['us-east-1']
  3. # Application name to match application tag.
  4. set :aws_ec2_application, (proc { fetch(:application) })
  5. # Stage to match stage tag.
  6. set :aws_ec2_stage, (proc { fetch(:stage) })
  7. # Tag to be used for Capistrano stage.
  8. set :aws_ec2_stage_tag, 'Stage'
  9. # Tag to be used to match the application.
  10. set :aws_ec2_application_tag, 'Application'
  11. # Tag to be used for Capistrano roles of the server (the tag value can be a comma separated list).
  12. set :aws_ec2_roles_tag, 'Roles'
  13. # Extra filters to be used to retrieve the instances. See the README.md for more information.
  14. set :aws_ec2_extra_filters, []
  15. # Tag to be used as the instance name in the instances table (aws:ec2:instances task).
  16. set :aws_ec2_name_tag, 'Name'
  17. # How to contact the instance (:public_ip, :public_dns, :private_ip, :private_dns, :id, :ipv_6_address).
  18. set :aws_ec2_contact_point, :public_ip

The AWS credentials are loaded from your system. Check https://github.com/aws/aws-sdk-ruby#configuration for more information.

Usage

The instances must be registered in each stage. In your config/deploy/<stage_name>.rb, add the following line:

This must be placed after you have configured your AWS settings

  1. aws_ec2_register

It will use the instance tags to call the server function in capistrano. You can pass a hash as an argument, and it will be merged into the function call:

  1. aws_ec2_register user: 'hello', port: 2222

Custom EC2 Filters

If you need to identify the instances based on more information, you can specify extra filters to be used in the filters option in the Aws::EC2::Resource.instances call.

Imagine you have some split test servers for your production environment, so you can use another tag for specifying the variation of some servers:

Name Application Environment Roles SplitTestVariation
foo-app01 foo-app production app,db 0
foo-app02 foo-app production app 0
foo-app03 foo-app production app 1
foo-app04 foo-app production app 1

In your environment files:

  1. # production.rb
  2. set :aws_ec2_extra_filters, [
  3. {
  4. name: "tag:SplitTestVariation",
  5. values: ["0"],
  6. },
  7. ]
  1. # production-b.rb
  2. set :aws_ec2_stage, "production" # Optional. Use if you have the same environment for the B servers.
  3. set :aws_ec2_extra_filters, [
  4. {
  5. name: "tag:SplitTestVariation",
  6. values: ["1"],
  7. },
  8. ]

The :aws_ec2_stage variable is needed in order to override the default value of the stage fielter(:stage). If you really have a different environment for your B servers, you can just use the name of the environment as the file name and remove this line.

Utility tasks

aws:ec2:instances

List all the instances found for with the current configuration.

  1. cap production aws:ec2:instances

Contributing

Open an issue or make a PR, feel free to contribute!