tsudura 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/Guardfile +30 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/exe/tsudura +5 -0
- data/lib/tsudura/aws/ami.rb +54 -0
- data/lib/tsudura/aws/auto_scale.rb +23 -0
- data/lib/tsudura/aws/launch_config.rb +42 -0
- data/lib/tsudura/aws/launch_instance.rb +59 -0
- data/lib/tsudura/aws/utils.rb +7 -0
- data/lib/tsudura/cli.rb +9 -0
- data/lib/tsudura/config_parser.rb +12 -0
- data/lib/tsudura/env_prefix.rb +18 -0
- data/lib/tsudura/normal_runner.rb +19 -0
- data/lib/tsudura/packer_plus_runner.rb +18 -0
- data/lib/tsudura/provisioner/ansible.rb +48 -0
- data/lib/tsudura/runner.rb +11 -0
- data/lib/tsudura/runner_module.rb +47 -0
- data/lib/tsudura/version.rb +3 -0
- data/lib/tsudura.rb +24 -0
- data/tsudura.gemspec +41 -0
- metadata +214 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 454145fa9c659a5e7a32d21490baea4945325605
         | 
| 4 | 
            +
              data.tar.gz: 6dc9088693f930d1de1caeeab5e991433dd0af1e
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 67440826f71c227b3234314a647225869475e70e9d040c7aaca717e3f19df10b1468ed4dba0a7b78b4d67243d680e4ce36ee0b35caa400b6ee85d4c08deccc30
         | 
| 7 | 
            +
              data.tar.gz: 0125a58832b60877e1d11332c6db6947a37bace5ebbf9af631eabaf1a656d648653b66654ea555df58525f86cb521a49540d6cb6d83398ae187c28ba91e316b5
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Guardfile
    ADDED
    
    | @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            ## Uncomment and set this to only include directories you want to watch
         | 
| 2 | 
            +
            # directories %w(app lib config test spec features)
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## Uncomment to clear the screen before every task
         | 
| 5 | 
            +
            # clearing :on
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # Note: The cmd option is now required due to the increasing number of ways
         | 
| 8 | 
            +
            #       rspec may be run, below are examples of the most common uses.
         | 
| 9 | 
            +
            #  * bundler: 'bundle exec rspec'
         | 
| 10 | 
            +
            #  * bundler binstubs: 'bin/rspec'
         | 
| 11 | 
            +
            #  * spring: 'bin/rspec' (This will use spring if running and you have
         | 
| 12 | 
            +
            #                          installed the spring binstubs per the docs)
         | 
| 13 | 
            +
            #  * zeus: 'zeus rspec' (requires the server to be started separately)
         | 
| 14 | 
            +
            #  * 'just' rspec: 'rspec'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            guard :rspec, cmd: "bundle exec rspec" do
         | 
| 17 | 
            +
              require "guard/rspec/dsl"
         | 
| 18 | 
            +
              dsl = Guard::RSpec::Dsl.new(self)
         | 
| 19 | 
            +
             | 
| 20 | 
            +
             | 
| 21 | 
            +
              # RSpec files
         | 
| 22 | 
            +
              rspec = dsl.rspec
         | 
| 23 | 
            +
              watch(rspec.spec_helper) { rspec.spec_dir }
         | 
| 24 | 
            +
              watch(rspec.spec_support) { rspec.spec_dir }
         | 
| 25 | 
            +
              watch(rspec.spec_files)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              # Ruby files
         | 
| 28 | 
            +
              ruby = dsl.ruby
         | 
| 29 | 
            +
              dsl.watch_spec_files_for(ruby.lib_files)
         | 
