deployto 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/deploy CHANGED
@@ -10,7 +10,6 @@ require 'deploytool/command'
10
10
 
11
11
  $logger = Logger.new STDOUT
12
12
  $logger.formatter = proc do |severity, datetime, progname, msg|
13
- next if severity == "DEBUG"
14
13
  if severity == "ERROR"
15
14
  "ERROR: #{msg}\n"
16
15
  else
@@ -23,4 +22,4 @@ args = ARGV.dup
23
22
  ARGV.clear
24
23
  command = args.shift.strip rescue 'help'
25
24
 
26
- DeployTool::Command.run(command, args)
25
+ DeployTool::Command.run(command, args)
@@ -1,12 +1,7 @@
1
1
  class DeployTool::Command
2
2
  COMMANDS = ["to", "logs", "import", "export", "config"]
3
3
 
4
- def self.run(command, args)
5
- change_to_toplevel_dir!
6
-
7
- DeployTool::Config.load(".deployrc")
8
-
9
- if command == "help"
4
+ def self.print_help
10
5
  puts "Deploytool Usage Instructions"
11
6
  puts ""
12
7
  puts "Add a target:"
@@ -16,6 +11,22 @@ class DeployTool::Command
16
11
  puts ""
17
12
  puts "Deploy the current directory to the target:"
18
13
  puts " deploy to production"
14
+ end
15
+
16
+ def self.run(command, args)
17
+ if args.include?("--debug")
18
+ args.delete("--debug")
19
+ $logger.level = Logger::DEBUG
20
+ else
21
+ $logger.level = Logger::INFO
22
+ end
23
+
24
+ change_to_toplevel_dir!
25
+
26
+ DeployTool::Config.load(".deployrc")
27
+
28
+ if command == "help"
29
+ print_help
19
30
  elsif command == "add"
20
31
  if args[0].nil?
21
32
  puts "ERROR: Missing target name."
@@ -35,6 +46,9 @@ class DeployTool::Command
35
46
  puts "Use \"deploy help\" if you're lost."
36
47
  exit
37
48
  end
49
+ if target.respond_to?(:verify)
50
+ target.verify
51
+ end
38
52
  DeployTool::Config[args[0]] = target.to_h
39
53
  elsif command == "list"
40
54
  puts "Registered Targets:"
@@ -47,9 +61,9 @@ class DeployTool::Command
47
61
  target_name = args[0]
48
62
 
49
63
  unless (target = DeployTool::Config[target_name]) && !target.nil? && target.size > 0
50
- puts "ERROR: Couldn't find target: #{target_name}"
64
+ puts "ERROR: Target \"#{target_name}\" is not configured"
51
65
  puts ""
52
- puts "Use \"deploy help\" if you're lost."
66
+ print_help
53
67
  exit
54
68
  end
55
69
 
@@ -8,16 +8,16 @@ require 'zip'
8
8
 
9
9
  class DeployTool::Target::EfficientCloud
10
10
  class ApiClient
11
- attr_reader :server, :app_id, :email, :password
12
- def initialize(server, app_id, email, password)
13
- @app_id = app_id
11
+ attr_reader :server, :app_name, :email, :password
12
+ def initialize(server, app_name, email, password)
13
+ @app_name = app_name
14
14
  @server = server
15
15
  @email = email
16
16
  @password = password
17
17
  end
18
18
 
19
19
  def call(method, method_name, data = {})
20
- url = Addressable::URI.parse("http://#{@server}/api/cli/v1/apps/#{@app_id}/#{method_name}")
20
+ url = Addressable::URI.parse("http://#{@server}/api/cli/v1/apps/#{@app_name}/#{method_name}")
21
21
  data = data.merge(:email => @email, :password => @password)
22
22
  if method == :post
23
23
  res = Net::HTTP.start(url.host, url.port) do |http|
@@ -34,6 +34,16 @@ class DeployTool::Target::EfficientCloud
34
34
  res.error!
35
35
  end
36
36
  end
37
+
38
+ def info
39
+ response = call :get, 'info'
40
+ doc = REXML::Document.new response
41
+ data = {}
42
+ doc.elements["app"].each_element do |el|
43
+ data[el.name.gsub('-','_').to_sym] = el.text
44
+ end
45
+ data
46
+ end
37
47
 
38
48
  def upload
39
49
  puts "-----> Packing code tarball..."
@@ -70,16 +80,16 @@ class DeployTool::Target::EfficientCloud
70
80
  rescue Net::HTTPServerException => e
71
81
  case e.response
72
82
  when Net::HTTPNotFound
73
- $logger.error "Application app%d.%s couldn't be found." % [@app_id, @server.gsub('api.', '')]
83
+ $logger.error "Application %s couldn't be found." % @app_name
74
84
  when Net::HTTPUnauthorized
75
- $logger.error "You're not authorized to update app%d.%s." % [@app_id, @server.gsub('api.', '')]
85
+ $logger.error "You're not authorized to update %s." % @app_name
76
86
  else
77
87
  raise e
78
88
  end
79
89
  $logger.info "\nPlease check the controlpanel for update instructions."
80
90
  exit 2
81
91
  end
82
-
92
+
83
93
  def deploy(code_token)
84
94
  initial_response = call :post, 'deploy', {:code_token => code_token}
85
95
  doc = REXML::Document.new initial_response
@@ -109,7 +119,7 @@ class DeployTool::Target::EfficientCloud
109
119
  puts "...possibly done."
110
120
  break
111
121
  end
112
- if doc.elements["deploy/message"].text == 'nojob'
122
+ if doc.elements["deploy/message"].text == 'finished'
113
123
  puts "\n-----> FINISHED after %d seconds!" % (Time.now-start)
114
124
  break
115
125
  end
@@ -1,15 +1,15 @@
1
1
  require 'highline'
2
2
 
3
3
  class DeployTool::Target::EfficientCloud < DeployTool::Target
4
- SUPPORTED_API_VERSION = 1
4
+ SUPPORTED_API_VERSION = 2
5
5
  def self.parse_target_spec(target_spec)
6
- server, app_id = target_spec.split('@').reverse
7
- if app_id.nil?
8
- app_id = server.split('.', 2).first
6
+ server, app_name = target_spec.split('@').reverse
7
+ if app_name.nil?
8
+ app_name = server.split('.', 2).first
9
9
  end
10
10
  [server, 'api.' + server, 'api.' + server.split('.', 2).last].each do |api_server|
11
11
  begin
12
- return [app_id.gsub('app', '').to_i, api_server] if check_version(api_server)
12
+ return [app_name, api_server] if check_version(api_server)
13
13
  rescue => e
14
14
  puts e
15
15
  end
@@ -22,16 +22,16 @@ class DeployTool::Target::EfficientCloud < DeployTool::Target
22
22
  end
23
23
 
24
24
  def to_h
25
- {:type => "EfficientCloud", :api_server => @api_client.server, :app_id => @api_client.app_id, :email => @api_client.email, :password => @api_client.password}
25
+ {:type => "EfficientCloud", :api_server => @api_client.server, :app_name => @api_client.app_name, :email => @api_client.email, :password => @api_client.password}
26
26
  end
27
27
 
28
28
  def to_s
29
- "app%s@%s (EFC-based platform)" % [@api_client.app_id, @api_client.server]
29
+ "%s@%s (EFC-based platform)" % [@api_client.app_name, @api_client.server]
30
30
  end
31
31
 
32
32
  def initialize(options)
33
33
  @api_server = options['api_server']
34
- @api_client = ApiClient.new(options['api_server'], options['app_id'], options['email'], options['password'])
34
+ @api_client = ApiClient.new(options['api_server'], options['app_name'], options['email'], options['password'])
35
35
  end
36
36
 
37
37
  def self.check_version(api_server)
@@ -45,6 +45,7 @@ class DeployTool::Target::EfficientCloud < DeployTool::Target
45
45
 
46
46
  if info['api_version'] > SUPPORTED_API_VERSION
47
47
  $logger.error "This version of deploytool is outdated.\nThis server requires at least API Version #{info['api_version']}."
48
+ return false
48
49
  end
49
50
  return true
50
51
  end
@@ -53,12 +54,35 @@ class DeployTool::Target::EfficientCloud < DeployTool::Target
53
54
  $logger.info "Please specify your controlpanel login information"
54
55
  email = HighLine.new.ask("E-mail: ")
55
56
  password = HighLine.new.ask("Password: ") {|q| q.echo = "*" }
56
- app_id, api_server = parse_target_spec(target_spec)
57
- EfficientCloud.new('api_server' => api_server, 'app_id' => app_id, 'email' => email, 'password' => password)
57
+ app_name, api_server = parse_target_spec(target_spec)
58
+ EfficientCloud.new('api_server' => api_server, 'app_name' => app_name, 'email' => email, 'password' => password)
59
+ end
60
+
61
+ def verify
62
+ self.class.check_version(@api_server)
63
+ begin
64
+ info = @api_client.info
65
+ return true
66
+ rescue => e
67
+ $logger.debug "Exception: %s %s\n %s" % [e.class.name, e.message, e.backtrace.join("\n ")]
68
+ if e.message.include?("401 ")
69
+ $logger.error "Authentication failed (password wrong?)"
70
+ elsif e.message.include?("404 ")
71
+ $logger.error "Application does not exist"
72
+ else
73
+ $logger.error "Remote server said: %s" % [e.message]
74
+ end
75
+ end
76
+ exit 5
58
77
  end
59
78
 
60
79
  def push(opts)
61
80
  self.class.check_version(@api_server)
81
+ info = @api_client.info
82
+ if info[:blocking_deployment]
83
+ $logger.error info[:blocking_deployment]
84
+ exit 4
85
+ end
62
86
  code_token = @api_client.upload
63
87
  deploy_token = @api_client.deploy(code_token)
64
88
  @api_client.deploy_status(deploy_token, opts) # Blocks till deploy is done
@@ -1,3 +1,3 @@
1
1
  module DeployTool
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
data/lib/deploytool.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module DeployTool; end
2
2
 
3
3
  require 'deploytool/config'
4
- require 'deploytool/target'
4
+ require 'deploytool/target'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deployto
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
5
- prerelease:
4
+ hash: 63
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Efficient Cloud Ltd
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-24 00:00:00 Z
18
+ date: 2011-08-31 00:00:00 +02:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: inifile
@@ -140,6 +141,7 @@ files:
140
141
  - spec/spec.opts
141
142
  - spec/spec_helper.rb
142
143
  - spec/target_spec.rb
144
+ has_rdoc: true
143
145
  homepage: http://platformdirectory.com/
144
146
  licenses: []
145
147
 
@@ -169,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
171
  requirements: []
170
172
 
171
173
  rubyforge_project:
172
- rubygems_version: 1.8.8
174
+ rubygems_version: 1.3.7
173
175
  signing_key:
174
176
  specification_version: 3
175
177
  summary: Multi-platform deployment tool.