gantree 0.4.7 → 0.4.8

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: 375f0ba44dd429bb2dac4ec8d9d7487cb799f22b
4
- data.tar.gz: b71597843a51ddaf68838f4b339e9d6359bb5cf6
3
+ metadata.gz: c29f307b0a0953654d60d594c16483af6170d65e
4
+ data.tar.gz: 99419b8282f4321e4bc03cfda65c5c6fc148b36f
5
5
  SHA512:
6
- metadata.gz: 7cd977a7179d2b9b09df0313809284e95567f1633e8cdaf4c4143cdf6a4691ef18a3b07817b5afa30054c2fd2cfe821997deacd4ec44144e7f6b984c0ff44556
7
- data.tar.gz: 6be3ab8f036c1bdaf56421482f5aa8fc6c0d2a95907092d9eb6c8c91cfd7c409e47e6ee13cd2e82436baa60ffa66f55a2de7c2f5ff1c7fa302cfe4cc5179d93a
6
+ metadata.gz: dd4eb18352ec83074acf1061c824c0ca571cb1f69a49f9f4475fcdbba3641b552cd19885c934aa6202be221fd07169a728ba18435e0aa654a437fcf72fd3fc61
7
+ data.tar.gz: 345e240f10d6ca87bf48e186540ddce77f39bf0862eef393c679103647fb9723f0f619f6c350ee4809f3af5eea475e27adb51cf0d353fb8b10f9c30b5c84a771
@@ -27,7 +27,7 @@ module Gantree
27
27
  end
28
28
 
29
29
  def tag
30
- origin = `git remote show origin | grep "Push" | cut -f1 -d"/" | cut -d":" -f3`.strip
30
+ origin = `git config --get remote.origin.url`.match(":(.*)\/")[1]
31
31
  branch = `git rev-parse --abbrev-ref HEAD`.strip
32
32
  hash = `git rev-parse --verify --short #{branch}`.strip
33
33
  "#{origin}-#{branch}-#{hash}"
@@ -6,11 +6,13 @@ require 'gantree/cli/help'
6
6
  module Gantree
7
7
  class CLI < Thor
8
8
 
9
+ class_option :dry_run, :aliases => "-d", :desc => "dry run mode", :default => false
10
+
9
11
  desc "deploy APP", "deploy specified APP"
12
+ long_desc Help.deploy
10
13
  option :branch, :desc => 'branch to deploy'
11
14
  method_option :tag, :aliases => "-t", :desc => "set docker tag to deploy"
12
15
  method_option :ext, :aliases => "-x", :desc => "ebextensions folder/repo"
13
- option :dry_run, :aliases => "-d", :desc => "do not actually deploy the app"
14
16
  option :silent, :aliases => "-s", :desc => "mute notifications"
15
17
  option :image_path, :aliases => "-i", :desc => "docker hub image path ex. (bleacher/cms | quay.io/bleacherreport/cms)"
16
18
  option :autodetect_app_role, :desc => "use naming convention to determin role"
@@ -19,19 +21,19 @@ module Gantree
19
21
  end
20
22
 
21
23
  desc "init IMAGE", "create a dockerrun for your IMAGE"
24
+ long_desc Help.init
22
25
  method_option :user , :aliases => "-u", :desc => "user credentials for private dockerhub repo"
23
26
  method_option :port , :aliases => "-p", :desc => "port of running application"
24
27
  method_option :bucket , :aliases => "-b", :desc => "set bucket name, default is '<user>-docker-cfgs'"
25
- option :dry_run, :aliases => "-d", :desc => "do not actually upload to s3 bucket"
26
28
  def init image
27
29
  Gantree::Init.new(image, options).run
28
30
  end
29
31
 
30
32
  desc "create APP", "create a cfn stack"
33
+ long_desc Help.create
31
34
  method_option :env, :aliases => "-e", :desc => "(optional) environment name"
32
35
  method_option :instance_size, :aliases => "-i", :desc => "(optional) set instance size", :default => "m3.medium"
33
36
  method_option :rds, :aliases => "-r", :desc => "(optional) set database type [pg,mysql]"
34
- option :dry_run, :aliases => "-d", :desc => "do not actually create the stack"
35
37
  option :docker_version, :desc => "set the version of docker to use as solution stack"
36
38
  option :dupe, :desc => "copy an existing template into a new template"
37
39
  option :local, :desc => "use a local cfn nested template"
@@ -40,26 +42,26 @@ module Gantree
40
42
  end
41
43
 
42
44
  desc "update APP", "update a cfn stack"
43
- option :dry_run, :aliases => "-d", :desc => "do not actually create the stack"
45
+ long_desc Help.update
44
46
  option :role, :aliases => "-r", :desc => "add an app role (worker|listner|scheduler)"
47
+ option :solution, :aliases => "-s", :desc => "change solution stack"
45
48
  def update app
46
49
  Gantree::Stack.new(app, merge_defaults(options)).update
47
50
  end
48
51
 
49
52
  desc "delete APP", "delete a cfn stack"
50
53
  option :force, :desc => "do not prompt"
51
- option :dry_run, :aliases => "-d", :desc => "do not actually create the stack"
52
54
  def delete app
