ukku 0.2.1 → 0.2.2

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: 3fb9c1ffa5635540ca22a07a596acd32aba2da94
4
- data.tar.gz: d72c921c54053e4c6068e5bcc39a8d0ec0ee2526
3
+ metadata.gz: 8c0a07ab01d66c7f5cd95a53f3aff08bc9d86daa
4
+ data.tar.gz: 978dd591fc8ce3ceb9c04f3c68418238305d62ec
5
5
  SHA512:
6
- metadata.gz: bb7c6348d92265ad55c05058a201c578c403044172653f2ce575b226d207be2f89b739f52d76eb5f5e26128c7548b3955f0b987cb8874b2b966a0dff62712f42
7
- data.tar.gz: 0d604e16e402b753a23768605100e76f2867cb898045a026ba3d26fec927686c7d53a43e010f2c930bf1654bbae2f5a21a6a574167d9c76693fdb2090c091658
6
+ metadata.gz: 4674aa0bf3ab0a7d6f8f83be7da985ee257e0f04cb7b34a235a162bb22aef098c7bc6126edd101662b755abcd4d774315759a5c66d238fd3fa59d9606517ea23
7
+ data.tar.gz: e962080e4d41d9e9046026f14ab2b794d7c3ab7c6d49e67a596e8d51266f8921ea66decdc496320539eea2376e63ac516868a2324aab200b7bc810a095d488c7
data/bin/ukku CHANGED
@@ -48,6 +48,10 @@ begin
48
48
  PsRemoveCommand.new.execute(args) if args['ps:remove']
49
49
  rescue Docopt::Exit => e
50
50
  puts doc.strip
51
+ rescue NoApplicationError => e
52
+ puts " ! No application configured. Run 'ukku configure <host>' first."
53
+ rescue MultipleApplicationsError => e
54
+ puts " ! No app specified, use the --app NAME option"
51
55
  rescue Exception => e
52
56
  puts " ! #{e.message}"
53
57
  puts e.backtrace
data/lib/ukku.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  require 'ukku/version.rb'
2
+ require 'ukku/no_application_error.rb'
3
+ require 'ukku/multiple_applications_error.rb'
2
4
  require 'ukku/connection.rb'
5
+ require 'ukku/command.rb'
3
6
  require 'ukku/configure_command.rb'
4
7
  require 'ukku/run_command.rb'
5
8
  require 'ukku/vars_command.rb'
@@ -0,0 +1,21 @@
1
+ class Command
2
+ def load_app_info(args)
3
+ raise NoApplicationError if !File.exist?(UKKU_FILE)
4
+
5
+ data = YAML.load_file(UKKU_FILE)
6
+ raise NoApplicationError if data.length == 0
7
+
8
+ if data.length > 1
9
+ if args['--app'].nil? || args['--app'] !~ /[^[:space:]]/
10
+ raise MultipleApplicationsError
11
+ else
12
+ name = args['--app']
13
+ app_info = data[name]
14
+ end
15
+ else
16
+ app_info = data.values.first
17
+ end
18
+
19
+ app_info.each_with_object({}) { |(k,v), h| h[k.to_sym] = v }
20
+ end
21
+ end
@@ -1,4 +1,4 @@
1
- class ConfigureCommand
1
+ class ConfigureCommand < Command
2
2
  def execute(args)
3
3
  host = args['HOST']
4
4
  name = args['NAME'] || "production"
@@ -15,7 +15,7 @@ class ConfigureCommand
15
15
  raise "Name '#{name}' already exists, choose a different one"
16
16
  end
17
17
 
18
- conn = Connection.new(host, user, identity_file)
18
+ conn = Connection.new(entry)
19
19
  server_ready = is_server_ready?(conn)
20
20
 
21
21
  if server_ready
@@ -88,8 +88,9 @@ class ConfigureCommand
88
88
  end
89
89
 
90
90
  def append_entry_to_ukku_file(name, params)
91
- data = { name => params }
92
- File.open(UKKU_FILE, 'a') { |f| f.write data.to_yaml }
91
+ data = File.exist?(UKKU_FILE) ? YAML.load_file(UKKU_FILE) : {}
92
+ data[name] = params
93
+ File.open(UKKU_FILE, 'w') { |f| f.write data.to_yaml }
93
94
  end
94
95
 
95
96
  def append_ukku_file_to_gitignore
@@ -1,8 +1,10 @@
1
1
  class Connection
2
- def initialize(host, user, identity_file)
3
- @host = host
4
- @user = user
5
- @identity_file = identity_file
2
+ def initialize(opts)
3
+ options = opts.each_with_object({}) { |(k,v), h| h[k.to_sym] = v }
4
+
5
+ @host = options[:host]
6
+ @user = options[:user]
7
+ @identity_file = options[:identity_file]
6
8
  end
7
9
 
8
10
  def execute(command, &blk)
@@ -0,0 +1,2 @@
1
+ class MultipleApplicationsError < Exception
2
+ end
@@ -0,0 +1,2 @@
1
+ class NoApplicationError < Exception
2
+ end
@@ -1,32 +1,11 @@
1
- class PsAddCommand
1
+ class PsAddCommand < Command
2
2
  def execute(args)
3
3
  type = args['TYPE']
4
4
 
5
- if !File.exist?(UKKU_FILE)
6
- raise "No application configured. Run 'ukku configure HOST' first."
7
- end
8
-
9
- data = YAML.load_file(UKKU_FILE)
10
- name, server = data.first
11
- if name.nil?
12
- raise "No application configured. Run 'ukku configure <host>' first."
13
- end
14
-
15
- if data.length > 1
16
- if args['--app'].empty?
17
- raise "No app specified, use the --app NAME option"
18
- else
19
- name = args[--app]
20
- sever = data[name]
21
- end
22
- end
23
-
24
- host = server['host']
25
- user = server['user']
26
- identity_file = server['identity_file']
5
+ app_info = load_app_info(args)
27
6
 
28
- puts "Adding process type '#{type}' on #{host} ..."
29
- conn = Connection.new(host, user, identity_file)
7
+ puts "Adding process type '#{type}' on #{app_info[:host]} ..."
8
+ conn = Connection.new(app_info)
30
9
  conn.execute("sudo touch /etc/ukku/ps-types/#{type}")
31
10
  begin
32
11
  conn.execute("launchapp")
@@ -1,31 +1,10 @@
1
- class PsCommand
1
+ class PsCommand < Command
2
2
  def execute(args)
3
3
  type = args['TYPE']
4
4
 
5
- if !File.exist?(UKKU_FILE)
6
- raise "No application configured. Run 'ukku configure HOST' first."
7
- end
5
+ app_info = load_app_info(args)
8
6
 
9
- data = YAML.load_file(UKKU_FILE)
10
- name, server = data.first
11
- if name.nil?
12
- raise "No application configured. Run 'ukku configure <host>' first."
13
- end
14
-
15
- if data.length > 1
16
- if args['--app'].empty?
17
- raise "No app specified, use the --app NAME option"
18
- else
19
- name = args[--app]
20
- sever = data[name]
21
- end
22
- end
23
-
24
- host = server['host']
25
- user = server['user']
26
- identity_file = server['identity_file']
27
-
28
- conn = Connection.new(host, user, identity_file)
7
+ conn = Connection.new(app_info)
29
8
  conn.execute("ls /etc/ukku/ps-types")
30
9
  end
31
10
  end
@@ -1,34 +1,13 @@
1
- class PsRemoveCommand
1
+ class PsRemoveCommand < Command
2
2
  def execute(args)
3
3
  type = args['TYPE']
4
4
 
5
- if !File.exist?(UKKU_FILE)
6
- raise "No application configured. Run 'ukku configure HOST' first."
7
- end
8
-
9
- data = YAML.load_file(UKKU_FILE)
10
- name, server = data.first
11
- if name.nil?
12
- raise "No application configured. Run 'ukku configure <host>' first."
13
- end
14
-
15
- if data.length > 1
16
- if args['--app'].empty?
17
- raise "No app specified, use the --app NAME option"
18
- else
19
- name = args[--app]
20
- sever = data[name]
21
- end
22
- end
23
-
24
- host = server['host']
25
- user = server['user']
26
- identity_file = server['identity_file']
5
+ app_info = load_app_info(args)
27
6
 
28
- puts "Removing process type '#{type}' on #{host} ..."
29
- conn = Connection.new(host, user, identity_file)
30
- conn.execute("sudo rm /etc/ukku/ps-types/#{type} && docker kill app-#{type} && docker rm app-#{type}")
7
+ puts "Removing process type '#{type}' on #{app_info[:host]} ..."
8
+ conn = Connection.new(app_info)
31
9
  begin
10
+ conn.execute("sudo rm /etc/ukku/ps-types/#{type} && docker kill app-#{type} && docker rm app-#{type}")
32
11
  conn.execute("launchapp")
33
12
  rescue Subprocess::NonZeroExit => e
34
13
  end
@@ -1,32 +1,11 @@
1
- class RunCommand
1
+ class RunCommand < Command
2
2
  def execute(args)
3
3
  command = args['COMMAND'].join(' ')
4
4
 
5
- if !File.exist?(UKKU_FILE)
6
- raise "No application configured. Run 'ukku configure HOST' first."
7
- end
5
+ app_info = load_app_info(args)
8
6
 
9
- data = YAML.load_file(UKKU_FILE)
10
- name, server = data.first
11
- if name.nil?
12
- raise "No application configured. Run 'ukku configure <host>' first."
13
- end
14
-
15
- if data.length > 1
16
- if args['--app'].empty?
17
- raise "No app specified, use the --app NAME option"
18
- else
19
- name = args[--app]
20
- sever = data[name]
21
- end
22
- end
23
-
24
- host = server['host']
25
- user = server['user']
26
- identity_file = server['identity_file']
27
-
28
- puts "Running command '#{command}' on #{host} ..."
29
- conn = Connection.new(host, user, identity_file)
7
+ puts "Running command '#{command}' on #{app_info[:host]} ..."
8
+ conn = Connection.new(app_info)
30
9
  conn.execute("runcommand #{command}")
31
10
  end
32
11
  end
@@ -1,28 +1,11 @@
1
- class SetVarCommand
1
+ class SetVarCommand < Command
2
2
  def execute(args)
3
3
  var_name = args['VAR_NAME']
4
4
  var_value = args['VAR_VALUE']
5
5
 
6
- data = YAML.load_file(UKKU_FILE)
7
- name, server = data.first
8
- if name.nil?
9
- raise "No application configured. Run 'ukku configure <host>' first."
10
- end
11
-
12
- if data.length > 1
13
- if args['--app'].empty?
14
- raise "No app specified, use the --app NAME option"
15
- else
16
- name = args[--app]
17
- sever = data[name]
18
- end
19
- end
20
-
21
- host = server['host']
22
- user = server['user']
23
- identity_file = server['identity_file']
6
+ app_info = load_app_info(args)
24
7
 
25
- conn = Connection.new(host, user, identity_file)
8
+ conn = Connection.new(app_info)
26
9
  conn.execute("sudo mkdir -p /etc/ukku/vars && echo '#{var_value}' > /etc/ukku/vars/#{var_name}")
27
10
  begin
28
11
  conn.execute("launchapp")
@@ -1,28 +1,10 @@
1
- class UploadKeyCommand
1
+ class UploadKeyCommand < Command
2
2
  def execute(args)
3
- data = YAML.load_file(UKKU_FILE)
4
- name, server = data.first
5
- if name.nil?
6
- raise "No application configured. Run 'ukku configure <host>' first."
7
- end
8
-
9
- if data.length > 1
10
- if args['--app'].empty?
11
- raise "No app specified, use the --app NAME option"
12
- else
13
- name = args[--app]
14
- sever = data[name]
15
- end
16
- end
17
-
18
- host = server['host']
19
- user = server['user']
20
- identity_file = server['identity_file']
3
+ app_info = load_app_info(args)
4
+ conn = Connection.new(app_info)
21
5
 
22
6
  key_file = args['PUBLIC_KEY_FILE']
23
7
 
24
- conn = Connection.new(host, user, identity_file)
25
-
26
8
  puts "Uploading key '#{key_file}' ... "
27
9
  conn.execute("gitreceive upload-key ukku") do |p|
28
10
  p.communicate IO.read(File.expand_path(key_file))
@@ -1,25 +1,8 @@
1
- class VarsCommand
1
+ class VarsCommand < Command
2
2
  def execute(args)
3
- data = YAML.load_file(UKKU_FILE)
4
- name, server = data.first
5
- if name.nil?
6
- raise "No application configured. Run 'ukku configure <host>' first."
7
- end
3
+ app_info = load_app_info(args)
8
4
 
9
- if data.length > 1
10
- if args['--app'].empty?
11
- raise "No app specified, use the --app NAME option"
12
- else
13
- name = args[--app]
14
- sever = data[name]
15
- end
16
- end
17
-
18
- host = server['host']
19
- user = server['user']
20
- identity_file = server['identity_file']
21
-
22
- conn = Connection.new(host, user, identity_file)
5
+ conn = Connection.new(app_info)
23
6
  conn.execute("sudo mkdir -p /etc/ukku/vars && FILES=/etc/ukku/vars/*; for f in $FILES; do echo \"${f##*/}=$(<$f)\"; done")
24
7
  end
25
8
  end
data/lib/ukku/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ukku
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ukku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Germán Escobar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -123,8 +123,11 @@ files:
123
123
  - features/support/env.rb
124
124
  - features/ukku.feature
125
125
  - lib/ukku.rb
126
+ - lib/ukku/command.rb
126
127
  - lib/ukku/configure_command.rb
127
128
  - lib/ukku/connection.rb
129
+ - lib/ukku/multiple_applications_error.rb
130
+ - lib/ukku/no_application_error.rb
128
131
  - lib/ukku/ps_add_command.rb
129
132
  - lib/ukku/ps_command.rb
130
133
  - lib/ukku/ps_remove_command.rb