aws-ec2 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42b56c4659b31e265e4cf80becf741303ea43fb9a1885724f12e6a0e76fbfb1e
4
- data.tar.gz: e23f45d1462ee2897a20ad52fe2d57ed207090c8d38eee1d3869b0261f100fc7
3
+ metadata.gz: 0cf9927e8f80013a840c32371fdd48096c1f349002f3f9ee6141a369a326c002
4
+ data.tar.gz: c8985115802338c38fab0d24f7d95f1dad7021eef7d15c874b53c1b3ef2e23e3
5
5
  SHA512:
6
- metadata.gz: a7b83b59c84b4da126a0d1e6ea7df4ba88c340da499edd2ef35b4d94c69c05d318e5542d0d60ba9698a5633666cfd0c81315c2a56370bb0e0dc5684b2e86ed89
7
- data.tar.gz: c8e7a78cbff83c6f40366b5c90d235fc84f3605fa1a2052185a37b9bacc65373ad8b19c2af1ec8430973d7a0db78342b1809ae752a6199e208ba296507647341
6
+ metadata.gz: dc87b7836701be0468190525dcf22e3373f5ba0bf9dc2d7050af88ec443de2c0bd83853bfe36683030d8e653f8edf9ac854d68ede7cab351a959f82cb3db3ffb
7
+ data.tar.gz: 77de0393c45ccffaa18527d585465ea9864d76739b4fd73550884496fff5d0b55be51ab2a4677c64e0b75e68dd2e54315aacd21c3c07afa461fda1a4ce168fd1
@@ -3,6 +3,10 @@
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
+ ## [0.7.0]
7
+ - Rid of name to profile convention, check profile exists and report to user
8
+ if it does not exist. This is a more expected interface.
9
+
6
10
  ## [0.6.0]
7
11
  - add scripts_s3_bucket config option
8
12
  - halt script if hooks fail
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Simple tool to create AWS ec2 instances consistently with pre-configured settings. The pre-configured settings are stored in the profiles folder of the current directory.
4
4
  Example:
5
5
 
6
- * profiles/default.yml: default settings.
6
+ * profiles/default.yml: default settings. used when no profile is specified.
7
7
  * profiles/myserver.yml: myserver settings.
8
8
 
9
9
  ## Usage
@@ -30,14 +30,6 @@ The template helpers defined in:
30
30
 
31
31
  You can also define your own custom helpers in the `app/helpers` folder as ruby modules with the naming convention `'*_helper.rb`. Example, the module FooHelper should be defined in `app/helpers/foo_helper.rb`. The custom helpers are first class citizens and have access to the same variables and methods as built in helpers.
32
32
 
33
- ### Convention
34
-
35
- By convention, the profile name matches the first parameter after the create command. So the command above could be shortened to:
36
-
37
- ```
38
- aws-ec2 create myserver
39
- ```
40
-
41
33
  ## Noop mode
42
34
 
43
35
  You can do a test run with the `--noop` flag. This will print out what settings will be used to launch the instance. This is a good way to inspect the generated user-data script.
@@ -96,6 +88,8 @@ scripts_s3_bucket: mybucket # enables s3 uploading of generated app/scripts
96
88
 
97
89
  The variables are accessible via the `config` helper method. Example (only showing the part of the profile), `profiles/default.yml`:
98
90
 
91
+ The `scripts_s3_bucket` is an option that changes the behavior of aws-ec2 to automatically sync the generated scripts from app/scripts to the s3 bucket right before the internal call to run_instances to launch the instance. If you need more custom logic, look at the hooks section.
92
+
99
93
  ```yaml
100
94
  image_id: ami-4fffc834 # Amazon Lambda AMI
101
95
  instance_type: t2.medium
@@ -7,6 +7,7 @@ module AwsEc2
7
7
  autoload :Command, "aws_ec2/command"
8
8
  autoload :CLI, "aws_ec2/cli"
9
9
  autoload :AwsServices, "aws_ec2/aws_services"
10
+ autoload :Profile, "aws_ec2/profile"
10
11
  autoload :Base, "aws_ec2/base"
11
12
  autoload :Create, "aws_ec2/create"
12
13
  autoload :Ami, "aws_ec2/ami"
@@ -3,6 +3,7 @@ module AwsEc2
3
3
  def initialize(options={})
4
4
  @options = options.clone
5
5
  AwsEc2.validate_in_project!
6
+ Profile.new(@options).check!
6
7
  end
7
8
  end
8
9
  end
@@ -4,6 +4,7 @@ require 'active_support/core_ext/hash'
4
4
  module AwsEc2
5
5
  class Create < Base
6
6
  autoload :Params, "aws_ec2/create/params"
7
+
7
8
  include AwsServices
8
9
 
9
10
  def run
@@ -1,7 +1,5 @@
1
1
  class AwsEc2::Create
2
2
  class Params
3
- include AwsEc2::TemplateHelper
4
-
5
3
  def initialize(options)
6
4
  @options = options
7
5
  end
@@ -10,7 +8,7 @@ class AwsEc2::Create
10
8
  # up until that point we're dealing with String keys.
11
9
  def generate
12
10
  cleanup
13
- params = load_profiles(profile_name)
11
+ params = AwsEc2::Profile.new(@options).load
14
12
  decorate_params(params)
15
13
  normalize_launch_template(params).deep_symbolize_keys
16
14
  end
@@ -108,47 +106,5 @@ class AwsEc2::Create
108
106
  min_count: 1,
109
107
  }
110
108
  end
111
-
112
- def load_profiles(profile_name)
113
- return @profile_params if @profile_params
114
-
115
- profile_file = "#{AwsEc2.root}/profiles/#{profile_name}.yml"
116
- base_path = File.dirname(profile_file)
117
- default_file = "#{base_path}/default.yml"
118
-
119
- params_exit_check!(profile_file, default_file)
120
-
121
- params = File.exist?(profile_file) ?
122
- load_profile(profile_file) :
123
- load_profile(default_file)
124
- @profile_params = params
125
- end
126
-
127
- def params_exit_check!(profile_file, default_file)
128
- return if File.exist?(profile_file) or File.exist?(default_file)
129
-
130
- puts "Unable to find a #{profile_file} or #{default_file} profile file."
131
- puts "Please double check."
132
- exit # EXIT HERE
133
- end
134
-
135
- def load_profile(file)
136
- return {} unless File.exist?(file)
137
-
138
- puts "Using profile: #{file}"
139
- data = YAML.load(erb_result(file))
140
- data ? data : {} # in case the file is empty
141
- data.has_key?("run_instances") ? data["run_instances"] : data
142
- end
143
-
144
- def profile_name
145
- # allow user to specify the path also
146
- if @options[:profile] && File.exist?(@options[:profile])
147
- profile = File.basename(@options[:profile], '.yml')
148
- end
149
-
150
- # conventional profile is the name of the ec2 instance
151
- profile || @options[:profile] || @options[:name]
152
- end
153
109
  end
154
110
  end
@@ -0,0 +1,48 @@
1
+ module AwsEc2
2
+ class Profile
3
+ include TemplateHelper
4
+
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def load
10
+ return @profile_params if @profile_params
11
+
12
+ check!
13
+
14
+ @profile_params = load_profile(profile_file)
15
+ end
16
+
17
+ def check!
18
+ return if File.exist?(profile_file)
19
+
20
+ puts "Unable to find a #{profile_file.colorize(:green)} profile file."
21
+ puts "Please double check that it exists or that you specified the right profile."
22
+ exit # EXIT HERE
23
+ end
24
+
25
+ def load_profile(file)
26
+ return {} unless File.exist?(file)
27
+
28
+ puts "Using profile: #{file}"
29
+ data = YAML.load(erb_result(file))
30
+ data ? data : {} # in case the file is empty
31
+ data.has_key?("run_instances") ? data["run_instances"] : data
32
+ end
33
+
34
+ def profile_file
35
+ "#{AwsEc2.root}/profiles/#{profile_name}.yml"
36
+ end
37
+
38
+ def profile_name
39
+ # allow user to specify the path also
40
+ if @options[:profile] && File.exist?(@options[:profile])
41
+ profile = File.basename(@options[:profile], '.yml')
42
+ end
43
+
44
+ # conventional profile is the name of the ec2 instance
45
+ profile || @options[:profile] || "default"
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module AwsEc2
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
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: 0.6.0
4
+ version: 0.7.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-01-29 00:00:00.000000000 Z
11
+ date: 2018-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -215,6 +215,7 @@ files:
215
215
  - lib/aws_ec2/help/compile.md
216
216
  - lib/aws_ec2/help/create.md
217
217
  - lib/aws_ec2/hook.rb
218
+ - lib/aws_ec2/profile.rb
218
219
  - lib/aws_ec2/s3.rb
219
220
  - lib/aws_ec2/script.rb
220
221
  - lib/aws_ec2/scripts/ami_creation.sh