53
55
  Gantree::Stack.new(app, merge_defaults(options)).delete
54
56
  end
55
57
 
56
58
  desc "restart APP", "restart an eb app"
57
- option :dry_run, :aliases => "-d", :desc => "do not actually restart"
58
59
  def restart app
59
60
  Gantree::App.new(app, merge_defaults(options)).restart
60
61
  end
61
62
 
62
63
  desc "build", "build and tag a docker application"
64
+ long_desc Help.build
63
65
  option :image_path, :aliases => "-i", :desc => "docker hub image path ex. (bleacher/cms | quay.io/bleacherreport/cms)"
64
66
  option :tag, :aliases => "-t", :desc => "set docker tag to build"
65
67
  def build
@@ -67,6 +69,8 @@ module Gantree
67
69
  end
68
70
 
69
71
  desc "push", "build and tag a docker application"
72
+ long_desc Help.push
73
+ option :hub, :aliases => "-h", :desc => "hub (docker|quay)"
70
74
  option :image_path, :aliases => "-i", :desc => "docker hub image path ex. (bleacher/cms | quay.io/bleacherreport/cms)"
71
75
  option :tag, :aliases => "-t", :desc => "set docker tag to push"
72
76
  def push
@@ -78,11 +82,11 @@ module Gantree
78
82
  puts Gantree::Docker.new(merge_defaults(options)).tag
79
83
  end
80
84
 
81
- desc "ship", "tag a docker application"
85
+ desc "ship", "build, push and deploy docker container to elastic beanstalk"
86
+ long_desc Help.ship
82
87
  option :branch, :desc => 'branch to deploy'
83
88
  option :tag, :aliases => "-t", :desc => "set docker tag to deploy", :default => Gantree::Base.new.tag
84
89
  option :ext, :aliases => "-x", :desc => "ebextensions folder/repo"
85
- option :dry_run, :aliases => "-d", :desc => "do not actually deploy the app"
86
90
  option :silent, :aliases => "-s", :desc => "mute notifications"
87
91
  option :autodetect_app_role, :desc => "use naming convention to determin role"
88
92
  option :image_path, :aliases => "-i", :desc => "hub image path ex. (bleacher/cms | quay.io/bleacherreport/cms)"
@@ -94,6 +98,12 @@ module Gantree
94
98
  Gantree::Deploy.new(server, merge_defaults(options)).run
95
99
  end
96
100
 
101
+ map "-v" => :version
102
+ desc "version", "gantree version"
103
+ def version
104
+ puts VERSION
105
+ end
106
+
97
107
  protected
98
108
 
99
109
  def merge_defaults(options={})
@@ -2,9 +2,131 @@ module Gantree
2
2
  class CLI < Thor
3
3
  class Help
4
4
  class << self
5
- def hello(action)
5
+ def init
6
6
  <<-EOL
7
- Adds a remote named <name> for the repository at <url>. The command git fetch <name> can then be used to create and update
7
+ Examples:
8
+
9
+ $ gantree init -u USERNAME -p PORT HANDLE/REPO:TAG
10
+
11
+ $ gantree init -u frodriguez -p 3000 bleacher/cauldron:master
12
+ EOL
13
+ end
14
+
15
+ def deploy
16
+ <<-EOL
17
+ Examples:
18
+
19
+ $ gantree deploy -t TAG ENVIRONMENT
20
+
21
+ $ gantree deploy -t latest stag-cauldon-app-s1
22
+
23
+ # to deploy to all environments to within the same application
24
+
25
+ $ gantree deploy -t TAG APPLICATION
26
+
27
+ $ gantree deploy -t TAG cauldron-stag-s1
28
+
29
+ # add remote .ebextensions
30
+
31
+ $ gantree deploy -t TAG stag-cauldron-s1 -x "git@github.com:br/.ebextensions.git"
32
+
33
+ # add remote .ebextensions branch
34
+
35
+ $ gantree deploy -t TAG stag-cauldron-s1 -x "git@github.com:br/.ebextensions:feature_branch"
36
+
37
+ EOL
38
+ end
39
+
40
+ def create
41
+ <<-EOL
42
+ Examples:
43
+
44
+ $ gantree create APPLICATION
45
+
46
+ $ gantree create linguist-stag-s1
47
+
48
+ $ gantree create APPLICATION -e ENVIRONMENT
49
+
50
+ $ gantree create linguist-stag-s1 -e linguist-stag-app-s1
51
+
52
+ $ gantree create --dupe=rails-stag-s1 rails-stag-s3
53
+ EOL
54
+ end
55
+
56
+ def update
57
+ <<-EOL
58
+ Examples:
59
+
60
+ # Update a cloudformation stack
61
+ $ gantree update linguist-stag-s1
62
+
63
+ # Add an app role to an existing stack
64
+ $ gantree update linguist-stag-s1 -r worker
65
+
66
+ # Update docker solution starck version
67
+ $ gantree update linguist-stag-s1 -s latest
68
+ $ gantree update linguist-stag-s1 -s "64bit Amazon Linux 2014.09 v1.0.11 running Docker 1.3.3"
69
+ EOL
70
+ end
71
+
72
+ def build
73
+ <<-EOL
74
+ Builds and tags a docker application.
75
+
76
+ Examples:
77
+
78
+ # Automatically tag a build
79
+ $ gantree build
80
+
81
+ # Add custom tag to a build
82
+ $ gantree build -t deploy
83
+
84
+ # Override image path to point to another hub
85
+ $ gantree build -i quay.io/bleacherreport/cms
86
+
87
+ EOL
88
+ end
89
+
90
+ def push
91
+ <<-EOL
92
+ Push docker image tag to hub
93
+
94
+ Examples:
95
+
96
+ # Push automatically tagged build
97
+ $ gantree push
98
+
99
+ # Push custom tagged build
100
+ $ gantree push -t deploy
101
+
102
+ # Push to another hub/acocunt/repo
103
+ $ gantree push -i quay.io/bleacherreport/cms
104
+ EOL
105
+ end
106
+
107
+ def ship
108
+ <<-EOL
109
+ build, push and deploy docker image to elastic beanstalk
110
+
111
+ Examples:
112
+
113
+ # Automatically tag a build, push that build and deploy to elastic beanstalk
114
+ $ gantree ship cms-stag-s1
115
+
116
+ # Override defaults
117
+ $ gantree ship -i bleacher/cms -x "git@github.com:br/.ebextensions.git:master" cms-stag-s1
118
+
119
+ $ gantree ship -i bleacher/cms -t built -x "git@github.com:br/.ebextensions.git:master" cms-stag-s1
120
+ EOL
121
+ end
122
+
123
+ def restart
124
+ <<-EOL
125
+ Restart docker environment
126
+
127
+ Examples:
128
+
129
+ $ gantree restart stag-rails-app-s1
8
130
  EOL
