dploy 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,64 +5,56 @@ require 'dploy/logger'
5
5
  require 'dploy/shell_command'
6
6
 
7
7
  module Dploy
8
-
9
8
  class Deployer
10
-
11
- attr_accessor :deploy_data
12
-
9
+
13
10
  def initialize(deploy_data)
14
-
15
- @deploy_data = deploy_data
16
-
11
+ @deploy_data = deploy_data
17
12
  @ec2 = EC2Client.new(
18
- DPLOY_CONFIG['ec2_access_key_id'],
19
- DPLOY_CONFIG['ec2_access_key'],
20
- DPLOY_CONFIG['ec2_endpoint'])
21
-
13
+ DPLOY_CONFIG['ec2_access_key_id'],
14
+ DPLOY_CONFIG['ec2_access_key'],
15
+ DPLOY_CONFIG['ec2_endpoint'])
22
16
  @chef = ChefClient.new(
23
- DPLOY_CONFIG['chef_api_url'],
24
- DPLOY_CONFIG['chef_api_user'],
25
- DPLOY_CONFIG['chef_api_key'])
26
-
27
-
17
+ DPLOY_CONFIG['chef_api_url'],
18
+ DPLOY_CONFIG['chef_api_user'],
19
+ DPLOY_CONFIG['chef_api_key'])
20
+
28
21
  #TODO validate deploy data
29
-
22
+
30
23
  @deploy_data[:id] = "#{@deploy_data[:project]}-#{@deploy_data[:environment]}-#{@deploy_data[:version].gsub('.','-')}-#{Time.now.to_i}"
31
- @log = Dploy::Logger.new(DPLOY_CONFIG['mongo_server'], @deploy_data[:id])
24
+ @log = Dploy::Logger.new(DPLOY_CONFIG['mongo_server'], @deploy_data[:id])
32
25
  end
33
-
26
+
34
27
  def deploy()
35
28
  begin
36
29
  #Get Instances
37
30
  search_tags = { 'project' => @deploy_data[:project], 'environment' => @deploy_data[:environment] }
38
- @log.debug("Searching For EC2 Instances")
39
- @log.debug("Search tags: #{search_tags}")
31
+ @log.debug("Searching For EC2 Instances")
32
+ @log.debug("Search tags: #{search_tags}")
40
33
  instances = @ec2.get_instances_by_tags(search_tags)
41
34
  @log.debug("#{instances.count} matching instances found")
42
-
35
+
43
36
  instances.each do |instance|
44
-
37
+
45
38
  @log.debug("Starting deploy for instance: #{instance.id}")
46
39
  #TODO Remove from LB
47
-
40
+
48
41
  #update chef node
49
42
  node_name = "#{@deploy_data[:environment]}-#{@deploy_data[:project]}-#{instance.id}"
50
43
  @log.debug("Updating chef node: #{node_name}")
51
44
  attributes = { :dploy => { :target_version => @deploy_data[:version], :status => 'deploying' } }
52
45
  @chef.update_node_attributes(node_name, attributes)
53
-
46
+
54
47
  #Run Chef client
55
48
  @log.debug("Running Chef Client for #{node_name} (#{instance.dns_name})")
56
49
  ShellCmd.run("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i #{DPLOY_CONFIG['ec2_ssh_key_path']} ubuntu@#{instance.dns_name} sudo chef-client", @deploy_data[:id])
57
-
50
+
58
51
  #TODO Test
52
+
53
+ end
59
54
  rescue Exception
60
- @log.error($!)
61
- end
62
-
63
- end
64
-
55
+ @log.error($!)
56
+ end
57
+ end
65
58
  end
66
-
67
59
  end
68
60
 
@@ -3,35 +3,34 @@ require 'mongo'
3
3
  module Dploy
4
4
 
5
5
  class Logger
6
-
7
- def initialize(mongo_host, deploy_id)
8
- @log = Mongo::Connection.new(mongo_host).db('log')[deploy_id]
6
+
7
+ def initialize(mongo_host, deploy_id)
8
+ @log = Mongo::Connection.new(mongo_host).db('log')[deploy_id]
9
9
  end
10
-
11
10
  private :log
12
- def log(message, meta_data )
11
+ def log(message, meta_data = {} )
13
12
  @log.insert({:meta_data => meta_data, :message => message})
14
13
  end
15
-
14
+
16
15
  def debug(message, meta_data = {})
17
16
  meta_data.merge({:log_type => 'debug' })
18
17
  log(message, metadata)
19
18
  end
20
-
19
+
21
20
  def error(message, meta_data = {})
22
21
  meta_data.merge({:log_type => 'debug' })
23
22
  log(message, metadata)
24
23
  end
25
-
24
+
26
25
  def completion(message, meta_data = {})
27
26
  meta_data.merge({:log_type => 'debug' })
28
27
  log(message, metadata)
29
28
  end
30
29
 
31
30
  def get_messages(collection, start_id = "000000000000000000000000")
32
- @@db[collection].find(:_id => {"$gt" => BSON::ObjectId(start_id)}).map {|row| row}
31
+ @log.find(:_id => {"$gt" => BSON::ObjectId(start_id)}).map {|row| row}
33
32
  end
34
-
33
+
35
34
  end
36
35
 
37
36
  end
@@ -1,3 +1,3 @@
1
1
  module Dploy
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
16
- requirement: &24476420 !ruby/object:Gem::Requirement
16
+ requirement: &9448920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24476420
24
+ version_requirements: *9448920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: chef
27
- requirement: &24475920 !ruby/object:Gem::Requirement
27
+ requirement: &9448500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *24475920
35
+ version_requirements: *9448500
36
36
  description: deploymoent module for chef and aws
37
37
  email:
38
38
  - james@stylesaint.com
@@ -54,6 +54,7 @@ files:
54
54
  - lib/dploy/logger.rb
55
55
  - lib/dploy/shell_command.rb
56
56
  - lib/dploy/version.rb
57
+ - ubuntu@dploy.internal.stylesaint.com
57
58
  homepage: ''
58
59
  licenses: []
59
60
  post_install_message: