aws-ec2 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 479b890e45d465cd48dad82e9063f5b9ef3074ca05a47461f68ed93ce8b0fd55
4
- data.tar.gz: 062a19ef9048e2ff0e284f97b1e1a21a7c44034642ac5639dfef53581f61c23a
3
+ metadata.gz: 1868534625988933a50ea50d14c3ed0d0b13a825d4d29a6e5feab301fd0d969a
4
+ data.tar.gz: ae53a49329501b81a4bc3283e4685e05da78b16da9e3bf79e2927ca067f7bcc4
5
5
  SHA512:
6
- metadata.gz: 7e0452f43bb90b093a39e889a65b581620532ac7dc8803e70d74c5b2a0dc56da645273bcf7814aee9de09d666cc61f05305ab94132e7d745d0b69994b27d3cf3
7
- data.tar.gz: 3731a44ca9cd7597fbee6f36cb62817ce801fb9404c26f05a7c98f8ade9303f487eca36df301e1c27f0e92d405f8e4f44ac10527fcb1ed32137c3454f865e73d
6
+ metadata.gz: 9efa949c751ffb52b187a722519b4c22ab0d3714a84a1cec7f96288557eb686dba403365e5b3e5a99719f7f5523417487856f3969e7f49d028397b4ec35ab49a
7
+ data.tar.gz: 1e8da07ac54e0f09236a84c9a8bb839ef64df6eead452b4a0a511112b2eea857c125341ec087debab54eeb73a2048066ecb584b603ee19b7c77c750450c69567
@@ -0,0 +1,3 @@
1
+ [submodule "vendor/render_me_pretty"]
2
+ path = vendor/render_me_pretty
3
+ url = https://github.com/tongueroo/render_me_pretty
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.2.0]
7
+ - Merge pull request #6 from tongueroo/wait: aws-ec2 wait ami command
8
+ - Fix dependencies: add aws-sdk-s3 dependency
9
+ - require render_me_pretty as vendor submodule for now
10
+
6
11
  ## [1.1.0]
7
12
  - Merge pull request #5 from tongueroo/auto-terminate
8
13
  - allow AWS_RDS_CODE_VERSION env variable
@@ -1,15 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- aws-ec2 (0.9.0)
4
+ aws-ec2 (1.1.0)
5
5
  activesupport
6
6
  aws-sdk-ec2
7
+ aws-sdk-s3
7
8
  colorize
8
9
  dotenv
9
10
  filesize
10
11
  hashie
11
- render_me_pretty
12
12
  thor
13
+ tilt
13
14
 
14
15
  GEM
15
16
  remote: https://rubygems.org/
@@ -19,16 +20,23 @@ GEM
19
20
  i18n (~> 0.7)
20
21
  minitest (~> 5.1)
21
22
  tzinfo (~> 1.1)
22
- aws-partitions (1.67.0)
23
- aws-sdk-core (3.17.0)
23
+ aws-partitions (1.72.0)
24
+ aws-sdk-core (3.17.1)
24
25
  aws-partitions (~> 1.0)
25
26
  aws-sigv4 (~> 1.0)
26
27
  jmespath (~> 1.0)
27
- aws-sdk-ec2 (1.28.0)
28
+ aws-sdk-ec2 (1.29.0)
29
+ aws-sdk-core (~> 3)
30
+ aws-sigv4 (~> 1.0)
31
+ aws-sdk-kms (1.5.0)
32
+ aws-sdk-core (~> 3)
33
+ aws-sigv4 (~> 1.0)
34
+ aws-sdk-s3 (1.8.2)
28
35
  aws-sdk-core (~> 3)
36
+ aws-sdk-kms (~> 1)
29
37
  aws-sigv4 (~> 1.0)
30
38
  aws-sigv4 (1.0.2)
31
- byebug (10.0.0)
39
+ byebug (10.0.1)
32
40
  codeclimate-test-reporter (1.0.8)
33
41
  simplecov (<= 0.13)
34
42
  coderay (1.1.2)
@@ -77,14 +85,10 @@ GEM
77
85
  pry (0.11.3)
78
86
  coderay (~> 1.1.0)
79
87
  method_source (~> 0.9.0)
80
- rake (12.3.0)
81
- rb-fsevent (0.10.2)
88
+ rake (12.3.1)
89
+ rb-fsevent (0.10.3)
82
90
  rb-inotify (0.9.10)
83
91
  ffi (>= 0.5.0, < 2)
84
- render_me_pretty (0.8.0)
85
- activesupport
86
- colorize
87
- tilt
88
92
  rspec (3.7.0)
89
93
  rspec-core (~> 3.7.0)
90
94
  rspec-expectations (~> 3.7.0)
@@ -21,13 +21,19 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "activesupport"
23
23
  spec.add_dependency "aws-sdk-ec2"
24
+ spec.add_dependency "aws-sdk-s3"
24
25
  spec.add_dependency "colorize"
25
26
  spec.add_dependency "dotenv"
26
27
  spec.add_dependency "filesize"
27
28
  spec.add_dependency "hashie"
28
- spec.add_dependency "render_me_pretty"
29
29
  spec.add_dependency "thor"
30
30
 
31
+ # spec.add_dependency "render_me_pretty"
32
+ # render_me_pretty dependencies since temporarily added it as vendored submodule
33
+ # spec.add_dependency "activesupport" # dup
34
+ # spec.add_dependency "colorize" # dup
35
+ spec.add_dependency "tilt"
36
+
31
37
  spec.add_development_dependency "bundler"
32
38
  spec.add_development_dependency "byebug"
33
39
  spec.add_development_dependency "guard"
@@ -1,17 +1,20 @@
1
1
  $:.unshift(File.expand_path("../", __FILE__))
2
2
  require "aws_ec2/version"
3
3
  require "colorize"
4
+
5
+ $:.unshift(File.expand_path("../../vendor/render_me_pretty/lib", __FILE__))
4
6
  require "render_me_pretty"
5
7
 
6
8
  module AwsEc2
7
9
  autoload :Help, "aws_ec2/help"
8
10
  autoload :Command, "aws_ec2/command"
9
11
  autoload :CLI, "aws_ec2/cli"
10
- autoload :AwsServices, "aws_ec2/aws_services"
12
+ autoload :AwsService, "aws_ec2/aws_service"
11
13
  autoload :Profile, "aws_ec2/profile"
12
14
  autoload :Base, "aws_ec2/base"
13
15
  autoload :Create, "aws_ec2/create"
14
16
  autoload :Ami, "aws_ec2/ami"
17
+ autoload :Wait, "aws_ec2/wait"
15
18
  autoload :Template, "aws_ec2/template"
16
19
  autoload :Script, "aws_ec2/script"
17
20
  autoload :Config, "aws_ec2/config"
@@ -1,6 +1,6 @@
1
1
  require 'aws-sdk-ec2'
2
2
 
3
- module AwsEc2::AwsServices
3
+ module AwsEc2::AwsService
4
4
  def ec2
5
5
  @ec2 ||= Aws::EC2::Client.new
6
6
  end
@@ -3,6 +3,10 @@ module AwsEc2
3
3
  class_option :noop, type: :boolean
4
4
  class_option :profile, desc: "profile name to use"
5
5
 
6
+ desc "wait SUBCOMMAND", "wait subcommands"
7
+ long_desc Help.text(:wait)
8
+ subcommand "wait", Wait
9
+
6
10
  common_options = Proc.new do
7
11
  option :auto_terminate, type: :boolean, default: false, desc: "automatically terminate the instance at the end of user-data"
8
12
  option :cloudwatch, type: :boolean, default: false, desc: "enable cloudwatch logging, only supported for amazonlinux"
@@ -6,7 +6,7 @@ module AwsEc2
6
6
  autoload :Params, "aws_ec2/create/params"
7
7
  autoload :ErrorMessages, "aws_ec2/create/error_messages"
8
8
 
9
- include AwsServices
9
+ include AwsService
10
10
  include ErrorMessages
11
11
 
12
12
  def run
@@ -1,12 +1,12 @@
1
1
  Examples:
2
2
 
3
- $ aws-ec2 ami myrubyami --profile ruby --noop
3
+ $ aws-ec2 ami myrubyami --profile ruby --noop
4
4
 
5
5
  Launches an EC2 instance to create an AMI. An AMI creation script is appended to the end of the user-data script. The AMI creation script calls `aws ec2 create-image` and causes the instance to reboot at the end.
6
6
 
7
7
  It is useful to include to timestamp as a part of the AMI name with the date command.
8
8
 
9
- $ aws-ec2 ami ruby-2.5.0_$(date "+%Y-%m-%d-%H-%M") --profile ruby --noop
9
+ $ aws-ec2 ami ruby-2.5.0_$(date "+%Y-%m-%d-%H-%M") --profile ruby --noop
10
10
 
11
11
  The instance also automatically gets terminated and cleaned up by a termination script appended to user-data.
12
12
 
@@ -1,5 +1,5 @@
1
1
  Examples:
2
2
 
3
- $ aws-ec2 compile
3
+ $ aws-ec2 compile
4
4
 
5
5
  Compiles app/scripts and app/user-data files to the tmp folder. Useful for inspection.
@@ -1,22 +1,22 @@
1
1
  Example:
2
2
 
3
- aws-ec2 completion
3
+ aws-ec2 completion
4
4
 
5
5
  Prints words for TAB auto-completion.
6
6
 
7
7
  Examples:
8
8
 
9
- aws-ec2 completion
10
- aws-ec2 completion hello
11
- aws-ec2 completion hello name
9
+ aws-ec2 completion
10
+ aws-ec2 completion hello
11
+ aws-ec2 completion hello name
12
12
 
13
13
  To enable, TAB auto-completion add the following to your profile:
14
14
 
15
- eval $(aws-ec2 completion_script)
15
+ eval $(aws-ec2 completion_script)
16
16
 
17
17
  Auto-completion example usage:
18
18
 
19
- aws-ec2 [TAB]
20
- aws-ec2 hello [TAB]
21
- aws-ec2 hello name [TAB]
22
- aws-ec2 hello name --[TAB]
19
+ aws-ec2 [TAB]
20
+ aws-ec2 hello [TAB]
21
+ aws-ec2 hello name [TAB]
22
+ aws-ec2 hello name --[TAB]
@@ -1,7 +1,7 @@
1
1
  Examples:
2
2
 
3
- $ aws-ec2 create my-instance
3
+ $ aws-ec2 create my-instance
4
4
 
5
5
  To see the snippet of code that gets added to the user-data script you can use the `--noop` option and then view the generated tmp/user-data.txt.
6
6
 
7
- $ aws-ec2 create myscript --noop
7
+ $ aws-ec2 create myscript --noop
@@ -1,6 +1,6 @@
1
1
  Examples:
2
2
 
3
- $ aws-ec2 upload
3
+ $ aws-ec2 upload
4
4
 
5
5
  Compiles the app/scripts and app/user-data files to the tmp folder. Then uploads the files to an s3 bucket that is configured in config/settings.yml. Example s3_folder setting:
6
6
 
@@ -0,0 +1,12 @@
1
+ Examples:
2
+
3
+ $ aws-ec2 wait ami ruby-2.5.0_2018-03-24-17-07
4
+ $ aws-ec2 wait ami ami-b0138dc8
5
+
6
+ Polls the AMI with the given AMI name or id until AMI is found and available.
7
+
8
+ ### Timeout
9
+
10
+ Command times out after 30 mins by default. You can control the timeout with the `--timeout` flag. The timeout is specified in seconds.
11
+
12
+ $ aws-ec2 wait ami --id ami-b0138dc8 --timeout 3600
@@ -1,5 +1,5 @@
1
1
  module AwsEc2::Template::Helper::AmiHelper
2
- include AwsEc2::AwsServices
2
+ include AwsEc2::AwsService
3
3
 
4
4
  # Example:
5
5
  #
@@ -25,7 +25,8 @@ module AwsEc2::Template::Helper::AmiHelper
25
25
  ec2.describe_images(
26
26
  owners: owners,
27
27
  filters: [
28
- {name: "name", values: [query]}
28
+ {name: "name", values: [query]},
29
+ {name: "state", values: ["available"]}
29
30
  ]
30
31
  ).images
31
32
  end
@@ -1,3 +1,3 @@
1
1
  module AwsEc2
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,13 @@
1
+ module AwsEc2
2
+ autoload :Waiter, 'aws_ec2/waiter'
3
+
4
+ class Wait < Command
5
+
6
+ desc "ami", "Wait until AMI available."
7
+ long_desc Help.text("wait:ami")
8
+ option :timeout, type: :numeric, default: 1800, desc: "Timeout in seconds."
9
+ def ami(name)
10
+ Waiter::Ami.new(options.merge(name: name)).wait
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module AwsEc2
2
+ module Waiter
3
+ autoload :Ami, 'aws_ec2/waiter/ami'
4
+ end
5
+ end
@@ -0,0 +1,61 @@
1
+ module AwsEc2::Waiter
2
+ class Ami < AwsEc2::Base
3
+ include AwsEc2::AwsService
4
+
5
+ def wait
6
+ delay = 30
7
+ timeout = @options[:timeout]
8
+ max_attempts = timeout / delay
9
+ current_time = 0
10
+
11
+ puts "Waiting for #{@options[:name]} to be available. Delay: #{delay}s. Timeout: #{timeout}s"
12
+ puts "Current time: #{Time.now}"
13
+ return if ENV['TEST']
14
+
15
+ # Using while loop because of issues with ruby's Timeout module
16
+ # http://www.mikeperham.com/2015/05/08/timeout-rubys-most-dangerous-api/
17
+ detected = detect_ami
18
+ until detected || current_time > timeout
19
+ print '.'
20
+ sleep delay
21
+ current_time += 30
22
+ detected = detect_ami
23
+ end
24
+
25
+ if current_time > timeout
26
+ puts "ERROR: Timeout. Unable to detect and available ami: #{@options[:name]}"
27
+ exit 1
28
+ else
29
+ puts "Found available AMI: #{@options[:name]}"
30
+ end
31
+ puts
32
+ end
33
+
34
+ private
35
+ # Using custom detect_ami instead of ec2.wait_until(:image_availalbe, ...)
36
+ # because we start checking for the ami even before we've called
37
+ # create_ami. We start checking right after we launch the instance
38
+ # which will create the ami at the end.
39
+ def detect_ami(owners=["self"])
40
+ images = ec2.describe_images(
41
+ owners: owners,
42
+ filters: filters
43
+ ).images
44
+ detected = images.first
45
+ !!detected
46
+ end
47
+
48
+ def filters
49
+ name_is_ami_id = @options[:name] =~ /^ami-/
50
+
51
+ filters = [{name: "state", values: ["available"]}]
52
+ filters << if name_is_ami_id
53
+ {name: "image-id", values: [@options[:name]]}
54
+ else
55
+ {name: "name", values: [@options[:name]]}
56
+ end
57
+
58
+ filters
59
+ end
60
+ end
61
+ end
@@ -14,6 +14,11 @@ describe AwsEc2::CLI do
14
14
  expect(out).to include("Creating EC2 instance")
15
15
  end
16
16
 
17
+ it "wait ami" do
18
+ out = execute("exe/aws-ec2 wait ami myimage")
19
+ expect(out).to include("Waiting for")
20
+ end
21
+
17
22
  commands = {
18
23
  "am" => "ami",
19
24
  "compile" => "--profile",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-ec2
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-23 00:00:00.000000000 Z
11
+ date: 2018-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aws-sdk-s3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: colorize
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: render_me_pretty
112
+ name: thor
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: thor
126
+ name: tilt
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -237,7 +251,7 @@ files:
237
251
  - exe/aws-ec2
238
252
  - lib/aws-ec2.rb
239
253
  - lib/aws_ec2/ami.rb
240
- - lib/aws_ec2/aws_services.rb
254
+ - lib/aws_ec2/aws_service.rb
241
255
  - lib/aws_ec2/base.rb
242
256
  - lib/aws_ec2/cli.rb
243
257
  - lib/aws_ec2/command.rb
@@ -257,6 +271,7 @@ files:
257
271
  - lib/aws_ec2/help/completion_script.md
258
272
  - lib/aws_ec2/help/create.md
259
273
  - lib/aws_ec2/help/upload.md
274
+ - lib/aws_ec2/help/wait/ami.md
260
275
  - lib/aws_ec2/hook.rb
261
276
  - lib/aws_ec2/profile.rb
262
277
  - lib/aws_ec2/script.rb
@@ -289,6 +304,9 @@ files:
289
304
  - lib/aws_ec2/template/helper/script_helper.rb
290
305
  - lib/aws_ec2/template/helper/ssh_key_helper.rb
291
306
  - lib/aws_ec2/version.rb
307
+ - lib/aws_ec2/wait.rb
308
+ - lib/aws_ec2/waiter.rb
309
+ - lib/aws_ec2/waiter/ami.rb
292
310
  - spec/fixtures/demo_project/config/settings.yml
293
311
  - spec/fixtures/demo_project/config/test.yml
294
312
  - spec/fixtures/demo_project/profiles/default.yml