9
131
  end
10
132
  end
@@ -116,8 +116,9 @@ module Gantree
116
116
  :option_settings => autodetect_app_role(env)
117
117
  })
118
118
  puts "Deployed #{@packaged_version} to #{env} on #{@app}".green
119
- rescue AWS::ElasticBeanstalk::Errors::InvalidParameterValue
119
+ rescue AWS::ElasticBeanstalk::Errors::InvalidParameterValue => e
120
120
  puts "Error: Something went wrong during the deploy to #{env}".red
121
+ puts "#{e.message}"
121
122
  end
122
123
  end
123
124
  end
@@ -51,10 +51,10 @@ module Gantree
51
51
  def update
52
52
  puts "Updating stack from local cfn repo"
53
53
  add_role @options[:role] if @options[:role]
54
- unless @options[:dry_run] then
55
- upload_templates
56
- @cfm.stacks[@options[:stack_name]].update(:template => stack_template)
57
- end
54
+ change_solution_stack if @options[:solution]
55
+ return if @options[:dry_run]
56
+ upload_templates
57
+ puts "Stack Updated".green if @cfm.stacks[@options[:stack_name]].update(:template => stack_template)
58
58
  end
59
59
 
60
60
  def delete
@@ -178,6 +178,25 @@ module Gantree
178
178
  end
179
179
  end
180
180
 
181
+ def change_solution_stack
182
+ beanstalk = JSON.parse(IO.read("cfn/#{@options[:stack_name]}-beanstalk.cfn.json"))
183
+ solution_stack = set_solution_stack
184
+ beanstalk["Resources"]["ConfigurationTemplate"]["Properties"]["SolutionStackName"] = solution_stack
185
+ beanstalk["Resources"]["ConfigurationTemplate"]["Properties"]["Description"] = solution_stack
186
+ IO.write("cfn/#{@options[:stack_name]}-beanstalk.cfn.json",JSON.pretty_generate(beanstalk))
187
+ end
188
+
189
+ def set_solution_stack
190
+ @options[:solution] == "latest" ? get_latest_docker_solution : @options[:solution]
191
+ end
192
+
193
+ def get_latest_docker_solution
194
+ result = eb.list_available_solution_stacks
195
+ solutions = result[:solution_stacks]
196
+ docker_solutions = solutions.select { |s| s.include? "running Docker"}
197
+ docker_solutions.first
198
+ end
199
+
181
200
  def add_role name
182
201
  env = @options[:env].sub('app', name)
183
202
  beanstalk = JSON.parse(IO.read("cfn/#{@options[:stack_name]}-beanstalk.cfn.json"))
@@ -1,3 +1,3 @@
1
1
  module Gantree
2
- VERSION = "0.4.7"
2
+ VERSION = "0.4.8"
3
3
  end
@@ -106,5 +106,17 @@ describe Gantree::CLI do
106
106
  expect(out).to include "Deleting"
107
107
  end
108
108
  end
109
+
110
+ describe "#version" do
111
+ it "should output gantree version" do
112
+ out = execute("bin/gantree version")
113
+ expect(out).to match /\d\.\d\.\d/
114
+ end
115
+
116
+ it "should output gantree version using alias" do
117
+ out = execute("bin/gantree -v")
118
+ expect(out).to match /\d\.\d\.\d/
119
+ end
120
+ end
109
121
  end
110
122
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gantree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor