jack-eb 0.0.3 → 0.0.4

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: dc83fe99fffa027536020c3af625b3c913689a4f
4
- data.tar.gz: e50d09ae4262c8a8773e0998dc89ab8c38e5f35f
3
+ metadata.gz: ba4de20f714331851a67992e8cbb3ddc5e2cea89
4
+ data.tar.gz: b545d2eaff2496ca3c506c8707ef4cd75e4ca143
5
5
  SHA512:
6
- metadata.gz: 2f129606547e21227dca1ade82c18ef6503c95a867745d9b4f9be4b1e6047c74d5d8e0b065a2392e0c3e239f46f45c197a31c21f1c0e50f28029f1ba94198669
7
- data.tar.gz: dea17503021a938ed10515d8be103f5201828594fba59c77a5a0c075ab32b8d2947e0545cc09a97130029a46594290deb490aef08d62cf0fc1115f40ac391eb7
6
+ metadata.gz: 2328f1cfefc1c29483d7ae00f46fc2d21bffb9406d5c5d64df76a6a1352669c6ed26859ffb762aa35b3bc146ea33385ea19093a733c723c120703566bcb03e2f
7
+ data.tar.gz: 8289fb3aa1a99504edd6ac8e89032b73a2a8712c5b19e7e6419c6fb835bdce42fa2ae0ea9095ae32549901e24b1684c343440f63e18a1a66f4aa81fdefe186bb
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jack-eb (0.0.1)
4
+ jack-eb (0.0.3)
5
5
  aws-sdk (~> 2)
6
6
  colorize
7
7
  thor
@@ -9,15 +9,15 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- aws-sdk (2.0.29)
13
- aws-sdk-resources (= 2.0.29)
14
- aws-sdk-core (2.0.29)
12
+ aws-sdk (2.0.28)
13
+ aws-sdk-resources (= 2.0.28)
14
+ aws-sdk-core (2.0.28)
15
15
  builder (~> 3.0)
16
16
  jmespath (~> 1.0)
17
17
  multi_json (~> 1.0)
18
18
  multi_xml (~> 0.5)
19
- aws-sdk-resources (2.0.29)
20
- aws-sdk-core (= 2.0.29)
19
+ aws-sdk-resources (2.0.28)
20
+ aws-sdk-core (= 2.0.28)
21
21
  builder (3.2.2)
22
22
  celluloid (0.16.0)
23
23
  timers (~> 4.0.0)
@@ -7,6 +7,8 @@ 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'
11
+ autoload :EbConfig, 'jack/eb_config'
10
12
  autoload :Config, 'jack/config'
11
13
  autoload :UI, 'jack/ui'
12
14
  autoload :Util, 'jack/util'
@@ -12,7 +12,7 @@ module Jack
12
12
  super
13
13
  @current_path = "#{@saved_configs}/current-#{timestamp}.cfg.yml"
14
14
  @current_name = extract_name(@current_path)
15
- sync_eb_config_yml
15
+ EbConfig::Update.new(env_name: @env_name).sync unless options[:noop]
16
16
  end
17
17
 
18
18
  def run
@@ -11,7 +11,7 @@ module Jack
11
11
  @options = options
12
12
  @root = options[:root] || '.'
13
13
  @env_name = options[:env_name]
14
- @app_name = @options[:app_name] || app_name_convention(@env_name)
14
+ @app_name = @options[:app] || app_name_convention(@env_name)
15
15
 
16
16
  @saved_configs = "#{@root}/.elasticbeanstalk/saved_configs"
17
17
 
@@ -19,46 +19,6 @@ module Jack
19
19
  @local_config_path = "jack/cfg/#{local_config_name}.cfg.yml"
20
20
  end
21
21
 
22
- def eb_config_path
23
- "#{@root}/.elasticbeanstalk/config.yml"
24
- end
25
-
26
- def sync_eb_config_yml(force=false)
27
- # should break out to another class but too much work right now
28
- create = Create.new(@options)
29
- create.ensure_eb_init
30
- do_sync_eb_config_yml(force)
31
- end
32
-
33
- private
34
-
35
- # force flag for specs
36
- def do_sync_eb_config_yml(force)
37
- return if @options[:noop] and !force
38
- envs = describe_environments
39
- env = envs[:environments].first
40
- if env
41
- write_eb_config_yml(env.application_name, env.solution_stack_name)
42
- else
43
- UI.say "#{@env_name} could not be found".colorize(:red)
44
- exit 0
45
- end
46
- end
47
-
48
- def write_eb_config_yml(application_name, solution_stack_name)
49
- data = YAML.load_file(eb_config_path)
50
- data['global']['application_name'] = application_name
51
- data['global']['default_platform'] = solution_stack_name
52
- dump = YAML.dump(data).gsub("!ruby/object:Hash", '')
53
- dump = dump.split("\n")[1..-1].join("\n") # strip first line
54
- File.write(eb_config_path, dump)
55
- end
56
-
57
- # useful for specs
58
- def describe_environments
59
- eb.describe_environments(environment_names: [@env_name])
60
- end
61
-
62
22
  def config_name_convention(env_name)
63
23
  env_name.split('-')[0..-2].join('-')
64
24
  end
@@ -88,10 +88,6 @@ EOL
88
88
  FileUtils.rm_f(@upload_path)
89
89
  end
90
90
 
91
- def ensure_folder_exist(folder)
92
- FileUtils.mkdir_p(folder) unless File.exist?(folder)
93
- end
94
-
95
91
  end
96
92
  end
97
93
  end
@@ -8,44 +8,14 @@ module Jack
8
8
  @options = options
9
9
  @root = options[:root] || '.'
10
10
  @env_name = options[:env_name]
11
- @app_name = options[:app_name] || app_name_convention(@env_name)
12
- @upload = Config::Upload.new(@options)
11
+ @app_name = options[:app] || app_name_convention(@env_name)
13
12
  end
14
13
 
15
14
  def run
16
- ensure_eb_init
15
+ EbConfig::Create.new(@options).sync unless @options[:noop]
17
16
  create_env
18
17
  end
19
18
 
20
- def ensure_eb_init
21
- if app_name_mismatch
22
- do_cmd(%Q|eb init -p "#{platform}" "#{@app_name}"|, @options)
23
- end
24
- end
25
-
26
- def app_name_mismatch
27
- return true unless File.exist?("#{@root}/.elasticbeanstalk/config.yml")
28
- return if @options[:noop]
29
- eb_config_path = @upload.eb_config_path
30
- data = YAML.load_file(eb_config_path)
31
- application_name = data['global']['application_name']
32
- application_name != @app_name
33
- end
34
-
35
- def platform
36
- create_yaml['platform'] || latest_docker_platform
37
- end
38
-
39
- def latest_docker_platform
40
- return if @options[:noop] # for cli spec
41
- solution_stacks.grep(/Docker/).reject {|x| x =~ /Preconfigured/}.sort.last
42
- end
43
-
44
- # for specs
45
- def solution_stacks
46
- eb.list_available_solution_stacks.solution_stacks
47
- end
48
-
49
19
  def create_env
50
20
  command = build_command
51
21
  do_cmd(command, @options)
@@ -53,26 +23,12 @@ module Jack
53
23
 
54
24
  def build_command
55
25
  @cfg = upload_cfg
56
- flags = create_yaml.inject("") {|s,(k,v)| s << %{--#{k} "#{v}" } ; s }.strip
26
+ flags = CreateYaml.new.flags
57
27
  "eb create --nohang #{flags} #{@cfg}#{cname}#{@env_name}"
58
28
  end
59
29
 
60
- def create_yaml
61
- return @create_yaml if @create_yaml
62
-
63
- project_file = "#{@root}/jack/create.yml"
64
- project = File.exist?(project_file) ? YAML.load_file(project_file) : {}
65
-
66
- user_file = "#{ENV['HOME']}/.jack/create.yml"
67
- user = File.exist?(user_file) ? YAML.load_file(user_file) : {}
68
-
69
- default_file = File.expand_path("../default/create.yml", __FILE__)
70
- default = YAML.load_file(default_file)
71
-
72
- @create_yaml = default.merge(project.merge(user))
73
- end
74
-
75
30
  def upload_cfg
31
+ @upload = Config::Upload.new(@options.merge(skip_sync: true))
76
32
  if @upload.local_cfg_exist?
77
33
  @upload.upload
78
34
  cfg = "--cfg #{@upload.upload_name} "
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,9 @@
1
+ require 'fileutils'
2
+
3
+ module Jack
4
+ module EbConfig
5
+ autoload :Base, 'jack/eb_config/base'
6
+ autoload :Update, 'jack/eb_config/update'
7
+ autoload :Create, 'jack/eb_config/create'
8
+ end
9
+ end
@@ -0,0 +1,38 @@
1
+ module Jack
2
+ module EbConfig
3
+ # Abstract Class
4
+ # Concrete classes should implement methods: platform and app_name
5
+ class Base
6
+ include Util
7
+
8
+ attr_reader :eb_config_path
9
+ def initialize(options={})
10
+ @options = options
11
+ @root = options[:root] || '.'
12
+ @env_name = options[:env_name]
13
+ @eb_config_path = "#{@root}/.elasticbeanstalk/config.yml"
14
+ ensure_folder_exist(@eb_config_path)
15
+ end
16
+
17
+ def sync
18
+ ensure_eb_init
19
+ write_eb_config_yml
20
+ end
21
+
22
+ def ensure_eb_init
23
+ unless File.exist?(eb_config_path)
24
+ do_cmd(%Q|eb init -p "#{platform}" "#{app_name}"|, @options)
25
+ end
26
+ end
27
+
28
+ def write_eb_config_yml
29
+ data = YAML.load_file(eb_config_path)
30
+ data['global']['application_name'] = app_name
31
+ data['global']['default_platform'] = platform
32
+ dump = YAML.dump(data).gsub("!ruby/object:Hash", '')
33
+ dump = dump.split("\n")[1..-1].join("\n") # strip first line
34
+ File.write(eb_config_path, dump)
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,28 @@
1
+ module Jack
2
+ module EbConfig
3
+ class Create < Base
4
+ attr_reader :eb_config_path
5
+ def initialize(options={})
6
+ super
7
+ @app_name = options[:app] || app_name_convention(@env_name)
8
+ end
9
+
10
+ def platform
11
+ CreateYaml.new.data['platform'] || latest_docker_platform
12
+ end
13
+
14
+ def app_name
15
+ @app_name
16
+ end
17
+
18
+ def latest_docker_platform
19
+ solution_stacks.grep(/Docker/).reject {|x| x =~ /Preconfigured/}.sort.last
20
+ end
21
+
22
+ def solution_stacks
23
+ eb.list_available_solution_stacks.solution_stacks
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ module Jack
2
+ module EbConfig
3
+ class Update < Base
4
+ attr_reader :eb_config_path
5
+ def initialize(options={})
6
+ super
7
+ end
8
+
9
+ def platform
10
+ env.solution_stack_name
11
+ end
12
+
13
+ def app_name
14
+ env.application_name
15
+ end
16
+
17
+ def env
18
+ return @env if @env
19
+ envs = describe_environments
20
+ @env = envs[:environments].first
21
+ end
22
+
23
+ # useful for specs
24
+ def describe_environments
25
+ eb.describe_environments(environment_names: [@env_name])
26
+ end
27
+ end
28
+ end
29
+ end
@@ -16,5 +16,9 @@ module Jack
16
16
  @@eb ||= Aws::ElasticBeanstalk::Client.new(region: region)
17
17
  end
18
18
 
19
+ def ensure_folder_exist(folder)
20
+ FileUtils.mkdir_p(folder) unless File.exist?(folder)
21
+ end
22
+
19
23
  end
20
24
  end
@@ -1,3 +1,3 @@
1
1
  module Jack
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,41 +1,26 @@
1
1
  require 'spec_helper'
2
- require 'ostruct'
3
2
 
4
3
  describe Jack::Config do
5
4
  before(:all) do
6
5
  Jack::UI.mute = true
7
- fake_eb_config
8
6
  end
9
7
 
10
8
  let(:transmit) { Jack::Config::Transmit.new(test_options) }
11
9
 
12
- def fake_eb_config
13
- input = <<-EOL
14
- ---
15
- global:
16
- application_name: blah
17
- default_platform: 64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3
18
- EOL
19
- file = "#{@root}/.elasticbeanstalk/config.yml"
20
- File.open(file, 'w') { |file| file.write(input) }
21
- end
22
-
23
- def mock
24
- {environments: [OpenStruct.new(
25
- application_name: "myapp",
26
- solution_stack_name: "my solution stack")]}
27
- end
28
-
29
10
  describe "transmit" do
30
- it "sync_eb_config_yml" do
31
- expect(transmit).to receive(:describe_environments).and_return(mock)
32
- transmit.sync_eb_config_yml(true)
11
+ it "config_name_convention" do
12
+ name = transmit.config_name_convention("stag-rails-app-s9")
13
+ expect(name).to eq "stag-rails-app"
14
+ end
33
15
 
34
- data = YAML.load_file(transmit.eb_config_path)
35
- global = data['global']
36
- expect(global['application_name']).to eq "myapp"
37
- expect(global['default_platform']).to eq "my solution stack"
16
+ it "timestamp" do
17
+ timestamp = transmit.timestamp
18
+ expect(timestamp).to be_a(String)
38
19
  end
39
20
 
21
+ it "extract_name" do
22
+ name = transmit.extract_name("/app/.elasticbeanstalk/saved_cofnigs/stag-rails-app.cfg.yml")
23
+ expect(name).to eq "stag-rails-app"
24
+ end
40
25
  end
41
26
  end
@@ -5,10 +5,6 @@ describe Jack::Create do
5
5
  @create = Jack::Create.new(test_options)
6
6
  end
7
7
 
8
- def solution_stacks
9
- ["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)"]
10
- end
11
-
12
8
  describe "jack" do
13
9
  it "create environment" do
14
10
  command = @create.build_command
@@ -19,16 +15,5 @@ describe Jack::Create do
19
15
  expect(command).to include('--cfg stag-rails-app')
20
16
  expect(command).to include('stag-rails-app-s9')
21
17
  end
22
-
23
- it "create_yaml" do
24
- data = @create.create_yaml
25
- expect(data["keyname"]).to eq "default"
26
- end
27
-
28
- it "list solution stacks" do
29
- @create = Jack::Create.new(test_options.merge(noop: false))
30
- expect(@create).to receive(:solution_stacks).and_return(solution_stacks)
31
- expect(@create.latest_docker_platform).to eq "64bit Amazon Linux 2014.09 v1.2.0 running Docker 1.3.3"
32
- end
33
18
  end
34
19
  end
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jack::EbConfig do
4
+ before(:all) do
5
+ Jack::UI.mute = true
6
+ fake_eb_config
7
+ end
8
+
9
+ 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)"]
11
+ end
12
+
13
+ let(:create) {
14
+ Jack::EbConfig::Create.new(test_options)
15
+ }
16
+
17
+ describe "create" do
18
+ it "sync config" do
19
+ expect(create).to receive(:solution_stacks).and_return(solution_stacks)
20
+ create.sync
21
+
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"
26
+ end
27
+
28
+ it "list solution stacks" do
29
+ 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"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Jack::EbConfig do
4
+ before(:all) do
5
+ Jack::UI.mute = true
6
+ end
7
+
8
+ def mock
9
+ {environments: [OpenStruct.new(
10
+ application_name: "myapp",
11
+ solution_stack_name: "my solution stack")]}
12
+ end
13
+
14
+ let(:update) {
15
+ Jack::EbConfig::Update.new(test_options)
16
+ }
17
+
18
+ describe "update" do
19
+ it "sync config" do
20
+ expect(update).to receive(:describe_environments).and_return(mock)
21
+ update.sync
22
+
23
+ data = YAML.load_file(update.eb_config_path)
24
+ global = data['global']
25
+ expect(global['application_name']).to eq "myapp"
26
+ expect(global['default_platform']).to eq "my solution stack"
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -4,6 +4,7 @@ require "codeclimate-test-reporter"
4
4
  CodeClimate::TestReporter.start
5
5
 
6
6
  require "pp"
7
+ require 'ostruct'
7
8
 
8
9
  root = File.expand_path('../../', __FILE__)
9
10
  require "#{root}/lib/jack"
@@ -25,6 +26,18 @@ module Helpers
25
26
  env_name: "stag-rails-app-s9"
26
27
  }
27
28
  end
29
+
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
+ File.write(path, data) unless File.exist?(path)
39
+ end
40
+
28
41
  end
29
42
 
30
43
  RSpec.configure do |c|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jack-eb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -152,7 +152,12 @@ files:
152
152
  - lib/jack/config/upload.rb
153
153
  - lib/jack/config/yaml_formatter.rb
154
154
  - lib/jack/create.rb
155
+ - lib/jack/create_yaml.rb
155
156
  - lib/jack/default/create.yml
157
+ - lib/jack/eb_config.rb
158
+ - lib/jack/eb_config/base.rb
159
+ - lib/jack/eb_config/create.rb
160
+ - lib/jack/eb_config/update.rb
156
161
  - lib/jack/ext/hash.rb
157
162
  - lib/jack/ui.rb
158
163
  - lib/jack/util.rb
@@ -169,6 +174,9 @@ files:
169
174
  - spec/lib/config/yaml_formatter_spec.rb
170
175
  - spec/lib/config_spec.rb
171
176
  - spec/lib/create_spec.rb
177
+ - spec/lib/create_yaml_spec.rb
178
+ - spec/lib/eb_config/create_spec.rb
179
+ - spec/lib/eb_config/update_spec.rb
172
180
  - spec/lib/verison_checker_spec.rb
173
181
  - spec/spec_helper.rb
174
182
  homepage: ''
@@ -207,5 +215,8 @@ test_files:
207
215
  - spec/lib/config/yaml_formatter_spec.rb
208
216
  - spec/lib/config_spec.rb
209
217
  - spec/lib/create_spec.rb
218
+ - spec/lib/create_yaml_spec.rb
219
+ - spec/lib/eb_config/create_spec.rb
220
+ - spec/lib/eb_config/update_spec.rb
210
221
  - spec/lib/verison_checker_spec.rb
211
222
  - spec/spec_helper.rb