| 30 | 
            +
            end
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2015 onigra
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,33 @@ | |
| 1 | 
            +
            [](https://travis-ci.org/onigra/tsudura)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # WARNING
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            This gem is alpha version.
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            # Tsudura
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tsudura`. To experiment with that code, run `bin/console` for an interactive prompt.
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ## Installation
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            install it yourself as:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                $ gem install tsudura
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            ## Usage
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            TODO: Write usage instructions here
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## Development
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec tsudura` to use the code located in this directory, ignoring other installed copies of this gem.
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## Contributing
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            1. Fork it ( https://github.com/[my-github-username]/tsudura/fork )
         | 
| 30 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 31 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 32 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 33 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require "bundler/gem_tasks"
         | 
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "tsudura"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 7 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 10 | 
            +
            # require "pry"
         | 
| 11 | 
            +
            # Pry.start
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require "irb"
         | 
| 14 | 
            +
            IRB.start
         | 
    
        data/bin/setup
    ADDED
    
    
    
        data/exe/tsudura
    ADDED
    
    
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            module Tsudura::Aws
         | 
| 2 | 
            +
              class Ami
         | 
| 3 | 
            +
                include Tsudura::Aws::Utils
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
                def initialize(instance_id, config, timestamp)
         | 
| 6 | 
            +
                  @instance_id = instance_id
         | 
| 7 | 
            +
                  @config = config
         | 
| 8 | 
            +
                  @timestamp = timestamp
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
                def create
         | 
| 12 | 
            +
                  @new_image_id = create_ami
         | 
| 13 | 
            +
                  waiting_for_available @new_image_id
         | 
| 14 | 
            +
                  @new_image_id
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
                 
         | 
| 17 | 
            +
                def deregister
         | 
| 18 | 
            +
                  ec2.deregister_image(image_id: get_old_image(describe_service_images))
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def describe_service_images 
         | 
| 22 | 
            +
                  ec2.describe_images(owners: ["#{@config[:owner]}"], filters: [ { name: "name", values: ["#{@config[:service]}-#{short_env}*"] }])
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def get_old_image(images)
         | 
| 26 | 
            +
                  old_image_id = nil
         | 
| 27 | 
            +
                  images.each_page { |i| old_image_id = i.images.map(&:image_id).reject { |id| id == @new_image_id }.first }
         | 
| 28 | 
            +
                  old_image_id
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
              
         | 
| 31 | 
            +
                private
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def create_ami
         | 
| 34 | 
            +
                  result = ec2.create_image(name: "#{@config[:service]}-#{short_env}-#{@timestamp}", instance_id: @instance_id)
         | 
| 35 | 
            +
                  result[:image_id]
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
                #
         | 
| 39 | 
            +
                # stateがavailableになるまで待ち
         | 
| 40 | 
            +
                #
         | 
| 41 | 
            +
                def waiting_for_available(new_image_id)
         | 
| 42 | 
            +
                  status = nil
         | 
| 43 | 
            +
              
         | 
| 44 | 
            +
                  while (status.nil? || status == 'pending')
         | 
| 45 | 
            +
                    sleep 10
         | 
| 46 | 
            +
                    status = ec2.describe_images(image_ids: [new_image_id])[:images].first.state
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def ec2
         | 
| 51 | 
            +
                  @ec2 ||= ::Aws::EC2::Client.new(region: @config[:region])
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
| @@ -0,0 +1,23 @@ | |
| 1 | 
            +
            module Tsudura::Aws
         | 
| 2 | 
            +
              class AutoScale
         | 
| 3 | 
            +
                include Tsudura::Aws::Utils
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(config, timestamp)
         | 
| 6 | 
            +
                  @config = config
         | 
| 7 | 
            +
                  @timestamp = timestamp
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
              
         | 
| 10 | 
            +
                def update
         | 
| 11 | 
            +
                  autoscaling.update_auto_scaling_group(
         | 
| 12 | 
            +
                    auto_scaling_group_name: "#{@config[:service]}-#{short_env}-group",
         | 
| 13 | 
            +
                    launch_configuration_name: "#{@config[:service]}-#{short_env}-#{@timestamp}",
         | 
| 14 | 
            +
                  )
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                private
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def autoscaling
         | 
| 20 | 
            +
                  @autoscaling ||= ::Aws::AutoScaling::Client.new(region: 'ap-northeast-1')
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| @@ -0,0 +1,42 @@ | |
| 1 | 
            +
            module Tsudura::Aws
         | 
| 2 | 
            +
              class LaunchConfig
         | 
| 3 | 
            +
                include Tsudura::Aws::Utils
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
                def initialize(image_id, config, timestamp)
         | 
| 6 | 
            +
                  @image_id = image_id
         | 
| 7 | 
            +
                  @config = config
         | 
| 8 | 
            +
                  @timestamp = timestamp
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
                def create
         | 
| 12 | 
            +
                  @new_launch_config = autoscaling.create_launch_configuration(
         | 
| 13 | 
            +
                    image_id: @image_id,
         | 
| 14 | 
            +
                    key_name: @config[:key_name],
         | 
| 15 | 
            +
                    user_data: Base64.encode64(@config[:user_data_script]),
         | 
| 16 | 
            +
                    instance_type: @config[:instance_type],
         | 
| 17 | 
            +
                    security_groups: [@config[:security_group_id]],
         | 
| 18 | 
            +
                    launch_configuration_name: "#{@config[:service]}-#{short_env}-#{@timestamp}",
         | 
| 19 | 
            +
                  )
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                def delete
         | 
| 23 | 
            +
                  autoscaling.delete_launch_configuration(launch_configuration_name: old_launch_config_name)
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
              
         | 
| 26 | 
            +
                def old_launch_config_name
         | 
| 27 | 
            +
                  tmp = []
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  autoscaling.describe_launch_configurations.each_page do |i|
         | 
| 30 | 
            +
                    tmp << i.launch_configurations.select { |item| item.launch_configuration_name =~ /#{@config[:service]}-#{short_env}/ }
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
              
         | 
| 33 | 
            +
                  tmp.flatten.reject { |obj| obj.launch_configuration_name == @new_launch_config }.map(&:launch_configuration_name).first
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
              
         | 
| 36 | 
            +
                private
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
                def autoscaling
         | 
| 39 | 
            +
                  @autoscaling ||= ::Aws::AutoScaling::Client.new(region: @config[:region])
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
              end
         | 
| 42 | 
            +
            end
         | 
| @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            module Tsudura::Aws
         | 
| 2 | 
            +
              class LaunchInstance
         | 
| 3 | 
            +
              
         | 
| 4 | 
            +
                def initialize(config)
         | 
| 5 | 
            +
                  @config = config
         | 
| 6 | 
            +
                end
         | 
| 7 | 
            +
              
         | 
| 8 | 
            +
                def launch
         | 
| 9 | 
            +
                  instance_result = launch_ec2
         | 
| 10 | 
            +
                  instance = instance_result[:instances].first
         | 
| 11 | 
            +
                  waiting_for_launch instance
         | 
| 12 | 
            +
                  ec2.create_tags(resources: [instance.instance_id], tags: [ { key: 'Name', value: "#{@config[:service]}-ami"}])
         | 
| 13 | 
            +
                  @launched_instance_id = instance.instance_id
         | 
| 14 | 
            +
                  @launched_instance_id
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
                def terminate
         | 
| 18 | 
            +
                  ec2.terminate_instances(instance_ids: [@launched_instance_id])
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
                private
         | 
| 22 | 
            +
              
         | 
| 23 | 
            +
                #
         | 
| 24 | 
            +
                # statusがreadyになるまで待ち
         | 
| 25 | 
            +
                #
         | 
| 26 | 
            +
                def waiting_for_launch(instance)
         | 
| 27 | 
            +
                  status = nil
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
                  while (status.nil? || status == 'initializing')
         | 
| 30 | 
            +
                    sleep 10
         | 
| 31 | 
            +
              
         | 
| 32 | 
            +
                    statuses = ec2.describe_instance_status(instance_ids: [instance.instance_id])
         | 
| 33 | 
            +
                    if statuses[:instance_statuses] == []
         | 
| 34 | 
            +
                      #  早過ぎると、ステータス取得すらできない
         | 
| 35 | 
            +
                      next
         | 
| 36 | 
            +
                    end
         | 
| 37 | 
            +
              
         | 
| 38 | 
            +
                    status = statuses[:instance_statuses].first[:system_status].status
         | 
| 39 | 
            +
                    puts status
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              
         | 
| 43 | 
            +
                def launch_ec2
         | 
| 44 | 
            +
                  ec2.run_instances(
         | 
| 45 | 
            +
                    min_count: 1,
         | 
| 46 | 
            +
                    max_count: 1,
         | 
| 47 | 
            +
                    key_name: @config[:key_name],
         | 
| 48 | 
            +
                    image_id: @config[:image_id],
         | 
| 49 | 
            +
                    subnet_id: @config[:subnet_id],
         | 
| 50 | 
            +
                    instance_type: @config[:instance_type],
         | 
| 51 | 
            +
                    security_group_ids: [@config[:security_group_id]],
         | 
| 52 | 
            +
                  )
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                def ec2
         | 
| 56 | 
            +
                  @ec2 ||= ::Aws::EC2::Client.new(region: @config[:region])
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
    
        data/lib/tsudura/cli.rb
    ADDED
    
    
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Tsudura
         | 
| 2 | 
            +
              class NormalRunner
         | 
| 3 | 
            +
                include Tsudura::RunnerModule
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(config)
         | 
| 6 | 
            +
                  @config = config
         | 
| 7 | 
            +
                  @timestamp = Time.now.strftime('%Y%m%d%H%M%S')
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def run
         | 
| 11 | 
            +
                  instance_id = launch_instance
         | 
| 12 | 
            +
                  provision
         | 
| 13 | 
            +
                  new_image_id = create_ami(instance_id)
         | 
| 14 | 
            +
                  create_launch_config(new_image_id)
         | 
| 15 | 
            +
                  update_auto_scaling_group
         | 
| 16 | 
            +
                  destroy_temp_objects
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,18 @@ | |
| 1 | 
            +
            module Tsudura
         | 
| 2 | 
            +
              class PackerPlusRunner
         | 
| 3 | 
            +
                include Tsudura::RunnerModule
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(config)
         | 
| 6 | 
            +
                  @config = config
         | 
| 7 | 
            +
                  @timestamp = Time.now.strftime('%Y%m%d%H%M%S')
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def run
         | 
| 11 | 
            +
                  instance_id = launch_instance
         | 
| 12 | 
            +
                  provision
         | 
| 13 | 
            +
                  new_image_id = create_ami(instance_id)
         | 
| 14 | 
            +
                  create_launch_config(new_image_id)
         | 
| 15 | 
            +
                  terminate_tmp_ec2_instance
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
            end
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            module Tsudura::Provisioner
         | 
| 2 | 
            +
              class Ansible
         | 
| 3 | 
            +
                def initialize(config)
         | 
| 4 | 
            +
                  @config = config
         | 
| 5 | 
            +
                end
         | 
| 6 | 
            +
              
         | 
| 7 | 
            +
                def provision!
         | 
| 8 | 
            +
                  command = base_command
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  if use_vault_option?
         | 
| 11 | 
            +
                    command << add_vault_option
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  Open3.popen3 command do |i, o, e, w|
         | 
| 15 | 
            +
                    o.each do |line| puts line end
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                ensure
         | 
| 18 | 
            +
                  remove_vault_password_file if use_vault_option?
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                private
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def base_command
         | 
| 24 | 
            +
                  "ansible-playbook #{@config[:playbook_path]} -i #{@config[:inventory_file]}"
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                def use_vault_option?
         | 
| 28 | 
            +
                  @config[:vault_password] ? true : false
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                def add_vault_option
         | 
| 32 | 
            +
                  create_vault_password_file
         | 
| 33 | 
            +
                  vault_option
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                def vault_option
         | 
| 37 | 
            +
                  " --vault-password-file tmp_password_file"
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def create_vault_password_file
         | 
| 41 | 
            +
                  File.open("tmp_password_file", "w") { |f| f.puts @config[:vault_password] }
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def remove_vault_password_file
         | 
| 45 | 
            +
                  FileUtils.rm "tmp_password_file"
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            module Tsudura
         | 
| 2 | 
            +
              class Runner
         | 
| 3 | 
            +
                def self.run(config)
         | 
| 4 | 
            +
                  if config.has_key?(:mode)
         | 
| 5 | 
            +
                    Object.const_get("Tsudura").const_get("#{config[:mode].split("_").map(&:capitalize).join}Runner").new(config).run
         | 
| 6 | 
            +
                  else
         | 
| 7 | 
            +
                    Tsudura::NormalRunner.new(config).run
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| @@ -0,0 +1,47 @@ | |
| 1 | 
            +
            module Tsudura
         | 
| 2 | 
            +
              module RunnerModule
         | 
| 3 | 
            +
             | 
| 4 | 
            +
                private
         | 
| 5 | 
            +
              
         | 
| 6 | 
            +
                def launch_instance
         | 
| 7 | 
            +
                  @ec2 = Aws::LaunchInstance.new(@config)
         | 
| 8 | 
            +
                  @ec2.launch
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              
         | 
| 11 | 
            +
                def provision
         | 
| 12 | 
            +
                  Provisioner::Ansible.new(@config).provision!
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
                def create_ami(instance_id)
         | 
| 16 | 
            +
                  @ami = Aws::Ami.new(instance_id, @config, @timestamp)
         | 
| 17 | 
            +
                  @ami.create
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              
         | 
| 20 | 
            +
                def create_launch_config(new_image_id)
         | 
| 21 | 
            +
                  @launch_config = Aws::LaunchConfig.new(new_image_id, @config, @timestamp)
         | 
| 22 | 
            +
                  @launch_config.create
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
                
         | 
| 25 | 
            +
                def update_auto_scaling_group
         | 
| 26 | 
            +
                  Aws::AutoScale.new(@config, @timestamp).update
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              
         | 
| 29 | 
            +
                def destroy_temp_objects
         | 
| 30 | 
            +
                  @ec2.terminate
         | 
| 31 | 
            +
                  @ami.deregister
         | 
| 32 | 
            +
                  @launch_config.delete
         | 
| 33 | 
            +
                end
         | 
| 34 | 
            +
                
         | 
| 35 | 
            +
                def terminate_tmp_ec2_instance
         | 
| 36 | 
            +
                  @ec2.terminate
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                def deregister_old_ami
         | 
| 40 | 
            +
                  @ami.deregister
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
                
         | 
| 43 | 
            +
                def delete_old_launch_config
         | 
| 44 | 
            +
                  @launch_config.delete
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
              end
         | 
| 47 | 
            +
            end
         | 
    
        data/lib/tsudura.rb
    ADDED
    
    | @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            require "thor"
         | 
| 2 | 
            +
            require "aws-sdk"
         | 
| 3 | 
            +
            require 'base64'
         | 
| 4 | 
            +
            require "yaml"
         | 
| 5 | 
            +
            require 'date'
         | 
| 6 | 
            +
            require "fileutils"
         | 
| 7 | 
            +
            require "open3"
         | 
| 8 | 
            +
            require "deep_hash_transform"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            require "tsudura/config_parser"
         | 
| 11 | 
            +
            require "tsudura/env_prefix"
         | 
| 12 | 
            +
            require "tsudura/runner_module"
         | 
| 13 | 
            +
            require "tsudura/normal_runner"
         | 
| 14 | 
            +
            require "tsudura/packer_plus_runner"
         | 
| 15 | 
            +
            require "tsudura/runner"
         | 
| 16 | 
            +
            require "tsudura/cli"
         | 
| 17 | 
            +
            require "tsudura/version"
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            require "tsudura/aws/utils"
         | 
| 20 | 
            +
            require "tsudura/aws/ami"
         | 
| 21 | 
            +
            require "tsudura/aws/auto_scale"
         | 
| 22 | 
            +
            require "tsudura/aws/launch_config"
         | 
| 23 | 
            +
            require "tsudura/aws/launch_instance"
         | 
| 24 | 
            +
            require "tsudura/provisioner/ansible"
         | 
    
        data/tsudura.gemspec
    ADDED
    
    | @@ -0,0 +1,41 @@ | |
| 1 | 
            +
            # coding: utf-8
         | 
| 2 | 
            +
            lib = File.expand_path('../lib', __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require 'tsudura/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "tsudura"
         | 
| 8 | 
            +
              spec.version       = Tsudura::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["onigra"]
         | 
| 10 | 
            +
              spec.email         = ["3280467rec@gmail.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = %q{Update ami and launch_config and auto scaling group like packer.}
         | 
| 13 | 
            +
              spec.description   = %q{Command line tool of create new ami and update auto scaling group and delete old ami and launch config.}
         | 
| 14 | 
            +
              spec.homepage      = "https://github.com/onigra/tsudura"
         | 
| 15 | 
            +
              spec.license       = "MIT"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
         | 
| 18 | 
            +
              # delete this section to allow pushing this gem to any host.
         | 
| 19 | 
            +
              if spec.respond_to?(:metadata)
         | 
| 20 | 
            +
                spec.metadata['allowed_push_host'] = "https://rubygems.org"
         | 
| 21 | 
            +
              else
         | 
| 22 | 
            +
                raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              spec.files         = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 26 | 
            +
              spec.bindir        = "exe"
         | 
| 27 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 28 | 
            +
              spec.require_paths = ["lib"]
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              spec.add_development_dependency "bundler", "~> 1.9"
         | 
| 31 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 32 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 33 | 
            +
              spec.add_development_dependency "guard"
         | 
| 34 | 
            +
              spec.add_development_dependency "guard-rspec"
         | 
| 35 | 
            +
              spec.add_development_dependency "growl"
         | 
| 36 | 
            +
              spec.add_development_dependency "awesome_print"
         | 
| 37 | 
            +
             | 
| 38 | 
            +
              spec.add_dependency "thor"
         | 
| 39 | 
            +
              spec.add_dependency "aws-sdk", '~> 2'
         | 
| 40 | 
            +
              spec.add_dependency "deep_hash_transform"
         | 
| 41 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,214 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: tsudura
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - onigra
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2015-06-05 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: bundler
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '1.9'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.9'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 43 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 | 
            +
                requirements:
         | 
| 45 | 
            +
                - - ">="
         | 
| 46 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 47 | 
            +
                    version: '0'
         | 
| 48 | 
            +
              type: :development
         | 
| 49 | 
            +
              prerelease: false
         | 
| 50 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 | 
            +
                requirements:
         | 
| 52 | 
            +
                - - ">="
         | 
| 53 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            +
                    version: '0'
         | 
| 55 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 56 | 
            +
              name: guard
         | 
| 57 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 58 | 
            +
                requirements:
         | 
| 59 | 
            +
                - - ">="
         | 
| 60 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 61 | 
            +
                    version: '0'
         | 
| 62 | 
            +
              type: :development
         | 
| 63 | 
            +
              prerelease: false
         | 
| 64 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
                requirements:
         | 
| 66 | 
            +
                - - ">="
         | 
| 67 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                    version: '0'
         | 
| 69 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 70 | 
            +
              name: guard-rspec
         | 
| 71 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 72 | 
            +
                requirements:
         | 
| 73 | 
            +
                - - ">="
         | 
| 74 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 75 | 
            +
                    version: '0'
         | 
| 76 | 
            +
              type: :development
         | 
| 77 | 
            +
              prerelease: false
         | 
| 78 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 79 | 
            +
                requirements:
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: '0'
         | 
| 83 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 84 | 
            +
              name: growl
         | 
| 85 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - ">="
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '0'
         | 
| 90 | 
            +
              type: :development
         | 
| 91 | 
            +
              prerelease: false
         | 
| 92 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 93 | 
            +
                requirements:
         | 
| 94 | 
            +
                - - ">="
         | 
| 95 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 96 | 
            +
                    version: '0'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: awesome_print
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :development
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 111 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 112 | 
            +
              name: thor
         | 
| 113 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 114 | 
            +
                requirements:
         | 
| 115 | 
            +
                - - ">="
         | 
| 116 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 117 | 
            +
                    version: '0'
         | 
| 118 | 
            +
              type: :runtime
         | 
| 119 | 
            +
              prerelease: false
         | 
| 120 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 121 | 
            +
                requirements:
         | 
| 122 | 
            +
                - - ">="
         | 
| 123 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 124 | 
            +
                    version: '0'
         | 
| 125 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 126 | 
            +
              name: aws-sdk
         | 
| 127 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 128 | 
            +
                requirements:
         | 
| 129 | 
            +
                - - "~>"
         | 
| 130 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 131 | 
            +
                    version: '2'
         | 
| 132 | 
            +
              type: :runtime
         | 
| 133 | 
            +
              prerelease: false
         | 
| 134 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 135 | 
            +
                requirements:
         | 
| 136 | 
            +
                - - "~>"
         | 
| 137 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 138 | 
            +
                    version: '2'
         | 
| 139 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 140 | 
            +
              name: deep_hash_transform
         | 
| 141 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 142 | 
            +
                requirements:
         | 
| 143 | 
            +
                - - ">="
         | 
| 144 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 145 | 
            +
                    version: '0'
         | 
| 146 | 
            +
              type: :runtime
         | 
| 147 | 
            +
              prerelease: false
         | 
| 148 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 149 | 
            +
                requirements:
         | 
| 150 | 
            +
                - - ">="
         | 
| 151 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 152 | 
            +
                    version: '0'
         | 
| 153 | 
            +
            description: Command line tool of create new ami and update auto scaling group and
         | 
| 154 | 
            +
              delete old ami and launch config.
         | 
| 155 | 
            +
            email:
         | 
| 156 | 
            +
            - 3280467rec@gmail.com
         | 
| 157 | 
            +
            executables:
         | 
| 158 | 
            +
            - tsudura
         | 
| 159 | 
            +
            extensions: []
         | 
| 160 | 
            +
            extra_rdoc_files: []
         | 
| 161 | 
            +
            files:
         | 
| 162 | 
            +
            - ".gitignore"
         | 
| 163 | 
            +
            - ".rspec"
         | 
| 164 | 
            +
            - ".travis.yml"
         | 
| 165 | 
            +
            - Gemfile
         | 
| 166 | 
            +
            - Guardfile
         | 
| 167 | 
            +
            - LICENSE.txt
         | 
| 168 | 
            +
            - README.md
         | 
| 169 | 
            +
            - Rakefile
         | 
| 170 | 
            +
            - bin/console
         | 
| 171 | 
            +
            - bin/setup
         | 
| 172 | 
            +
            - exe/tsudura
         | 
| 173 | 
            +
            - lib/tsudura.rb
         | 
| 174 | 
            +
            - lib/tsudura/aws/ami.rb
         | 
| 175 | 
            +
            - lib/tsudura/aws/auto_scale.rb
         | 
| 176 | 
            +
            - lib/tsudura/aws/launch_config.rb
         | 
| 177 | 
            +
            - lib/tsudura/aws/launch_instance.rb
         | 
| 178 | 
            +
            - lib/tsudura/aws/utils.rb
         | 
| 179 | 
            +
            - lib/tsudura/cli.rb
         | 
| 180 | 
            +
            - lib/tsudura/config_parser.rb
         | 
| 181 | 
            +
            - lib/tsudura/env_prefix.rb
         | 
| 182 | 
            +
            - lib/tsudura/normal_runner.rb
         | 
| 183 | 
            +
            - lib/tsudura/packer_plus_runner.rb
         | 
| 184 | 
            +
            - lib/tsudura/provisioner/ansible.rb
         | 
| 185 | 
            +
            - lib/tsudura/runner.rb
         | 
| 186 | 
            +
            - lib/tsudura/runner_module.rb
         | 
| 187 | 
            +
            - lib/tsudura/version.rb
         | 
| 188 | 
            +
            - tsudura.gemspec
         | 
| 189 | 
            +
            homepage: https://github.com/onigra/tsudura
         | 
| 190 | 
            +
            licenses:
         | 
| 191 | 
            +
            - MIT
         | 
| 192 | 
            +
            metadata:
         | 
| 193 | 
            +
              allowed_push_host: https://rubygems.org
         | 
| 194 | 
            +
            post_install_message: 
         | 
| 195 | 
            +
            rdoc_options: []
         | 
| 196 | 
            +
            require_paths:
         | 
| 197 | 
            +
            - lib
         | 
| 198 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 199 | 
            +
              requirements:
         | 
| 200 | 
            +
              - - ">="
         | 
| 201 | 
            +
                - !ruby/object:Gem::Version
         | 
| 202 | 
            +
                  version: '0'
         | 
| 203 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 204 | 
            +
              requirements:
         | 
| 205 | 
            +
              - - ">="
         | 
| 206 | 
            +
                - !ruby/object:Gem::Version
         | 
| 207 | 
            +
                  version: '0'
         | 
| 208 | 
            +
            requirements: []
         | 
| 209 | 
            +
            rubyforge_project: 
         | 
| 210 | 
            +
            rubygems_version: 2.4.5
         | 
| 211 | 
            +
            signing_key: 
         | 
| 212 | 
            +
            specification_version: 4
         | 
| 213 | 
            +
            summary: Update ami and launch_config and auto scaling group like packer.
         | 
| 214 | 
            +
            test_files: []
         |