jack-eb 0.1.6 → 0.2.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
  SHA1:
3
- metadata.gz: aeafb675a751c393409d6a719583390bd8cc711b
4
- data.tar.gz: 25cdd6bc564734c88fb4c0d68c479e20dd369256
3
+ metadata.gz: 2dc1841b5ba329d4b7075647c4ad06cb6949392b
4
+ data.tar.gz: 2ddb7d30db167c363ea5ad52b5d584858f3d801c
5
5
  SHA512:
6
- metadata.gz: 6aed79a0db2e4f5c3fb4695c935ce63e706f1ac7610016c87adb8cb493f0ba7e24a34180ea9cb8c163f9d43d1e8a7ffdf1264e103c982158b4f1e7223b3af87f
7
- data.tar.gz: 2ad41ee9616bd454961dca5ee3519f75737940d4d2a391663bbb8eaafbc4b8f7ad714e8573092f3fc08fc92b7c60e10e40378f0513457acaa1f4c1fbce78554a
6
+ metadata.gz: 42198b5dfcb6daa56c1faee7fc67569f53607b4ece7eae7870182e58dd4f3d3d6db0be0396fafbd673fb5adc28468fe691a889ca76cc8d7a1fb0fc2277e6b456
7
+ data.tar.gz: 47e426272c7dc8395bee6a8ffdfc8866e4aede18f20bf9f1ada5dc973d706e8b8d874971f1ffc28bf107a57b9c9932a5c2c2aec7a290c862552575d7ac178f33
data/.rspec CHANGED
@@ -1 +1,3 @@
1
1
  --color
2
+ --require spec_helper
3
+ --format documentation
data/README.md CHANGED
@@ -1,12 +1,21 @@
1
1
  # Jack and the Elastic Beanstalk
2
2
 
3
+ [![ReadmeCI](http://www.readmeci.com/images/readmeci-badge.svg)](http://www.readmeci.com/tongueroo/jack)
3
4
  [![Build Status](https://travis-ci.org/tongueroo/jack.svg?branch=master)](https://travis-ci.org/tongueroo/jack)
4
5
  [![Code Climate](https://codeclimate.com/github/tongueroo/jack/badges/gpa.svg)](https://codeclimate.com/github/tongueroo/jack)
5
6
  [![Test Coverage](https://codeclimate.com/github/tongueroo/jack/badges/coverage.svg)](https://codeclimate.com/github/tongueroo/jack)
6
7
 
7
- Jack is a wrapper tool around the eb cli tool that can be use to manage AWS Elastic Beanstalk environments. It allows you to create environments based on a saved template configuration file, located in the jack/cfg folder of your project. It also provides a helpful config command to manage the template configuration.
8
+ Jack is a wrapper tool around the [aws eb cli3](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3.html) tool use to manage AWS Elastic Beanstalk, EB, environments. It allows you to create environments based on a saved template configuration file, located in the jack/cfg folder of your project. The jack/cfg files are the same files that are saved by the `eb config save` command, they are simply moved into the jack directory.
8
9
 
9
- For things that this tool does not do, it is recommended that you use use the underlying eb tool directly. This tool has been tested with the 3.1.2 version of the eb command, so have at least that version installed.
10
+ Jack also provides a `jack config upload` command to update the EB environment. Before uploading the configuration to EB jack first downloads the current configuration and then does a diff on the changes that are about to be applied. This gives a very helpful preview of exactly what you are intending to change. This is also very helpful when changes are made through the EB GUI and are out of sync with what is stored in the `jack/cfg` files.
11
+
12
+ For things that this tool does not do, it is recommended that you use use the underlying aws `eb` tool directly. This tool has been tested with `EB CLI 3.7.6 (Python 2.7.1)`.
13
+
14
+ ## Use Cases
15
+
16
+ * Downloading EB config to codified the EB infrastructure that has been built.
17
+ * Allowing safe uploading of new configs.
18
+ * Moving EB enviroments from one EB application to another EB application. EB provides a way to clone environments within an application but not to another application.
10
19
 
11
20
  ## Installation
12
21
 
@@ -18,32 +27,79 @@ Note that the gem is called jack-eb but the command that is installed is called
18
27
 
19
28
  ### Setup
20
29
 
21
- This gem relies on the eb cli tool. To install follow the instructions on [AWS EB Documentation](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-getting-set-up.html). Here's the gist of it:
30
+ If the version of `eb` that you are using is not working with jack, here is a way to install the specific version jack has been tested with.
22
31
 
23
32
  <pre>
24
- $ sudo pip install awsebcli
33
+ cd ~/ && wget https://pypi.python.org/packages/source/a/awsebcli/awsebcli-3.7.6.tar.gz
34
+ tar -zxvf awsebcli-3.7.6.tar.gz
35
+ cd awsebcli-3.7.6
36
+ sudo python setup.py install
25
37
  </pre>
26
38
 
27
- You need at least version 3.1.2 of the eb tool. To check the version `eb --version`. If you need to upgrade:
39
+ More detail instructions are on [AWS EB Documentation](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-getting-set-up.html).
40
+
41
+ I typically install the `eb` cli tool with homebrew.
28
42
 
29
43
  <pre>
30
- $ sudo pip install --upgrade awsebcli
44
+ brew install awsebcli
31
45
  </pre>
32
46
 
33
- You'll also need to set up your environment with your aws access keys since the tool also uses the aws-sdk. Add the following to your ~/.profile, replacing xxx with your actually credentials. Don't forgot to source the ~/.profile or open up a new terminal.
47
+ You will also need to set up your environment with your aws access keys since the tool also uses the aws-sdk. Add the following to your ~/.profile, replacing xxx with your actually credentials. Do not forgot to source the ~/.profile or open up a new terminal.
34
48
 
35
49
  <pre>
36
50
  export AWS_ACCESS_KEY_ID=xxx
37
51
  export AWS_SECRET_ACCESS_KEY=xxx
38
52
  </pre>
39
53
 
54
+ The jack tool does not yet support the `.aws/credentials` method of setting the aws keys.
55
+
40
56
  You're ready to go.
41
57
 
42
58
  ## Usage
43
59
 
60
+ ### Conventions
61
+
62
+ Before using the tool, it is good to know that jack follows a convention for the environment and application name. This is done in order to keep the jack commands simple and short. The convention is:
63
+
64
+ <pre>
65
+ environment_name: [env]-[app]-[role]
66
+ application_name: [app]
67
+ </pre>
68
+
69
+ A concrete example is helpful:
70
+
71
+ <pre>
72
+ environment_name: prod-api-web
73
+ application_name: api
74
+ </pre>
75
+
76
+ The example above means the EB application name will be `api` and the environment name will be `prod-api-web`. The second word of the environment name is by convention the application name.
77
+
78
+ This convention can be overriden easily via by creating a `~/.jack/settings.yml` or `jack/settings` within the project and defining your own regular expression with the `conventions.app_name_pattern` key. The regexp is a ruby regexp and must have 1 capture group. Here is an example:
79
+
80
+ ```yaml
81
+ create:
82
+ keyname: default
83
+ platform: "64bit Amazon Linux 2015.03 v1.4.0 running Docker 1.6.0"
84
+ conventions:
85
+ app_name_pattern: (\w+)-\w+-\w+
86
+ ```
87
+
88
+ In the example above, the capture group is the first word and this will result in:
89
+
90
+ <pre>
91
+ environment_name: api-web-prod
92
+ application_name: api
93
+ </pre>
94
+
95
+
96
+ The default settings are located at [lib/jack/default/settings.yml](https://github.com/tongueroo/jack/blob/master/lib/jack/default/settings.yml).
97
+
98
+ You can also override the application name convention from the cli with the `--app` flag. Examples are provided below.
99
+
44
100
  ### Overview
45
101
 
46
- In your project folder create a folder call jack/cfg. It might be useful for your company to create a baseline config that you can use. If you do not already have a baseline template, you can download the template from an existing environment like so:
102
+ You can download a starting baseline jack cfg and use it as template from one of your existing EB environments.
47
103
 
48
104
  <pre>
49
105
  $ jack config download [ENVIRONMENT_NAME]
@@ -63,17 +119,17 @@ Config downloaded to jack/cfg/stag-rails-app.cfg.yml
63
119
  $
64
120
  </pre>
65
121
 
66
- Results in a saved jack/cfg/stag-rails-app-s1.cfg.yml template configuration file. This is overridable.
122
+ Results in a saved jack/cfg/stag-rails-app-s1.cfg.yml template configuration file. This saved path is overridable with the `-c` flag.
67
123
 
68
124
  <pre>
69
125
  $ jack config download -c myconfig stag-rails-app-s1
70
126
  </pre>
71
127
 
72
- Results in a saved jack/cfg/myconfig.cfg.yml template configuration file.
128
+ Results in a saved `jack/cfg/myconfig.cfg.yml`.
73
129
 
74
130
  #### Configuration Templates
75
131
 
76
- Configuration templates hold all the options and settings that we can set for an EB environment. Elastic Beanstalk surfaces a portion of all the settings actually available on the underlying AWS Resources that we are allowed to configured. These includes the some of the ELB behavior, VPC, LaunchConfiguration, Autoscaling settings, hard drive size, environment variables, etc.
132
+ Configuration templates hold all the options and settings that we can set for an EB environment. Elastic Beanstalk surfaces a portion of settings available from the underlying AWS Resources. These settings include ELB behavior, VPC, LaunchConfiguration, Autoscaling settings, hard drive size, environment variables, etc.
77
133
 
78
134
  * [Here](https://gist.github.com/tongueroo/acc421c5ec998f238b4b) is an example of all the settings available.
79
135
  * [Here](https://gist.github.com/tongueroo/f22bbae7864ecec41ff3) is an example of what you would tyically see when you download the initial saved configuration.
@@ -83,12 +139,14 @@ Configuration templates hold all the options and settings that we can set for an
83
139
  The purpose of the jack/cfg configs is allow us to be able to create environments with a codified configuration file that can be versioned controlled.
84
140
 
85
141
  <pre>
86
- $ jack create stag-rails-app-s1 # uses the jack/cfg/stag-rails-app-s1.cfg.yml template
87
- $ jack create stag-rails-app-s2 # uses the jack/cfg/stag-rails-app-s2.cfg.yml template
88
- $ jack create -c myconfig stag-rails-app-s3 # creates environment using a config not based on environment naming convention
142
+ $ jack create stag-rails-app-s1 # uses the jack/cfg/stag-rails-app-s1.cfg.yml config
143
+ $ jack create stag-rails-app-s2 # uses the jack/cfg/stag-rails-app-s2.cfg.yml config
144
+ $ jack create -c myconfig stag-rails-app-s3 # creates environment using jack/cfg/myconfig.cfg.yml
89
145
  </pre>
90
146
 
91
- If the project is brand new and has never had `eb init` ran on it before. For example, a project that has just been git cloned. Then calling any of the jack commands will automatically call `eb init` in the project. `eb init` requires the platform flag in order to avoid prompting. By default, the latest Docker solution stack is used for the platform option. But you can override that by creating an ~/.jack/create.yml or jack/create.yml within the project folder. Here's an [example](https://gist.github.com/tongueroo/086e3c11c4d00d5c39b6). The options from each file is merged using the following precedence: project folder, user home, default that is packaged with this gem. Most of the settings that `jack create` should used should be in the template configuration file though.
147
+ If the project is brand new and has never had `eb init` ran on it before. For example, a project that has just been git cloned. Then calling any of the jack commands will automatically call `eb init` in the project. `eb init` requires the platform flag in order to avoid prompting. The default platform is "64bit Amazon Linux 2015.03 v1.4.0 running Docker 1.6.0". But you can override that by creating an `~/.jack/settings.yml` or `jack/settings.yml` within the project folder and setting the `create.platform` key.
148
+
149
+ Here's an [example](https://gist.github.com/tongueroo/086e3c11c4d00d5c39b6). The options from each file is merged and combined together in following order: project folder, user home, [default](lib/jack/default/settings.yml) that is packaged with this gem.
92
150
 
93
151
  ### Downloading and Uploading Template Configurations
94
152
 
@@ -98,6 +156,8 @@ To download a template configuration.
98
156
 
99
157
  ```
100
158
  $ jack config download stag-rails-app-s1
159
+
160
+ $ jack config download stag-rails-app-s1 --app customappname
101
161
  ```
102
162
 
103
163
  This will save the config to jack/cfg/stag-rails-app-s1.cfg.yml.
@@ -108,21 +168,23 @@ To upload a template configuration.
108
168
 
109
169
  ```
110
170
  $ jack config upload stag-rails-app-s1
171
+
172
+ $ jack config upload stag-rails-app-s1 --app customappname
111
173
  ```
112
174
 
113
- This will save the config to jack/cfg/stag-rails-app-s1.cfg.yml. Here's an example of the [output](http://d.pr/i/14Sfh).
175
+ This will save the config to `jack/cfg/stag-rails-app-s1.cfg.yml`.
114
176
 
115
- Notice that the `eb config upload` command also prompts you with the diff before uploading and ask for confirmation. You can bypass the prompt with the force option.
177
+ You will notice that the `eb config upload` command prompts you with the diff and asks for confirmation before uploading. You can bypass the prompt with the force option.
116
178
 
117
179
  #### Diff - Comparing your local config to the live environment config
118
180
 
119
- You can use the diff command directly to compare your local config to what configs the environment is actually using is useful. To see the diff.
181
+ You can use the diff command directly to compare your local config to what configs the environment is actually using is useful. To see the diff.
120
182
 
121
183
  ```
122
184
  $ jack config diff stag-rails-app-s1
123
185
  ```
124
186
 
125
- A note about the configs. They are formatted so that the keys are sorted. This has been done so the diffs are actually useful. It is also recommended you install colordiff so you can see the diff output colorized. You can also specify your own diff viewer via the JACK_DIFF environment variable. Example of [colorized diff](http://d.pr/i/9wrS).
187
+ A note about the configs. They are formatted so that the keys are sorted. This has been done so the diffs are actually useful. It is also recommended you install colordiff so you can see the diff output colorized. You can also specify your own diff viewer via the JACK_DIFF environment variable.
126
188
 
127
189
  ### More Help
128
190
 
@@ -133,10 +195,5 @@ $ jack help
133
195
  $ jack help create
134
196
  $ jack config help download
135
197
  $ jack config help upload
136
- $ jack config help upload
137
198
  $ jack config help sort
138
199
  </pre>
139
-
140
- ### TODO
141
-
142
- * encrypted the jack/cfg files similar to how [shopify/ejson](https://github.com/Shopify/ejson) works, except with yaml - pull requests are welcome
@@ -24,7 +24,8 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "pry"
27
28
  spec.add_development_dependency "guard"
28
29
  spec.add_development_dependency "guard-bundler"
29
30
  spec.add_development_dependency "guard-rspec"
30
- end
31
+ end
@@ -7,10 +7,10 @@ require File.expand_path("../jack/ext/hash", __FILE__)
7
7
  module Jack
8
8
  autoload :CLI, 'jack/cli'
9
9
  autoload :Create, 'jack/create'
10
- autoload :CreateYaml, 'jack/create_yaml'
10
+ autoload :Settings, 'jack/settings'
11
11
  autoload :EbConfig, 'jack/eb_config'
12
12
  autoload :Config, 'jack/config'
13
13
  autoload :UI, 'jack/ui'
14
14
  autoload :Util, 'jack/util'
15
15
  autoload :VersionChecker, 'jack/version_checker'
16
- end
16
+ end
@@ -28,7 +28,7 @@ module Jack
28
28
 
29
29
  def cleanup_files
30
30
  return false if @options[:dirty]
31
- @download.clean(silent=true)
31
+ @download.clean(mute=true)
32
32
  end
33
33
 
34
34
  def diff_command
@@ -41,4 +41,4 @@ module Jack
41
41
  end
42
42
  end
43
43
  end
44
- end
44
+ end
@@ -21,7 +21,7 @@ module Jack
21
21
  end
22
22
 
23
23
  def download
24
- add_gitignore
24
+ # add_gitignore
25
25
  get_current_cfg
26
26
  copy_to_local_cfg
27
27
  clean
@@ -63,9 +63,9 @@ module Jack
63
63
  end
64
64
 
65
65
  # remove both the local download file and remote eb config
66
- def clean(silent=false)
66
+ def clean(mute=false)
67
67
  return if @options[:dirty]
68
- UI.say "Cleaning up eb remote config and local files" unless silent
68
+ UI.say "Cleaning up eb remote config and local files" unless mute
69
69
  eb.delete_configuration_template(
70
70
  application_name: @updater.app_name,
71
71
  template_name: current_name
@@ -75,4 +75,4 @@ module Jack
75
75
 
76
76
  end
77
77
  end
78
- end
78
+ end
@@ -47,7 +47,7 @@ overwrite your #{@local_config_path} instead, you can use this command:
47
47
  $ jack config download #{@env_name}
48
48
  $ jack config help download # for more info
49
49
  EOL
50
- print "yes/no? [no] " unless @options[:silent] || @options[:force]
50
+ print "yes/no? [no] " unless @options[:mute] || @options[:force]
51
51
  answer = get_answer
52
52
  answer =~ /^y/
53
53
  end
@@ -90,4 +90,4 @@ EOL
90
90
 
91
91
  end
92
92
  end
93
- end
93
+ end
@@ -36,12 +36,12 @@ module Jack
36
36
 
37
37
  def build_command
38
38
  @cfg = upload_cfg
39
- flags = CreateYaml.new.flags
39
+ flags = settings.create_flags
40
40
  "eb create --sample --nohang #{flags} #{@cfg}#{cname}#{@env_name}"
41
41
  end
42
42
 
43
43
  def upload_cfg
44
- @upload = Config::Upload.new(@options.merge(skip_sync: true))
44
+ @upload = Config::Upload.new(@options)
45
45
  if @upload.local_cfg_exist?
46
46
  @upload.upload
47
47
  cfg = "--cfg #{@upload.upload_name} "
@@ -53,4 +53,4 @@ module Jack
53
53
  end
54
54
 
55
55
  end
56
- end
56
+ end
@@ -0,0 +1,5 @@
1
+ create:
2
+ keyname: default
3
+ platform: "64bit Amazon Linux 2015.03 v1.4.0 running Docker 1.6.0"
4
+ conventions:
5
+ app_name_pattern: \w+-(\w+)-\w+
@@ -27,12 +27,12 @@ module Jack
27
27
 
28
28
  def write_eb_config_yml
29
29
  data = YAML.load_file(eb_config_path)
30
- data['global']['application_name'] = app_name
31
- data['global']['default_platform'] = platform
30
+ data['global']['application_name'] = app_name # from subclass
31
+ data['global']['default_platform'] = platform # from subclass
32
32
  dump = YAML.dump(data).gsub("!ruby/object:Hash", '')
33
33
  dump = dump.split("\n")[1..-1].join("\n") # strip first line
34
34
  File.write(eb_config_path, dump)
35
35
  end
36
36
  end
37
37
  end
38
- end
38
+ end
@@ -8,7 +8,10 @@ module Jack
8
8
  end
9
9
 
10
10
  def platform
11
- CreateYaml.new.data['Platform'] || latest_docker_platform
11
+ # TODO: change so that the gem default settins has nil for platform
12
+ # but need to provide a deprecation warning first.
13
+ # Right now it will never hit the lastest_docker_platform logic
14
+ settings.create['platform'] || latest_docker_platform
12
15
  end
13
16
 
14
17
  def app_name
@@ -16,7 +19,10 @@ module Jack
16
19
  end
17
20
 
18
21
  def latest_docker_platform
19
- "64bit Amazon Linux 2015.03 v1.4.0 running Docker 1.6.0"
22
+ solution_stacks.grep(/Docker/).
23
+ reject {|x| x =~ /Preconfigured/}.
24
+ reject {|x| x =~ /Multi-container/}.
25
+ sort.last
20
26
  end
21
27
 
22
28
  def solution_stacks
@@ -0,0 +1,43 @@
1
+ module Jack
2
+ class Settings
3
+ def initialize(root=nil)
4
+ @root = root || '.'
5
+ end
6
+
7
+ def data
8
+ return @settings_yaml if @settings_yaml
9
+
10
+ project_file = "#{@root}/jack/settings.yml"
11
+ project = File.exist?(project_file) ? YAML.load_file(project_file) : {}
12
+
13
+ user_file = "#{home}/.jack/settings.yml"
14
+ user = File.exist?(user_file) ? YAML.load_file(user_file) : {}
15
+
16
+ default_file = File.expand_path("../default/settings.yml", __FILE__)
17
+ default = YAML.load_file(default_file)
18
+
19
+ @settings_yaml = default.merge(project.merge(user))
20
+ end
21
+
22
+ def home
23
+ # hack but fast
24
+ ENV['TEST'] ? "spec/fixtures/home" : ENV['HOME']
25
+ end
26
+
27
+ def create_flags
28
+ create.inject("") {|s,(k,v)| s << %{--#{k} "#{v}" } ; s }.strip
29
+ end
30
+
31
+ def create
32
+ data["create"]
33
+ end
34
+
35
+ def app_name_pattern
36
+ Regexp.new(conventions["app_name_pattern"])
37
+ end
38
+
39
+ def conventions
40
+ data["conventions"]
41
+ end
42
+ end
43
+ end
@@ -1,14 +1,23 @@
1
1
  module Jack
2
+ # Any class that includes this module should define @root as it is used in
3
+ # the settings method.
2
4
  module Util
3
5
  def do_cmd(command, options={})
4
- UI.say "Running: #{command.colorize(:green)}" unless options[:silent]
6
+ UI.say "Running: #{command.colorize(:green)}"
5
7
  return command if options[:noop]
6
8
  out = `#{command}`
7
- UI.say out unless options[:silent]
9
+ UI.say out
8
10
  end
9
11
 
10
12
  def app_name_convention(env_name)
11
- env_name.split('-')[1] # convention
13
+ pattern = settings.app_name_pattern
14
+ env_name.match(pattern)[1]
15
+ end
16
+
17
+ def settings
18
+ # do not like the instance @root variable in this module but better
19
+ # than having to pass settings around
20
+ @settings ||= Settings.new(@root)
12
21
  end
13
22
 
14
23
  def eb
@@ -19,6 +28,5 @@ module Jack
19
28
  def ensure_folder_exist(folder)
20
29
  FileUtils.mkdir_p(folder) unless File.exist?(folder)
21
30
  end
22
-
23
31
  end
24
- end
32
+ end
@@ -1,3 +1,3 @@
1
1
  module Jack
2
- VERSION = "0.1.6"
3
- end
2
+ VERSION = "0.2.0"
3
+ end
@@ -15,11 +15,11 @@ describe Jack::Config do
15
15
  download.download
16
16
  end
17
17
 
18
- it "should add jack/cfg/*.yml to gitignore" do
19
- download.download
20
- ignore = IO.read("#{@root}/.gitignore")
21
- expect(ignore).to include("jack/cfg")
22
- end
18
+ # it "should add jack/cfg/*.yml to gitignore" do
19
+ # download.download
20
+ # ignore = IO.read("#{@root}/.gitignore")
21
+ # expect(ignore).to include("jack/cfg")
22
+ # end
23
23
 
24
24
  end
25
- end
25
+ end
@@ -5,7 +5,7 @@ describe Jack::Config::Upload do
5
5
  Jack::UI.mute = true
6
6
  end
7
7
 
8
- let(:upload) { Jack::Config::Upload.new(test_options.merge(silent: true)) }
8
+ let(:upload) { Jack::Config::Upload.new(test_options.merge(mute: true)) }
9
9
 
10
10
  describe "upload" do
11
11
  it "upload code paths" do
@@ -23,4 +23,4 @@ describe Jack::Config::Upload do
23
23
  upload.run
24
24
  end
25
25
  end
26
- end
26
+ end
@@ -2,6 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Jack::Create do
4
4
  before(:all) do
5
+ Jack::UI.mute = true
5
6
  @create = Jack::Create.new(test_options)
6
7
  end
7
8
 
@@ -16,4 +17,4 @@ describe Jack::Create do
16
17
  expect(command).to include('stag-rails-app-s9')
17
18
  end
18
19
  end
19
- end
20
+ end
@@ -3,31 +3,55 @@ require 'spec_helper'
3
3
  describe Jack::EbConfig do
4
4
  before(:all) do
5
5
  Jack::UI.mute = true
6
- fake_eb_config
7
6
  end
8
7
 
9
8
  def solution_stacks
10
- ["64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3", "64bit Amazon Linux 2014.03 v1.0.0 running Docker 1.0.0", "64bit Amazon Linux 2014.03 v1.0.1 running Docker 1.0.0", "64bit Amazon Linux 2014.03 v1.0.4 running Docker 0.9.0", "64bit Amazon Linux 2014.03 v1.0.5 running Docker 0.9.0", "64bit Debian jessie v1.2.0 running Go 1.3 (Preconfigured - Docker)", "64bit Debian jessie v1.2.0 running Go 1.4 (Preconfigured - Docker)"]
9
+ [
10
+ "64bit Amazon Linux 2015.03 v1.4.6 running Docker 1.6.2",
11
+ "64bit Amazon Linux 2015.09 v2.0.6 running Docker 1.7.1",
12
+ "64bit Amazon Linux 2016.03 v2.1.0 running Docker 1.9.1",
13
+ "64bit Debian jessie v2.1.0 running GlassFish 4.1 Java 8 (Preconfigured - Docker)",
14
+ "64bit Amazon Linux 2015.03 v1.4.6 running Multi-container Docker 1.6.2 (Generic)"
15
+ ]
11
16
  end
12
17
 
13
- let(:create) {
14
- Jack::EbConfig::Create.new(test_options)
15
- }
18
+ let(:create) do
19
+ Jack::EbConfig::Create.new(test_options(env_name))
20
+ end
21
+ let(:env_name) { "stag-rails-app-s9" }
16
22
 
17
- describe "create" do
18
- it "sync config" do
19
- expect(create).to receive(:solution_stacks).and_return(solution_stacks)
20
- create.sync
23
+ describe "Create#sync" do
24
+ context "default platform from default settings" do
25
+ it "have default platform from default settings" do
26
+ create.sync
27
+
28
+ data = YAML.load_file(create.eb_config_path)
29
+ global = data['global']
30
+ expect(global['application_name']).to eq "rails"
31
+ expect(global['default_platform']).to eq "64bit Amazon Linux 2015.03 v1.4.0 running Docker 1.6.0"
32
+ end
33
+ end
34
+
35
+ context "different platform from project settings" do
36
+ let(:env_name) { "rails-app-stag9" }
37
+
38
+ before(:each) { fake_project.create_settings }
39
+ after(:each) { fake_project.remove_settings }
40
+ it "have platform from project settings" do
41
+ create.sync
21
42
 
22
- data = YAML.load_file(create.eb_config_path)
23
- global = data['global']
24
- expect(global['application_name']).to eq "rails"
25
- expect(global['default_platform']).to eq "64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3"
43
+ data = YAML.load_file(create.eb_config_path)
44
+ global = data['global']
45
+ expect(global['application_name']).to eq "rails"
46
+ expect(global['default_platform']).to eq "Fake Platform From Project Settings"
47
+ end
26
48
  end
27
49
 
50
+ # To see newest solution stacks:
51
+ # aws elasticbeanstalk list-available-solution-stacks | jq '.SolutionStacks' | grep Docker
28
52
  it "list solution stacks" do
29
53
  expect(create).to receive(:solution_stacks).and_return(solution_stacks)
30
- expect(create.latest_docker_platform).to eq "64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3"
54
+ expect(create.latest_docker_platform).to eq "64bit Amazon Linux 2016.03 v2.1.0 running Docker 1.9.1"
31
55
  end
32
56
  end
33
- end
57
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jack::Settings do
4
+ before(:all) do
5
+ Jack::UI.mute = true
6
+ end
7
+ let(:settings) {
8
+ Jack::Settings.new(@root)
9
+ }
10
+
11
+ describe "create" do
12
+ context "custom project settings" do
13
+ before(:each) { fake_project.create_settings }
14
+ after(:each) { fake_project.remove_settings }
15
+ it "flags uses custom project settings" do
16
+ project_flags = '--keyname "default" --platform "Fake Platform From Project Settings"'
17
+ expect(settings.create_flags).to eq(project_flags)
18
+ end
19
+ end
20
+
21
+ context "no custom project settings" do
22
+ it "flags uses defaults provided gem" do
23
+ project_flags = '--keyname "default" --platform "64bit Amazon Linux 2015.03 v1.4.0 running Docker 1.6.0"'
24
+ expect(settings.create_flags).to eq(project_flags)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ # just for the spec
4
+ class Utilable
5
+ include Jack::Util
6
+ def initialize(root)
7
+ @root = root
8
+ end
9
+ end
10
+
11
+ describe Jack::Util do
12
+ before(:all) do
13
+ Jack::UI.mute = true
14
+ end
15
+ let(:util) do
16
+ Utilable.new(@root)
17
+ end
18
+
19
+ describe "util" do
20
+ it "app_name_convention default" do
21
+ app_name = util.app_name_convention("prod-rails-web-s1")
22
+ expect(app_name).to eq "rails"
23
+ end
24
+
25
+ context "custom app_name_convention" do
26
+ before(:each) { fake_project.create_settings }
27
+ after(:each) { fake_project.remove_settings }
28
+ it "app_name_convention from project settings.yml" do
29
+ app_name = util.app_name_convention("rails-web-prod1")
30
+ expect(app_name).to eq "rails"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -5,10 +5,13 @@ CodeClimate::TestReporter.start
5
5
 
6
6
  require "pp"
7
7
  require 'ostruct'
8
+ require 'pry'
8
9
 
9
10
  root = File.expand_path('../../', __FILE__)
10
11
  require "#{root}/lib/jack"
11
12
 
13
+ require "#{root}/spec/support/fake_project"
14
+
12
15
  module Helpers
13
16
  def execute(cmd)
14
17
  puts "Running: #{cmd}" if ENV['DEBUG']
@@ -17,38 +20,31 @@ module Helpers
17
20
  out
18
21
  end
19
22
 
20
- def test_options
23
+ def test_options(env_name="stag-rails-app-s9")
21
24
  {
22
25
  noop: true,
23
26
  mute: true,
24
27
  force: true,
25
28
  root: @root,
26
- env_name: "stag-rails-app-s9"
29
+ env_name: env_name
27
30
  }
28
31
  end
29
32
 
30
- def fake_eb_config
31
- data = <<-EOL
32
- ---
33
- global:
34
- application_name: blah
35
- default_platform: 64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3
36
- EOL
37
- path = "#{@root}/.elasticbeanstalk/config.yml"
38
- dir = File.dirname(path)
39
- FileUtils.mkdir_p(dir) unless File.exist?(path)
40
- File.write(path, data) unless File.exist?(path)
33
+ def fake_project
34
+ return @fake_project if @fake_project
35
+ @fake_project = FakeProject.new(@root)
36
+ @fake_project.create_eb_config
37
+ @fake_project
41
38
  end
42
-
43
39
  end
44
40
 
45
41
  RSpec.configure do |c|
46
42
  c.include Helpers
47
43
  c.before :all do
48
- @root = "spec/fixtures/project"
49
- fake_eb_config
44
+ @root = "spec/fixtures/project" # @root is being treated as a global with specs
45
+ fake_project
50
46
  end
51
47
  c.after :all do
52
48
  FileUtils.rm_f("#{@root}/.gitignore")
53
49
  end
54
- end
50
+ end
@@ -0,0 +1,51 @@
1
+ class FakeProject
2
+ def initialize(root)
3
+ @root = root || '.'
4
+ end
5
+
6
+ def create_eb_config
7
+ data = <<-EOL
8
+ ---
9
+ global:
10
+ application_name: blah
11
+ default_platform: 64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3
12
+ EOL
13
+ path = "#{@root}/.elasticbeanstalk/config.yml"
14
+ create_file(path, data)
15
+ end
16
+
17
+ def create_settings
18
+ data = <<-EOL
19
+ create:
20
+ keyname: default
21
+ platform: "Fake Platform From Project Settings"
22
+ conventions:
23
+ app_name_pattern: (\\w+)-\\w+-\\w+
24
+ EOL
25
+ # really tricky but when writting yaml file like this the \ needs to be escaped
26
+ # when writing the yaml file normal, they do not need to be escaped
27
+ create_file(settings_path, data)
28
+ end
29
+
30
+ def remove_settings
31
+ remove_file(settings_path)
32
+ end
33
+
34
+ def settings_path
35
+ "#{@root}/jack/settings.yml"
36
+ end
37
+
38
+ def create_file(path, contents)
39
+ ensure_parent_folder(path)
40
+ File.write(path, contents) unless File.exist?(path)
41
+ end
42
+
43
+ def remove_file(path)
44
+ FileUtils.rm_f(path)
45
+ end
46
+
47
+ def ensure_parent_folder(path)
48
+ dir = File.dirname(path)
49
+ FileUtils.mkdir_p(dir) unless File.exist?(path)
50
+ end
51
+ end
metadata CHANGED
@@ -1,125 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jack-eb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-28 00:00:00.000000000 Z
11
+ date: 2016-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: colorize
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: aws-sdk
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
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
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: guard
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - '>='
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
103
  version: '0'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - '>='
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: guard-bundler
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - '>='
115
+ - - ">="
102
116
  - !ruby/object:Gem::Version
103
117
  version: '0'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - '>='
122
+ - - ">="
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: guard-rspec
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - '>='
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
131
  version: '0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - '>='
136
+ - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
139
  description: Wrapper tool to manage AWS Elastic Beanstalk environments
@@ -130,9 +144,9 @@ executables:
130
144
  extensions: []
131
145
  extra_rdoc_files: []
132
146
  files:
133
- - .gitignore
134
- - .rspec
135
- - .travis.yml
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
136
150
  - Gemfile
137
151
  - Guardfile
138
152
  - LICENSE.txt
@@ -151,13 +165,13 @@ files:
151
165
  - lib/jack/config/upload.rb
152
166
  - lib/jack/config/yaml_formatter.rb
153
167
  - lib/jack/create.rb
154
- - lib/jack/create_yaml.rb
155
- - lib/jack/default/create.yml
168
+ - lib/jack/default/settings.yml
156
169
  - lib/jack/eb_config.rb
157
170
  - lib/jack/eb_config/base.rb
158
171
  - lib/jack/eb_config/create.rb
159
172
  - lib/jack/eb_config/update.rb
160
173
  - lib/jack/ext/hash.rb
174
+ - lib/jack/settings.rb
161
175
  - lib/jack/ui.rb
162
176
  - lib/jack/util.rb
163
177
  - lib/jack/version.rb
@@ -172,11 +186,13 @@ files:
172
186
  - spec/lib/config/yaml_formatter_spec.rb
173
187
  - spec/lib/config_spec.rb
174
188
  - spec/lib/create_spec.rb
175
- - spec/lib/create_yaml_spec.rb
176
189
  - spec/lib/eb_config/create_spec.rb
177
190
  - spec/lib/eb_config/update_spec.rb
191
+ - spec/lib/settings_spec.rb
192
+ - spec/lib/util_spec.rb
178
193
  - spec/lib/verison_checker_spec.rb
179
194
  - spec/spec_helper.rb
195
+ - spec/support/fake_project.rb
180
196
  homepage: ''
181
197
  licenses:
182
198
  - MIT
@@ -187,17 +203,17 @@ require_paths:
187
203
  - lib
188
204
  required_ruby_version: !ruby/object:Gem::Requirement
189
205
  requirements:
190
- - - '>='
206
+ - - ">="
191
207
  - !ruby/object:Gem::Version
192
208
  version: '0'
193
209
  required_rubygems_version: !ruby/object:Gem::Requirement
194
210
  requirements:
195
- - - '>='
211
+ - - ">="
196
212
  - !ruby/object:Gem::Version
197
213
  version: '0'
198
214
  requirements: []
199
215
  rubyforge_project:
200
- rubygems_version: 2.0.14
216
+ rubygems_version: 2.6.4
201
217
  signing_key:
202
218
  specification_version: 4
203
219
  summary: Wrapper tool to manage AWS Elastic Beanstalk environments
@@ -212,9 +228,11 @@ test_files:
212
228
  - spec/lib/config/yaml_formatter_spec.rb
213
229
  - spec/lib/config_spec.rb
214
230
  - spec/lib/create_spec.rb
215
- - spec/lib/create_yaml_spec.rb
216
231
  - spec/lib/eb_config/create_spec.rb
217
232
  - spec/lib/eb_config/update_spec.rb
233
+ - spec/lib/settings_spec.rb
234
+ - spec/lib/util_spec.rb
218
235
  - spec/lib/verison_checker_spec.rb
219
236
  - spec/spec_helper.rb
237
+ - spec/support/fake_project.rb
220
238
  has_rdoc:
@@ -1,22 +0,0 @@
1
- module Jack
2
- class CreateYaml
3
- def data
4
- return @create_yaml if @create_yaml
5
-
6
- project_file = "#{@root}/jack/create.yml"
7
- project = File.exist?(project_file) ? YAML.load_file(project_file) : {}
8
-
9
- user_file = "#{ENV['HOME']}/.jack/create.yml"
10
- user = File.exist?(user_file) ? YAML.load_file(user_file) : {}
11
-
12
- default_file = File.expand_path("../default/create.yml", __FILE__)
13
- default = YAML.load_file(default_file)
14
-
15
- @create_yaml = default.merge(project.merge(user))
16
- end
17
-
18
- def flags
19
- data.inject("") {|s,(k,v)| s << %{--#{k} "#{v}" } ; s }.strip
20
- end
21
- end
22
- end
@@ -1 +0,0 @@
1
- keyname: default
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Jack::CreateYaml do
4
- before(:all) do
5
- Jack::UI.mute = true
6
- end
7
-
8
- let(:create_yaml) {
9
- Jack::CreateYaml.new
10
- }
11
-
12
- describe "create" do
13
- it "flags" do
14
- expect(create_yaml.flags).to eq('--keyname "default"')
15
- end
16
- end
17
- end