jack-eb 1.0.1 → 1.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/circle.yml +3 -0
- data/lib/jack.rb +2 -0
- data/lib/jack/cli.rb +18 -13
- data/lib/jack/config.rb +1 -0
- data/lib/jack/config/diff.rb +11 -6
- data/lib/jack/config/download.rb +2 -2
- data/lib/jack/config/help.rb +70 -0
- data/lib/jack/config/upload.rb +23 -25
- data/lib/jack/create.rb +4 -3
- data/lib/jack/eb_config/base.rb +1 -1
- data/lib/jack/eb_config/update.rb +6 -2
- data/lib/jack/help.rb +59 -0
- data/lib/jack/terminate.rb +23 -0
- data/lib/jack/util.rb +147 -23
- data/lib/jack/version.rb +1 -1
- data/lib/jack/version_checker.rb +8 -6
- data/spec/lib/cli_spec.rb +9 -3
- data/spec/lib/config/diff_spec.rb +3 -3
- data/spec/lib/config/upload_spec.rb +2 -0
- data/spec/lib/verison_checker_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -1
- metadata +6 -4
- data/.travis.yml +0 -4
- data/lib/jack/cli/help.rb +0 -107
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a12aefa1e04666526e9afa664b848c27ab22c4a7
|
4
|
+
data.tar.gz: e0d8f2f0dd5b415bcd7381ed38de4ada5c31c714
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8964f711975df4c4bac1b028592639a6bbf16998246c1fbbabf38ebb4bd7ef3bda9779591c08c48c999a1c43a2f03a5024b826cfe18289181372be1b1975a235
|
7
|
+
data.tar.gz: 3d6c0322d650e684d0bad994addc80dbab14a5c2bedbaddf6d5bb4b69b6d7500bda53543fba86161949bed836bfab18fb01f2ad9c9d624a81ca79c2c605383b1
|
data/CHANGELOG.md
CHANGED
@@ -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.1.0]
|
7
|
+
- add jack terminate
|
8
|
+
- refactoring: https://github.com/tongueroo/jack/pull/6
|
9
|
+
- autodetect eb_bin and aws_bin
|
10
|
+
|
6
11
|
## [1.0.1]
|
7
12
|
- improve jack eb install error message
|
8
13
|
|
data/README.md
CHANGED
@@ -161,7 +161,7 @@ $ jack config upload hi-web-prod-1 --app customappname
|
|
161
161
|
|
162
162
|
This will save the config to `jack/cfg/hi-web-prod-1.cfg.yml`.
|
163
163
|
|
164
|
-
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
|
164
|
+
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 `--sure` option.
|
165
165
|
|
166
166
|
#### Diff Config - Comparing your local config to the live environment config
|
167
167
|
|
data/circle.yml
ADDED
data/lib/jack.rb
CHANGED
@@ -6,8 +6,10 @@ require File.expand_path("../jack/ext/hash", __FILE__)
|
|
6
6
|
|
7
7
|
module Jack
|
8
8
|
autoload :Command, 'jack/command'
|
9
|
+
autoload :Help, 'jack/help'
|
9
10
|
autoload :CLI, 'jack/cli'
|
10
11
|
autoload :Create, 'jack/create'
|
12
|
+
autoload :Terminate, 'jack/terminate'
|
11
13
|
autoload :Settings, 'jack/settings'
|
12
14
|
autoload :EbConfig, 'jack/eb_config'
|
13
15
|
autoload :Config, 'jack/config'
|
data/lib/jack/cli.rb
CHANGED
@@ -1,36 +1,35 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'jack/command'
|
3
|
-
require 'jack/cli/help'
|
4
3
|
require 'jack/version_checker'
|
5
4
|
Jack::VersionChecker.new.run unless ENV['TEST']
|
6
5
|
|
7
6
|
module Jack
|
8
7
|
class Config < Command
|
9
8
|
desc "upload ENV_NAME", "upload and apply jack config changes to EB environment"
|
10
|
-
long_desc
|
11
|
-
option :
|
9
|
+
long_desc Help.upload
|
10
|
+
option :sure, aliases: :f, type: :boolean, desc: "skip prompt"
|
12
11
|
def upload(env_name)
|
13
|
-
|
12
|
+
Upload.new(options.merge(env_name: env_name)).run
|
14
13
|
end
|
15
14
|
|
16
15
|
desc "download ENV_NAME", "downloads environment config to jack/cfg folder"
|
17
|
-
long_desc
|
16
|
+
long_desc Help.download
|
18
17
|
option :dirty, type: :boolean, desc: "leave the remote eb config and download config behind"
|
19
18
|
def download(env_name)
|
20
|
-
|
19
|
+
Download.new(options.merge(env_name: env_name)).run
|
21
20
|
end
|
22
21
|
|
23
22
|
desc "diff ENV_NAME", "diff jack config vs environment config"
|
24
|
-
long_desc
|
23
|
+
long_desc Help.diff
|
25
24
|
option :dirty, type: :boolean, desc: "leave the remote eb config and download config behind"
|
26
25
|
def diff(env_name)
|
27
|
-
|
26
|
+
Diff.new(options.merge(env_name: env_name)).run
|
28
27
|
end
|
29
28
|
|
30
29
|
desc "sort ENV_NAME", "reformat local jack config file to a sorted yaml file format"
|
31
|
-
long_desc
|
30
|
+
long_desc Help.sort
|
32
31
|
def sort(env_name)
|
33
|
-
|
32
|
+
Sort.new(options.merge(env_name: env_name)).run
|
34
33
|
end
|
35
34
|
end
|
36
35
|
|
@@ -38,7 +37,7 @@ module Jack
|
|
38
37
|
class_option :verbose, type: :boolean
|
39
38
|
class_option :mute, type: :boolean, desc: "mute all output, useful for specs"
|
40
39
|
class_option :noop, type: :boolean, desc: "dont run any destructive commands"
|
41
|
-
class_option :
|
40
|
+
class_option :sure, type: :boolean, desc: "bypass confirmation prompt"
|
42
41
|
class_option :root, :default => '.', desc: "root of the project, useful for specs"
|
43
42
|
class_option :cfg, aliases: :c, desc: "local config name if want to override the convention"
|
44
43
|
class_option :app, aliases: :a, desc: "app name if want to override the convention"
|
@@ -46,12 +45,18 @@ module Jack
|
|
46
45
|
desc "create ENV_NAME", "create EB environment"
|
47
46
|
long_desc Help.create
|
48
47
|
def create(env_name)
|
49
|
-
|
48
|
+
Create.new(options.merge(env_name: env_name)).run
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "terminate ENV_NAME", "deletes EB environment"
|
52
|
+
long_desc Help.terminate
|
53
|
+
def terminate(env_name)
|
54
|
+
Terminate.new(options.merge(env_name: env_name)).run
|
50
55
|
end
|
51
56
|
|
52
57
|
desc "version", "display jack version number"
|
53
58
|
def version
|
54
|
-
puts
|
59
|
+
puts VERSION
|
55
60
|
end
|
56
61
|
|
57
62
|
desc "config ACTION ENV_NAME", "manage environment config"
|
data/lib/jack/config.rb
CHANGED
data/lib/jack/config/diff.rb
CHANGED
@@ -11,19 +11,24 @@ module Jack
|
|
11
11
|
|
12
12
|
def run
|
13
13
|
@download.get_current_cfg
|
14
|
-
|
14
|
+
difference = compute_diff(@download.current_path, @download.local_config_path)
|
15
15
|
cleanup_files
|
16
|
+
difference
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
-
|
19
|
+
def compute_diff(current, local)
|
20
|
+
# the diff command returns 0 when there is no difference and returns 1 when there is a difference
|
21
|
+
pretty_current_path = @download.current_path.sub(/.*\.elasticbeanstalk/,'.elasticbeanstalk')
|
22
|
+
command = "#{diff_command} #{pretty_current_path} #{@download.local_config_path}"
|
23
|
+
UI.say("=> #{command}")
|
24
|
+
|
20
25
|
return if @options[:noop]
|
21
26
|
sorter = YamlFormatter.new
|
22
27
|
sorter.process(current)
|
23
28
|
sorter.process(local)
|
24
|
-
|
25
|
-
system(
|
26
|
-
|
29
|
+
|
30
|
+
no_difference = system(command)
|
31
|
+
!no_difference
|
27
32
|
end
|
28
33
|
|
29
34
|
def cleanup_files
|
data/lib/jack/config/download.rb
CHANGED
@@ -34,7 +34,7 @@ module Jack
|
|
34
34
|
ignores = IO.read(path)
|
35
35
|
has_ignore = ignores.include?("jack/cfg")
|
36
36
|
end
|
37
|
-
|
37
|
+
sh("echo 'jack/cfg/*.yml' >> #{path}") unless has_ignore
|
38
38
|
end
|
39
39
|
|
40
40
|
def get_current_cfg
|
@@ -44,7 +44,7 @@ module Jack
|
|
44
44
|
|
45
45
|
# for specs
|
46
46
|
def eb_config_save
|
47
|
-
|
47
|
+
sh("#{eb_bin} config save#{eb_base_flags} --cfg #{current_name} #{@env_name}", @options)
|
48
48
|
end
|
49
49
|
|
50
50
|
def copy_to_local_cfg
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class Jack::Config::Help
|
2
|
+
class << self
|
3
|
+
def upload
|
4
|
+
<<-EOL
|
5
|
+
Uploads the specified template configuration in jack/cfg and applies it to the environment immediately.
|
6
|
+
|
7
|
+
#{convention}
|
8
|
+
|
9
|
+
Example:
|
10
|
+
|
11
|
+
$ jack config upload hi-web-stag-1
|
12
|
+
|
13
|
+
$ jack config upload myapp -c myconfig hi-web-stag-1
|
14
|
+
EOL
|
15
|
+
end
|
16
|
+
|
17
|
+
def download
|
18
|
+
<<-EOL
|
19
|
+
Downloads the environment's config to jack/cfg/[CONFIG_NAME].cfg.yml
|
20
|
+
|
21
|
+
#{convention}
|
22
|
+
|
23
|
+
Example:
|
24
|
+
|
25
|
+
$ jack config download hi-web-stag-1
|
26
|
+
|
27
|
+
$ jack config download myapp -c myconfig hi-web-stag-1
|
28
|
+
EOL
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def diff
|
33
|
+
<<-EOL
|
34
|
+
Diff local jack config vs environment config. The environment config is generated on the fly.
|
35
|
+
|
36
|
+
If you have colordiff installed the diff command will use make use of it. If you want to have your own custom diff, you can set your JACK_DIFF environment variable to it.
|
37
|
+
|
38
|
+
#{convention}
|
39
|
+
|
40
|
+
Example:
|
41
|
+
|
42
|
+
$ jack config diff hi-web-stag-1
|
43
|
+
|
44
|
+
$ jack config diff myapp -c myconfig hi-web-stag-1
|
45
|
+
EOL
|
46
|
+
end
|
47
|
+
|
48
|
+
def sort
|
49
|
+
<<-EOL
|
50
|
+
Reformats local jack config file to a sorted yaml format.
|
51
|
+
|
52
|
+
#{convention}
|
53
|
+
|
54
|
+
Example:
|
55
|
+
|
56
|
+
$ jack config sort hi-web-stag-1
|
57
|
+
|
58
|
+
$ jack config sort -c myconfig hi-web-stag-1 # env name doesnt matter here
|
59
|
+
EOL
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
# duplicated in jack/help.rb
|
64
|
+
def convention
|
65
|
+
<<-EOL
|
66
|
+
The configuration name is based on convention. An environment with the name of hi-web-stag-1 results in the jack/cfg/hi-web-stag.cfg.yml being used. The convention can be overriden with the --cfg option.
|
67
|
+
EOL
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/jack/config/upload.rb
CHANGED
@@ -18,13 +18,31 @@ module Jack
|
|
18
18
|
UI.say "#{local_config_path} does not exist, nothing to upload"
|
19
19
|
exit 0
|
20
20
|
end
|
21
|
-
compare
|
22
|
-
if
|
23
|
-
|
24
|
-
|
21
|
+
difference = compare
|
22
|
+
if difference
|
23
|
+
if confirm(confirmation_message)
|
24
|
+
upload
|
25
|
+
update_env
|
26
|
+
else
|
27
|
+
UI.say("Whew, that was close. EB Configuration was not updated.")
|
28
|
+
end
|
29
|
+
else
|
30
|
+
UI.say("There was no difference detected from your #{@local_config_path} and what exists on the EB environment")
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
34
|
+
def confirmation_message
|
35
|
+
message = "Are you sure you want to update the environment with your the new config #{@local_config_path}?\n".colorize(:yellow)
|
36
|
+
message += <<-EOL
|
37
|
+
If the difference is not what you expected, you should say no.
|
38
|
+
If you want to download the config from the environment and get #{@local_config_path}
|
39
|
+
back in sync, you can use this command:
|
40
|
+
$ jack config download #{@env_name}
|
41
|
+
$ jack config download -h # for more info
|
42
|
+
EOL
|
43
|
+
message
|
44
|
+
end
|
45
|
+
|
28
46
|
def compare
|
29
47
|
Diff.new(@options).run
|
30
48
|
end
|
@@ -37,26 +55,6 @@ module Jack
|
|
37
55
|
clean_up
|
38
56
|
end
|
39
57
|
|
40
|
-
def confirm
|
41
|
-
UI.say("Are you sure you want to update the environment with your the new config #{@config_path}?".colorize(:yellow))
|
42
|
-
UI.say(<<-EOL)
|
43
|
-
If the difference is not what you expected, you should say no.
|
44
|
-
A blank newline indicates that there was no difference.
|
45
|
-
If you want to download the config from the environment and
|
46
|
-
overwrite your #{@local_config_path} instead, you can use this command:
|
47
|
-
$ jack config download #{@env_name}
|
48
|
-
$ jack config help download # for more info
|
49
|
-
EOL
|
50
|
-
print "yes/no? [no] " unless @options[:mute] || @options[:force]
|
51
|
-
answer = get_answer
|
52
|
-
answer =~ /^y/
|
53
|
-
end
|
54
|
-
|
55
|
-
def get_answer
|
56
|
-
return 'y' if @options[:force]
|
57
|
-
$stdin.gets
|
58
|
-
end
|
59
|
-
|
60
58
|
def update_env
|
61
59
|
UI.say("Updating environment #{@env_name} with template #{upload_name}")
|
62
60
|
eb.update_environment(
|
@@ -80,7 +78,7 @@ EOL
|
|
80
78
|
|
81
79
|
# for specs
|
82
80
|
def eb_config_put
|
83
|
-
|
81
|
+
sh("#{eb_bin} config put#{eb_base_flags} #{upload_name}", @options)
|
84
82
|
end
|
85
83
|
|
86
84
|
def clean_up
|
data/lib/jack/create.rb
CHANGED
@@ -12,6 +12,7 @@ module Jack
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def run
|
15
|
+
check_aws_setup
|
15
16
|
create_app
|
16
17
|
EbConfig::Create.new(@options).sync unless @options[:noop]
|
17
18
|
create_env
|
@@ -31,19 +32,19 @@ module Jack
|
|
31
32
|
|
32
33
|
def create_env
|
33
34
|
command = build_command
|
34
|
-
|
35
|
+
sh(command, @options)
|
35
36
|
end
|
36
37
|
|
37
38
|
def build_command
|
38
39
|
@cfg = upload_cfg
|
39
40
|
flags = settings.create_flags
|
40
|
-
"
|
41
|
+
"#{eb_bin} create#{eb_base_flags} --sample --nohang #{flags} #{@cfg}#{cname}#{@env_name}"
|
41
42
|
end
|
42
43
|
|
43
44
|
def upload_cfg
|
44
45
|
@upload = Config::Upload.new(@options)
|
45
46
|
if @upload.local_cfg_exist?
|
46
|
-
@upload.upload
|
47
|
+
@upload.upload
|
47
48
|
cfg = "--cfg #{@upload.upload_name} "
|
48
49
|
end
|
49
50
|
end
|
data/lib/jack/eb_config/base.rb
CHANGED
@@ -13,11 +13,15 @@ module Jack
|
|
13
13
|
def app_name
|
14
14
|
env.application_name
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def env
|
18
18
|
return @env if @env
|
19
19
|
envs = describe_environments
|
20
20
|
@env = envs[:environments].first
|
21
|
+
unless @env
|
22
|
+
abort("ERROR: Environment #{@env_name} not found. Are you sure it exists?".colorize(:red))
|
23
|
+
end
|
24
|
+
@env
|
21
25
|
end
|
22
26
|
|
23
27
|
# useful for specs
|
@@ -26,4 +30,4 @@ module Jack
|
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
29
|
-
end
|
33
|
+
end
|
data/lib/jack/help.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Jack
|
2
|
+
class Help
|
3
|
+
class << self
|
4
|
+
def create
|
5
|
+
<<-EOL
|
6
|
+
Creates a new environment using the configuration in jack/cfg folder. The AWS sample app is initially used for the newly created environment. The sample app is used as a starting point to make sure that the environment is working before you introduce your own app code.
|
7
|
+
|
8
|
+
#{convention}
|
9
|
+
|
10
|
+
Example:
|
11
|
+
|
12
|
+
$ jack create hi-web-stag-1
|
13
|
+
|
14
|
+
$ jack create -c myconfig hi-web-stag-1
|
15
|
+
|
16
|
+
$ jack create -a myapp -c myconfig hi-web-stag-1
|
17
|
+
EOL
|
18
|
+
end
|
19
|
+
|
20
|
+
def terminate
|
21
|
+
<<-EOL
|
22
|
+
Deletes Elastic Beanstalk environment.
|
23
|
+
|
24
|
+
Example:
|
25
|
+
|
26
|
+
$ jack terminate hi-web-stag-1
|
27
|
+
EOL
|
28
|
+
end
|
29
|
+
|
30
|
+
# Thor auto generates the subcommand help menu.
|
31
|
+
# Leaving here in case we figure out a way to override this Thor behavior.
|
32
|
+
def config
|
33
|
+
<<-EOL
|
34
|
+
Manage the environment's config. Can use this to download the environment's config to jack/cfg folder or upload config in jack/cfg folder and apply it to the environment.
|
35
|
+
|
36
|
+
Example:
|
37
|
+
|
38
|
+
$ jack config download hi-web-stag-1
|
39
|
+
|
40
|
+
For more info:
|
41
|
+
|
42
|
+
$ jack help config
|
43
|
+
|
44
|
+
$ jack config help upload
|
45
|
+
|
46
|
+
$ jack config help download
|
47
|
+
EOL
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
# duplicated in jack/config/help.rb
|
52
|
+
def convention
|
53
|
+
<<-EOL
|
54
|
+
The configuration name is based on convention. An environment with the name of hi-web-stag-1 results in the jack/cfg/hi-web-stag.cfg.yml being used. The convention can be overriden with the --cfg option.
|
55
|
+
EOL
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jack
|
2
|
+
class Terminate
|
3
|
+
include Util
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@options = options
|
7
|
+
@root = options[:root] || '.'
|
8
|
+
@env_name = options[:env_name]
|
9
|
+
@app_name = options[:app] || app_name_convention(@env_name)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
check_aws_setup
|
14
|
+
message = "Are you sure you want to delete the environment #{@env_name}?".colorize(:yellow)
|
15
|
+
if confirm(message) && !@options[:noop]
|
16
|
+
eb.terminate_environment(environment_name: @env_name)
|
17
|
+
UI.say("Environment #{@env_name} is terminating!")
|
18
|
+
else
|
19
|
+
UI.say("Whew that was close. Environment #{@env_name} was not deleted.")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/jack/util.rb
CHANGED
@@ -1,32 +1,156 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
# Any class that includes this module should define @root as it is used in
|
2
|
+
# the settings method.
|
3
|
+
module Jack::Util
|
4
|
+
def confirm(message)
|
5
|
+
Jack::UI.say(message)
|
6
|
+
print "yes/no? [no] " unless @options[:mute] || @options[:sure]
|
7
|
+
answer = get_answer
|
8
|
+
answer =~ /^y/
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_answer
|
12
|
+
return 'y' if @options[:sure]
|
13
|
+
$stdin.gets
|
14
|
+
end
|
15
|
+
|
16
|
+
def sh(command, options={})
|
17
|
+
Jack::UI.say "=> #{command.colorize(:green)}"
|
18
|
+
return command if options[:noop]
|
19
|
+
|
20
|
+
if options[:backtick]
|
8
21
|
out = `#{command}`
|
9
|
-
UI.say out
|
22
|
+
Jack::UI.say out
|
23
|
+
success = $?.success?
|
24
|
+
else
|
25
|
+
success = system(command)
|
10
26
|
end
|
11
27
|
|
12
|
-
|
13
|
-
|
14
|
-
env_name.match(pattern)[1]
|
15
|
-
end
|
28
|
+
abort "Exiting! Error running command: #{command}".colorize(:red) unless success
|
29
|
+
end
|
16
30
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
31
|
+
def app_name_convention(env_name)
|
32
|
+
pattern = settings.app_name_pattern
|
33
|
+
env_name.match(pattern)[1]
|
34
|
+
end
|
22
35
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
36
|
+
def settings
|
37
|
+
# do not like the instance @root variable in this module but better
|
38
|
+
# than having to pass settings around
|
39
|
+
@settings ||= Jack::Settings.new(@root)
|
40
|
+
end
|
41
|
+
|
42
|
+
def eb
|
43
|
+
@@eb ||= Aws::ElasticBeanstalk::Client.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def ensure_folder_exist(folder)
|
47
|
+
FileUtils.mkdir_p(folder) unless File.exist?(folder)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Checks main if the ~/.aws/config has been set up properly. If it has not
|
51
|
+
# print a message to the user and exit the program.
|
52
|
+
def check_aws_setup
|
53
|
+
# abusing `aws configure get region` to check that aws is probably properly configured
|
54
|
+
get_region # method will exits when unable to query for the region
|
55
|
+
end
|
56
|
+
|
57
|
+
# get the region from ~/.aws/config settings
|
58
|
+
# The eb tool reqiures you to specify the region when you run `eb init`. After that
|
59
|
+
# the setting is saved in the ~/.elasticbeanstalk folder. We will default to what
|
60
|
+
# is set in ~/.aws/config.
|
61
|
+
def get_region
|
62
|
+
return 'us-west-2' if ENV['TEST']
|
27
63
|
|
28
|
-
|
29
|
-
|
64
|
+
command = "#{aws_bin} configure get region"
|
65
|
+
region = `#{command}`.strip
|
66
|
+
success = $?.success?
|
67
|
+
unless success
|
68
|
+
abort <<~EOS.colorize(:red)
|
69
|
+
ERROR: Unable to infer the region from your ~/.aws/config settings with command: `#{command}`.
|
70
|
+
Maybe it is not properly configured? Please double check ~/.aws/config.
|
71
|
+
If you haven't set your region yet, ou can set your region with `aws configure set region REGION`. Example:
|
72
|
+
aws configure set region us-west-2
|
73
|
+
EOS
|
30
74
|
end
|
75
|
+
|
76
|
+
# Defaults to us-east-1:
|
77
|
+
# right now aws configure get region will actually return an error 1 code so we
|
78
|
+
# will never default to us-east-1 here but doing this just in case the return code
|
79
|
+
# changes to 0.
|
80
|
+
region == '' ? 'us-east-1' : region
|
81
|
+
end
|
82
|
+
|
83
|
+
@@aws_bin = nil
|
84
|
+
# Auto detects the aws binary for use, will use an aws binary based on the following precedence:
|
85
|
+
#
|
86
|
+
# 1. JACK_AWS_BIN environmental variable
|
87
|
+
# 2. aws detected using the load path.
|
88
|
+
# For example: /usr/bin/local/aws if /usr/bin/local/ is earlest in the load path.
|
89
|
+
# 3. /opt/bolts/embedded/bin/aws - This comes packaged with the the bolts toolbelt.
|
90
|
+
# https://boltops.com/toolbelt
|
91
|
+
#
|
92
|
+
# If an aws installation is not deetcted it'll display a message and exit the program.
|
93
|
+
def aws_bin
|
94
|
+
return @@aws_bin if @@aws_bin
|
95
|
+
|
96
|
+
return @@aws_bin = "aws" if ENV['TEST']
|
97
|
+
|
98
|
+
return @@aws_bin = ENV["JACK_AWS_BIN"] if ENV["JACK_AWS_BIN"]
|
99
|
+
|
100
|
+
which_aws = `which aws`.strip
|
101
|
+
return @@aws_bin = which_aws if which_aws
|
102
|
+
|
103
|
+
embedded_aws = "/opt/bolts/embedded/bin/aws"
|
104
|
+
return @@aws_bin = embedded_aws if File.exist?(embedded_aws)
|
105
|
+
|
106
|
+
# if reach here we did not detect the eb binary
|
107
|
+
message = "ERROR: Unable to auto detect an aws executable. Please make sure you have installed the aws cli tool.\n"
|
108
|
+
message << if RUBY_PLATFORM =~ /darwin/
|
109
|
+
"You can install the aws tool via homebrew:\n\nbrew install awscli"
|
110
|
+
else
|
111
|
+
"Installation instructions: http://docs.aws.amazon.com/cli/latest/userguide/installing.html"
|
112
|
+
end
|
113
|
+
abort(message)
|
114
|
+
end
|
115
|
+
|
116
|
+
@@eb_bin = nil
|
117
|
+
# Auto detects the eb binary for use, will use an eb binary based on the following precedence:
|
118
|
+
#
|
119
|
+
# 1. JACK_EB_BIN environmental variable
|
120
|
+
# 2. eb detected using the load path.
|
121
|
+
# For example: /usr/bin/local/eb if /usr/bin/local/ is earlest in the load path.
|
122
|
+
# 3. /opt/bolts/embedded/bin/eb - This comes packaged with the the bolts toolbelt.
|
123
|
+
# https://boltops.com/toolbelt
|
124
|
+
#
|
125
|
+
# If an eb installation is not deetcted it'll display a message and exit the program.
|
126
|
+
def eb_bin
|
127
|
+
return @@eb_bin if @@eb_bin
|
128
|
+
|
129
|
+
return @@eb_bin = "eb" if ENV['TEST']
|
130
|
+
|
131
|
+
return @@eb_bin = ENV["JACK_EB_BIN"] if ENV["JACK_EB_BIN"]
|
132
|
+
|
133
|
+
which_eb = `which eb`.strip
|
134
|
+
return @@eb_bin = which_eb if which_eb
|
135
|
+
|
136
|
+
embedded_eb = "/opt/bolts/embedded/bin/eb"
|
137
|
+
return @@eb_bin = embedded_eb if File.exist?(embedded_aws)
|
138
|
+
|
139
|
+
# if reach here we did not detect the eb binary
|
140
|
+
message = "ERROR: Unable to auto detect an eb executable. Please make sure you have installed the eb cli tool.\n"
|
141
|
+
instructions = VersionChecker.new.install_instructions
|
142
|
+
message << instructions
|
143
|
+
abort(message)
|
144
|
+
end
|
145
|
+
|
146
|
+
def eb_base_flags
|
147
|
+
return @eb_base_flags if @eb_base_flags
|
148
|
+
region = get_region
|
149
|
+
profile = ENV['AWS_PROFILE']
|
150
|
+
flags = {
|
151
|
+
profile: region ? " --profile #{profile}" : "",
|
152
|
+
region: region ? " -r #{region}" : ""
|
153
|
+
}
|
154
|
+
@eb_base_flags = "#{flags[:profile]}#{flags[:region]}"
|
31
155
|
end
|
32
156
|
end
|
data/lib/jack/version.rb
CHANGED
data/lib/jack/version_checker.rb
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
module Jack
|
2
2
|
class VersionChecker
|
3
3
|
REQUIRED_VERSION = "3.1.2"
|
4
|
+
include Util
|
4
5
|
|
5
6
|
def run
|
6
|
-
leave(not_installed) unless system("type
|
7
|
+
leave(not_installed) unless system("type #{eb_bin} > /dev/null 2>&1")
|
7
8
|
leave(version_too_low) unless check
|
8
|
-
# "SORRY: #{message}, please install at least version #{REQUIRED_VERSION}")
|
9
9
|
end
|
10
10
|
|
11
11
|
def check
|
12
|
-
major, minor, patch =
|
13
|
-
r_major, r_minor, r_patch =
|
12
|
+
major, minor, patch = version_parts(parsed_version)
|
13
|
+
r_major, r_minor, r_patch = version_parts(REQUIRED_VERSION)
|
14
14
|
(major > r_major) ||
|
15
15
|
(major == r_major && minor > r_minor) ||
|
16
16
|
(major == r_major && minor == r_minor && patch >= r_patch)
|
17
17
|
end
|
18
18
|
|
19
19
|
def get_version
|
20
|
-
|
20
|
+
command = "#{eb_bin} --version"
|
21
|
+
puts "command: #{command}"
|
22
|
+
`#{eb_bin} --version`
|
21
23
|
end
|
22
24
|
|
23
25
|
def parsed_version
|
@@ -29,7 +31,7 @@ module Jack
|
|
29
31
|
end
|
30
32
|
|
31
33
|
|
32
|
-
def
|
34
|
+
def version_parts(parsed)
|
33
35
|
parsed.split('.').collect(&:to_i)
|
34
36
|
end
|
35
37
|
|
data/spec/lib/cli_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Jack::CLI do
|
4
4
|
before(:all) do
|
5
|
-
@args = "hi-web-stag-1 --root spec/fixtures/project --noop --
|
5
|
+
@args = "hi-web-stag-1 --root spec/fixtures/project --noop --sure"
|
6
6
|
FileUtils.rm_rf("spec/fixtures/project/.elasticbeanstalk")
|
7
7
|
end
|
8
8
|
|
@@ -19,7 +19,7 @@ describe Jack::CLI do
|
|
19
19
|
it "should upload and apply config to environment" do
|
20
20
|
out = execute("bin/jack config upload #{@args}")
|
21
21
|
# puts out
|
22
|
-
expect(out).to include('eb config
|
22
|
+
expect(out).to include('eb config save')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should download config from environment" do
|
@@ -31,7 +31,7 @@ describe Jack::CLI do
|
|
31
31
|
it "should diff local config from eb environment config" do
|
32
32
|
out = execute("bin/jack config diff #{@args}")
|
33
33
|
# puts out
|
34
|
-
expect(out).to include("
|
34
|
+
expect(out).to include("diff")
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should reformat the local config to a sorted yaml format" do
|
@@ -39,5 +39,11 @@ describe Jack::CLI do
|
|
39
39
|
# puts out
|
40
40
|
expect(out).to include("Reformatted the local config")
|
41
41
|
end
|
42
|
+
|
43
|
+
it "should terminate enviornment" do
|
44
|
+
out = execute("bin/jack terminate #{@args}")
|
45
|
+
# puts out
|
46
|
+
expect(out).to include("Whew that was close")
|
47
|
+
end
|
42
48
|
end
|
43
49
|
end
|
@@ -8,8 +8,8 @@ describe Jack::Config do
|
|
8
8
|
let(:diff) { Jack::Config::Diff.new(test_options) }
|
9
9
|
|
10
10
|
describe "diff" do
|
11
|
-
it "diff
|
12
|
-
expect(diff).to receive(:
|
11
|
+
it "diff compute_diff" do
|
12
|
+
expect(diff).to receive(:compute_diff)
|
13
13
|
diff.run
|
14
14
|
end
|
15
15
|
|
@@ -18,4 +18,4 @@ describe Jack::Config do
|
|
18
18
|
expect(command).to match /diff/
|
19
19
|
end
|
20
20
|
end
|
21
|
-
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
ENV['TEST'] = '1'
|
2
|
+
# Ensures aws api never called. Fixture home folder does not contain ~/.aws/credentails
|
3
|
+
ENV['HOME'] = "spec/fixtures/home"
|
2
4
|
|
3
5
|
require "pp"
|
4
6
|
require 'ostruct'
|
@@ -10,6 +12,7 @@ require "#{root}/lib/jack"
|
|
10
12
|
require "#{root}/spec/support/fake_project"
|
11
13
|
|
12
14
|
module Helpers
|
15
|
+
# TEST=1 DEBUG=1 bin/jack config diff hi-web-stag-1 --root spec/fixtures/project --noop --sure
|
13
16
|
def execute(cmd)
|
14
17
|
puts "Running: #{cmd}" if ENV['DEBUG']
|
15
18
|
out = `#{cmd}`
|
@@ -21,7 +24,7 @@ module Helpers
|
|
21
24
|
{
|
22
25
|
noop: true,
|
23
26
|
mute: true,
|
24
|
-
|
27
|
+
sure: true,
|
25
28
|
root: @root,
|
26
29
|
env_name: env_name
|
27
30
|
}
|
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: 1.0
|
4
|
+
version: 1.1.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: 2017-06-
|
11
|
+
date: 2017-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -118,7 +118,6 @@ extra_rdoc_files: []
|
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
120
|
- ".rspec"
|
121
|
-
- ".travis.yml"
|
122
121
|
- CHANGELOG.md
|
123
122
|
- Gemfile
|
124
123
|
- Guardfile
|
@@ -126,14 +125,15 @@ files:
|
|
126
125
|
- README.md
|
127
126
|
- Rakefile
|
128
127
|
- bin/jack
|
128
|
+
- circle.yml
|
129
129
|
- jack.gemspec
|
130
130
|
- lib/jack.rb
|
131
131
|
- lib/jack/cli.rb
|
132
|
-
- lib/jack/cli/help.rb
|
133
132
|
- lib/jack/command.rb
|
134
133
|
- lib/jack/config.rb
|
135
134
|
- lib/jack/config/diff.rb
|
136
135
|
- lib/jack/config/download.rb
|
136
|
+
- lib/jack/config/help.rb
|
137
137
|
- lib/jack/config/sort.rb
|
138
138
|
- lib/jack/config/transmit.rb
|
139
139
|
- lib/jack/config/upload.rb
|
@@ -145,7 +145,9 @@ files:
|
|
145
145
|
- lib/jack/eb_config/create.rb
|
146
146
|
- lib/jack/eb_config/update.rb
|
147
147
|
- lib/jack/ext/hash.rb
|
148
|
+
- lib/jack/help.rb
|
148
149
|
- lib/jack/settings.rb
|
150
|
+
- lib/jack/terminate.rb
|
149
151
|
- lib/jack/ui.rb
|
150
152
|
- lib/jack/util.rb
|
151
153
|
- lib/jack/version.rb
|
data/.travis.yml
DELETED
data/lib/jack/cli/help.rb
DELETED
@@ -1,107 +0,0 @@
|
|
1
|
-
module Jack
|
2
|
-
class CLI < Command
|
3
|
-
class Help
|
4
|
-
class << self
|
5
|
-
def convention
|
6
|
-
<<-EOL
|
7
|
-
The configuration name is based on convention. An environment with the name of hi-web-stag-1 results in the jack/cfg/stag-rails-app.cfg.yml being used. The convention can be overriden with the --cfg option.
|
8
|
-
EOL
|
9
|
-
end
|
10
|
-
|
11
|
-
def create
|
12
|
-
<<-EOL
|
13
|
-
Creates a new environment using the configuration in jack/cfg folder. The AWS sample app is initially used for the newly created environment. The sample app is used as a starting point to make sure that the environment is working before you introduce your own app code.
|
14
|
-
|
15
|
-
#{convention}
|
16
|
-
|
17
|
-
Example:
|
18
|
-
|
19
|
-
$ jack create hi-web-stag-1
|
20
|
-
|
21
|
-
$ jack create -c myconfig hi-web-stag-1
|
22
|
-
|
23
|
-
$ jack create -a myapp -c myconfig hi-web-stag-1
|
24
|
-
EOL
|
25
|
-
end
|
26
|
-
|
27
|
-
def upload
|
28
|
-
<<-EOL
|
29
|
-
Uploads the specified template configuration in jack/cfg and applies it to the environment immediately.
|
30
|
-
|
31
|
-
#{convention}
|
32
|
-
|
33
|
-
Example:
|
34
|
-
|
35
|
-
$ jack config upload hi-web-stag-1
|
36
|
-
|
37
|
-
$ jack config upload myapp -c myconfig hi-web-stag-1
|
38
|
-
EOL
|
39
|
-
end
|
40
|
-
|
41
|
-
def download
|
42
|
-
<<-EOL
|
43
|
-
Downloads the environment's config to jack/cfg/[CONFIG_NAME].cfg.yml
|
44
|
-
|
45
|
-
#{convention}
|
46
|
-
|
47
|
-
Example:
|
48
|
-
|
49
|
-
$ jack config download hi-web-stag-1
|
50
|
-
|
51
|
-
$ jack config download myapp -c myconfig hi-web-stag-1
|
52
|
-
EOL
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
def diff
|
57
|
-
<<-EOL
|
58
|
-
Diff local jack config vs environment config. The environment config is generated on the fly.
|
59
|
-
|
60
|
-
If you have colordiff installed the diff command will use make use of it. If you want to have your own custom diff, you can set your JACK_DIFF environment variable to it.
|
61
|
-
|
62
|
-
#{convention}
|
63
|
-
|
64
|
-
Example:
|
65
|
-
|
66
|
-
$ jack config diff hi-web-stag-1
|
67
|
-
|
68
|
-
$ jack config diff myapp -c myconfig hi-web-stag-1
|
69
|
-
EOL
|
70
|
-
end
|
71
|
-
|
72
|
-
def sort
|
73
|
-
<<-EOL
|
74
|
-
Reformats local jack config file to a sorted yaml format.
|
75
|
-
|
76
|
-
#{convention}
|
77
|
-
|
78
|
-
Example:
|
79
|
-
|
80
|
-
$ jack config sort hi-web-stag-1
|
81
|
-
|
82
|
-
$ jack config sort -c myconfig hi-web-stag-1 # env name doesnt matter here
|
83
|
-
EOL
|
84
|
-
end
|
85
|
-
|
86
|
-
# dumb thor bug, so this doesnt even show, leaving here in case Thor is fixed
|
87
|
-
def config
|
88
|
-
<<-EOL
|
89
|
-
Manage the environment's config. Can use this to download the environment's config to jack/cfg folder or upload config in jack/cfg folder and apply it to the environment.
|
90
|
-
|
91
|
-
Example:
|
92
|
-
|
93
|
-
$ jack config download hi-web-stag-1
|
94
|
-
|
95
|
-
For more info:
|
96
|
-
|
97
|
-
$ jack help config
|
98
|
-
|
99
|
-
$ jack config help apply
|
100
|
-
|
101
|
-
$ jack config help download
|
102
|
-
EOL
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|