veronic 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/veronic CHANGED
@@ -3,13 +3,10 @@
3
3
  require 'rubygems'
4
4
  require 'optparse'
5
5
  require 'yaml'
6
- require "cgi"
7
6
 
8
- require_relative '../lib/deployer'
7
+ require_relative '../lib/veronic'
9
8
 
10
9
  file = __FILE__
11
- path = File.dirname($0)
12
- config_file = File.exists?('/etc/veronic/veronic.yml') ? '/etc/veronic/veronic.yml' : path + '/veronic.yml'
13
10
 
14
11
  options = {}
15
12
 
@@ -31,18 +28,17 @@ opt_parser = OptionParser.new do |opt|
31
28
  opt.separator ""
32
29
  opt.separator "Options"
33
30
 
34
- options[:config_file] = ENV['config_file'] || config_file
31
+ options[:config_file] = ENV['config_file']
35
32
  opt.on("-c","--config_file veronic.yml","Use specific config file") do |c|
36
33
  options[:config_file] = c
37
34
  end
38
- CONFIG = YAML.load_file(options[:config_file])
39
35
 
40
- options[:environment] = ENV['environment'] || 'branch'
36
+ options[:environment] = ENV['environment']
41
37
  opt.on("-E","--environment ENVIRONMENT","Which environment you want box run") do |e|
42
38
  options[:environment] = e
43
39
  end
44
40
 
45
- options[:name] = ENV['name'] || 'sitemap-generator-45625091'
41
+ options[:name] = ENV['name']
46
42
  opt.on("-N","--node-name NAME","Which node name you want for the box") do |n|
47
43
  options[:name] = n
48
44
  end
@@ -52,42 +48,42 @@ opt_parser = OptionParser.new do |opt|
52
48
  options[:branch] = b
53
49
  end
54
50
 
55
- options[:ssh_user] = ENV['ssh_user'] || "ubuntu"
51
+ options[:ssh_user] = ENV['ssh_user']
56
52
  opt.on("-u","--ssh_user ssh_user","Which ssh user use to connect box") do |s|
57
53
  options[:ssh_user] = s
58
54
  end
59
55
 
60
- options[:ssh_port] = ENV['ssh_port'] || 22
56
+ options[:ssh_port] = ENV['ssh_port']
61
57
  opt.on("-p","--ssh_port ssh_port","Which ssh port use to connect box") do |p|
62
58
  options[:ssh_port] = p
63
59
  end
64
60
 
65
- options[:identity_file] = ENV['identity_file'] || CONFIG['identity_file']
61
+ options[:identity_file] = ENV['identity_file']
66
62
  opt.on("-i","--identity_file identity_file.pem","Which file use by ssh to connect box") do |i|
67
63
  options[:identity_file] = i
68
64
  end
69
65
 
70
- options[:role] = ENV['role'] || 'beta'
66
+ options[:role] = ENV['role']
71
67
  opt.on("-r","--role role","Which role use to deploy the box") do |r|
72
68
  options[:role] = r
73
69
  end
74
70
 
75
- options[:flavor] = ENV['flavor'] || 'm1.medium'
71
+ options[:flavor] = ENV['flavor']
76
72
  opt.on("-f","--flavor flavor","Which flavor use to deploy the box") do |f|
77
73
  options[:flavor] = f
78
74
  end
79
75
 
80
- options[:dns_zone_name] = ENV['dns_zone_name'] || 'aipotfil.com'
76
+ options[:dnsprovider_zone_name] = ENV['dnsprovider_zone_name']
81
77
  opt.on("-d","--dns_zone_name dns_zone_name","Which dns zone use for the box's dns") do |d|
82
- options[:dns_zone_name] = d
78
+ options[:dnsprovider_zone_name] = d
83
79
  end
84
80
 
85
- options[:security_groups] = ENV['security_groups'] || 'public-web'
81
+ options[:security_groups] = ENV['security_groups']
86
82
  opt.on("-S","--security_groups security_groups","Which security groups use for the box") do |s|
87
83
  options[:security_groups] = s
88
84
  end
89
85
 
90
- options[:deploy_cmd] = ENV['deploy_cmd'] || 'sudo chef-client'
86
+ options[:deploy_cmd] = ENV['deploy_cmd']
91
87
  opt.on("-D","--deploy_cmd security_groups","Which command line us to deploy the box") do |dc|
92
88
  options[:deploy_cmd] = dc
93
89
  end
@@ -97,64 +93,30 @@ end
97
93
 
98
94
  opt_parser.parse!
99
95
 
100
- config = {}
101
- config[:dnsprovider] = :route53
102
- config[:cloudprovider] = :ec2
103
- config[:configprovider] = :chefserver
104
- config[:dnsprovider_access_key_id] = CONFIG['dnsprovider_access_key_id']
105
- config[:dnsprovider_secret_access_key] = CONFIG['dnsprovider_secret_access_key']
106
- config[:cloudprovider_access_key_id] = CONFIG['cloudprovider_access_key_id']
107
- config[:cloudprovider_secret_access_key] = CONFIG['cloudprovider_secret_access_key']
108
- config[:cloudprovider_images_owner_id] = CONFIG['cloudprovider_images_owner_id']
109
- config[:dnsprovider_zone_url] = CONFIG['dnsprovider_zone_url']
110
- config[:region] = CONFIG['us-east-1']
111
- config[:availability_zone] = CONFIG['us-east-1b']
112
- config[:aws_ssh_key_id] = CONFIG['aws_ssh_key_id']
113
- config[:node_name] = CONFIG['node_name']
114
- config[:client_key] = CONFIG['client_key']
115
- config[:validation_client_name] = CONFIG['validation_client_name']
116
- config[:validation_key] = CONFIG['validation_key']
117
- config[:chef_server_url] = CONFIG['chef_server_url']
118
- config[:ssl_version] = CONFIG['ssl_version']
119
- config[:identity_file] = options[:identity_file]
120
- config[:dnsprovider_zone_name] = "#{options[:dns_zone_name]}."
121
- config[:branch] = options[:branch]
122
- config[:environment] = options[:environment]
123
- config[:name] = options[:branch] ? options[:branch] : options[:name]
124
- config[:ssh_user] = options[:ssh_user]
125
- config[:ssh_port] = options[:ssh_port]
126
- config[:role] = options[:role]
127
- config[:roles] = "role[#{options[:role]}]"
128
- config[:flavor] = options[:flavor]
129
- config[:domain] = options[:dns_zone_name]
130
- config[:security_groups] = [options[:security_groups]]
131
- config[:deploy_cmd] = options[:deploy_cmd]
132
- config[:dns_array] = ["#{config[:name]}.#{options[:dns_zone_name]}", "#{config[:name]}.core.#{options[:dns_zone_name]}", "#{config[:name]}.store.#{options[:dns_zone_name]}", "*.#{config[:name]}.store.#{options[:dns_zone_name]}"]
133
-
134
96
  case ARGV[0] || ENV['action']
135
97
  when "create"
136
- Deployer.new(config).create
98
+ Veronic::Deployer.new(options).create
137
99
  when "bootstrap"
138
- Deployer.new(config).bootstrap
100
+ Veronic::Deployer.new(options).bootstrap
139
101
  when "destroy"
140
- Deployer.new(config).destroy
102
+ Veronic::Deployer.new(options).destroy
141
103
  when "deploy"
142
- Deployer.new(config).deploy
104
+ Veronic::Deployer.new(options).deploy
143
105
  when "deploy_stacks"
144
- Deployer.new(config).deploy_stacks
106
+ Veronic::Deployer.new(options).deploy_stacks
145
107
  when "deploy_apps"
146
- Deployer.new(config).deploy_apps
108
+ Veronic::Deployer.new(options).deploy_apps
147
109
  when "run_tests"
148
- Deployer.new(config).run_tests
110
+ Veronic::Deployer.new(options).run_tests
149
111
  when "update_instance_dns"
150
- Deployer.new(config).update_instance_dns
112
+ Veronic::Deployer.new(options).update_instance_dns
151
113
  when "stop"
152
- Deployer.new(config).stop
114
+ Veronic::Deployer.new(options).stop
153
115
  when "start"
154
- Deployer.new(config).start
155
- Deployer.new(config).update_instance_dns
116
+ Veronic::Deployer.new(options).start
117
+ Veronic::Deployer.new(options).update_instance_dns
156
118
  when "list"
157
- Deployer.new(config).instances_list
119
+ Veronic::Deployer.new(options).instances_list
158
120
  else
159
121
  puts opt_parser
160
122
  end
@@ -0,0 +1,47 @@
1
+ module Veronic
2
+ class Config
3
+ attr_accessor :dnsprovider, :cloudprovider, :configprovider, :dnsprovider_access_key_id, :dnsprovider_secret_access_key, :cloudprovider_access_key_id, :cloudprovider_secret_access_key, :cloudprovider_images_owner_id, :dnsprovider_zone_url, :dnsprovider_zone_name, :region, :availability_zone, :aws_ssh_key_id, :node_name, :client_key, :validation_client_name, :validation_key, :chef_server_url, :ssl_version, :identity_file, :branch, :environment, :ssh_user, :ssh_port, :role, :flavor, :security_groups, :deploy_cmd, :name, :image
4
+
5
+ def initialize(options={})
6
+ config_file = File.exists?('/etc/veronic/veronic.yml') ? '/etc/veronic/veronic.yml' : '../../' + File.dirname($0) + '/veronic.yml'
7
+ config_from_file = YAML.load_file(options[:config_file] || config_file)
8
+
9
+ @dnsprovider = :route53
10
+ @cloudprovider = :ec2
11
+ @configprovider = :chefserver
12
+ @dnsprovider_access_key_id = options[:dnsprovider_access_key_id] || config_from_file['dnsprovider_access_key_id']
13
+ @dnsprovider_secret_access_key = options[:dnsprovider_secret_access_key] || config_from_file['dnsprovider_secret_access_key']
14
+ @cloudprovider_access_key_id = options[:cloudprovider_access_key_id] || config_from_file['cloudprovider_access_key_id']
15
+ @cloudprovider_secret_access_key = options[:cloudprovider_secret_access_key] || config_from_file['cloudprovider_secret_access_key']
16
+ @cloudprovider_images_owner_id = options[:cloudprovider_images_owner_id] || config_from_file['cloudprovider_images_owner_id']
17
+ @dnsprovider_zone_url = options[:dnsprovider_zone_url] || config_from_file['dnsprovider_zone_url']
18
+ @dnsprovider_zone_name = options[:dnsprovider_zone_name] || config_from_file['dnsprovider_zone_name']
19
+ @region = options[:region] || config_from_file['region']
20
+ @availability_zone = options[:availability_zone] || config_from_file['availability_zone']
21
+ @aws_ssh_key_id = options[:aws_ssh_key_id] || config_from_file['aws_ssh_key_id']
22
+ @node_name = options[:node_name] || config_from_file['node_name']
23
+ @client_key = options[:client_key] || config_from_file['client_key']
24
+ @validation_client_name = options[:validation_client_name] || config_from_file['validation_client_name']
25
+ @validation_key = options[:validation_key] || config_from_file['validation_key']
26
+ @chef_server_url = options[:chef_server_url] || config_from_file['chef_server_url']
27
+ @ssl_version = options[:ssl_version] || config_from_file['ssl_version']
28
+ @identity_file = options[:identity_file] || config_from_file['identity_file']
29
+ @branch = options[:branch] || config_from_file['branch']
30
+ @environment = options[:environment] || config_from_file['environment'] || 'beta'
31
+ @ssh_user = options[:ssh_user] || config_from_file['ssh_user'] || 'ubuntu'
32
+ @ssh_port = options[:ssh_port] || config_from_file['ssh_port'] || 22
33
+ @role = options[:role] || config_from_file['role'] || 'default'
34
+ @flavor = options[:flavor] || config_from_file['flavor'] || 'm1.medium'
35
+ @security_groups = [options[:security_groups]] || [config_from_file['security_groups']]
36
+ @deploy_cmd = options[:deploy_cmd] || config_from_file['deploy_cmd'] || 'sudo chef-client'
37
+ @name = (options[:branch] || config_from_file['branch']) ? (options[:branch] || config_from_file['branch']) : (options[:name] || config_from_file['name'])
38
+ @image = nil
39
+ end
40
+
41
+ def to_hash
42
+ hash = {}
43
+ self.instance_variables.each {|var| hash[var.to_s.delete("@").to_sym] = self.instance_variable_get(var) }
44
+ return hash
45
+ end
46
+ end
47
+ end
@@ -23,7 +23,7 @@ module Provider
23
23
  @identity_file = config[:identity_file]
24
24
  @aws_ssh_key_id = config[:aws_ssh_key_id]
25
25
  @environment = config[:environment]
26
- @roles = config[:roles]
26
+ @roles = "role[#{config[:role]}]"
27
27
  @flavor = config[:flavor]
28
28
  @region = config[:region]
29
29
  @availability_zone = config[:availability_zone]
@@ -8,7 +8,7 @@ module Provider
8
8
  def initialize(config)
9
9
  @access_key_id = config[:dnsprovider_access_key_id]
10
10
  @secret_access_key = config[:dnsprovider_secret_access_key]
11
- @zone_name = config[:dnsprovider_zone_name]
11
+ @zone_name = config[:dnsprovider_zone_name] || '' + '.'
12
12
  @zone_url = config[:dnsprovider_zone_url]
13
13
  @r53 = r53
14
14
  @zone = zone
@@ -19,7 +19,7 @@ module Provider
19
19
  end
20
20
 
21
21
  def zone
22
- Provider::R53::Zone.new(@r53, @zone_name, @zone_url)
22
+ Provider::R53::Zone.new(@r53, @zone_name, @zone_url) rescue puts 'Bad DNS settings'
23
23
  end
24
24
 
25
25
  end
data/lib/veronic.rb ADDED
@@ -0,0 +1,130 @@
1
+ require_relative 'config/config'
2
+ require_relative 'providers/cloudprovider'
3
+ require_relative 'providers/dnsprovider'
4
+ require_relative 'providers/configprovider'
5
+
6
+ module Veronic
7
+ class Deployer
8
+
9
+ def initialize(options={})
10
+ @config = config(options)
11
+ @config_hash = @config.to_hash
12
+ @role = @config_hash[:role]
13
+ @environment = @config_hash[:environment]
14
+ @deploy_cmd = @config_hash[:deploy_cmd]
15
+ end
16
+
17
+ def config
18
+ @config || Veronic::Config.new
19
+ end
20
+
21
+ def config(options={})
22
+ @config || Veronic::Config.new(options)
23
+ end
24
+
25
+ def configprovider
26
+ ConfigProvider.new(@config_hash)
27
+ end
28
+
29
+ def dnsprovider
30
+ DnsProvider.new(@config_hash)
31
+ end
32
+
33
+ def cloudprovider
34
+ CloudProvider.new(@config_hash)
35
+ end
36
+
37
+ def create
38
+ unless bootstrap
39
+ configprovider.instance.create
40
+ end
41
+ end
42
+
43
+ def deploy_stacks
44
+ bootstrap
45
+ query = cloudprovider.instance.dns_name
46
+ deploy_cmd = 'sudo chef-client -l debug'
47
+ manual = true
48
+ configprovider.ssh(query, deploy_cmd, manual)
49
+ end
50
+
51
+ def deploy_apps
52
+ if bootstrap
53
+ deploy_stacks
54
+ end
55
+ query = cloudprovider.instance.dns_name
56
+ deploy_cmd = 'sudo chef-client -o "recipe[lift_envs::app_deploy]" -l debug'
57
+ manual = true
58
+ configprovider.ssh(query, deploy_cmd, manual)
59
+ end
60
+
61
+ def run_tests
62
+ if bootstrap
63
+ deploy_stacks
64
+ deploy_apps
65
+ end
66
+ query = cloudprovider.instance.dns_name
67
+ deploy_cmd = 'sudo chef-client -o "recipe[lift_envs::app_testing]" -l debug'
68
+ manual = true
69
+ configprovider.ssh(query, deploy_cmd, manual)
70
+ end
71
+
72
+ def destroy
73
+ if cloudprovider.instance.exist?
74
+ configprovider.instance.destroy([cloudprovider.instance.id])
75
+ else
76
+ configprovider.instance.destroy([])
77
+ end
78
+ end
79
+
80
+ def deploy
81
+ if cloudprovider.instance.exist?
82
+ if @environment == 'branch'
83
+ query = cloudprovider.instance.dns_name
84
+ manual = true
85
+ else
86
+ query = "role:#{@role}"
87
+ manual = false
88
+ end
89
+ configprovider.ssh(query, @deploy_cmd, manual)
90
+ end
91
+ end
92
+
93
+ def update_instance_dns
94
+ @dns_array.each do |dns|
95
+ puts "Setting DNS #{dns} ..."
96
+ dnsprovider.zone.record.new(dnsprovider.zone, dns, [cloudprovider.instance.public_ip_address], "A", "10")
97
+ puts "DNS #{dns} updated"
98
+ end
99
+ end
100
+
101
+ def instances_list
102
+ cloudprovider.instances_list
103
+ end
104
+
105
+ def stop
106
+ cloudprovider.instance.stop
107
+ end
108
+
109
+ def start
110
+ cloudprovider.instance.start
111
+ update_instance_dns
112
+ end
113
+
114
+ def bootstrap
115
+ @config.image = cloudprovider.image.id
116
+ if cloudprovider.instance.status == :running
117
+ return false
118
+ elsif cloudprovider.instance.status == :stopped
119
+ start
120
+ return false
121
+ elsif cloudprovider.instance.exist? == false
122
+ configprovider.instance.bootstrap
123
+ configprovider.instance.set_role
124
+ return true
125
+ else
126
+ raise ArgumentError.new('Error during connecting instance')
127
+ end
128
+ end
129
+ end
130
+ end
data/veronic.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'veronic'
3
- s.version = '0.0.4'
3
+ s.version = '0.0.5'
4
4
  s.date = '2013-04-05'
5
5
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
6
6
  s.summary = "Veronic, deux qui la tiennent trois qui la niquent"
data/veronic.yml CHANGED
@@ -1,16 +1,25 @@
1
- dnsprovider_access_key_id:
2
- dnsprovider_secret_access_key:
3
- dnsprovider_zone_url:
4
- cloudprovider_access_key_id:
5
- cloudprovider_secret_access_key:
6
- cloudprovider_images_owner_id:
7
- region:
8
- availability_zone:
9
- aws_ssh_key_id:
1
+ dnsprovider_access_key_id:
2
+ dnsprovider_secret_access_key:
3
+ cloudprovider_access_key_id:
4
+ cloudprovider_secret_access_key:
5
+ cloudprovider_images_owner_id:
6
+ dnsprovider_zone_url:
7
+ dnsprovider_zone_name:
8
+ region:
9
+ availability_zone:
10
+ aws_ssh_key_id:
10
11
  node_name:
11
- chef_server_url:
12
- validation_client_name:
12
+ client_key:
13
+ validation_client_name:
13
14
  validation_key:
14
- client_key:
15
- identity_file:
16
- ssl_version:
15
+ chef_server_url:
16
+ ssl_version:
17
+ identity_file:
18
+ branch:
19
+ environment:
20
+ ssh_user:
21
+ ssh_port:
22
+ role:
23
+ flavor:
24
+ security_groups:
25
+ deploy_cmd:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: veronic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -21,7 +21,7 @@ files:
21
21
  - .gitignore
22
22
  - README.md
23
23
  - bin/veronic
24
- - lib/deployer.rb
24
+ - lib/config/config.rb
25
25
  - lib/providers/chefserver/chefserver.rb
26
26
  - lib/providers/chefserver/instance.rb
27
27
  - lib/providers/chefserver/rest_request.rb
@@ -34,6 +34,7 @@ files:
34
34
  - lib/providers/route53/r53.rb
35
35
  - lib/providers/route53/record.rb
36
36
  - lib/providers/route53/zone.rb
37
+ - lib/veronic.rb
37
38
  - veronic.gemspec
38
39
  - veronic.yml
39
40
  homepage: http://github.com/GabKlein/veronic
data/lib/deployer.rb DELETED
@@ -1,109 +0,0 @@
1
- require_relative 'providers/cloudprovider'
2
- require_relative 'providers/dnsprovider'
3
- require_relative 'providers/configprovider'
4
-
5
- class Deployer
6
-
7
- def initialize(config)
8
- @role = config[:role]
9
- @environment = config[:environment]
10
- @deploy_cmd = config[:deploy_cmd]
11
- @dns_array = config[:dns_array]
12
- @cloudprovider = CloudProvider.new(config)
13
- config[:image] = @cloudprovider.image.id
14
- @dnsprovider = DnsProvider.new(config)
15
- @configprovider = ConfigProvider.new(config)
16
- end
17
-
18
- def create
19
- if bootstrap
20
- @configprovider.instance.create
21
- end
22
- end
23
-
24
- def deploy_stacks
25
- bootstrap
26
- query = @cloudprovider.instance.dns_name
27
- deploy_cmd = 'sudo chef-client -l debug'
28
- manual = true
29
- @configprovider.ssh(query, deploy_cmd, manual)
30
- end
31
-
32
- def deploy_apps
33
- unless bootstrap
34
- deploy_stacks
35
- end
36
- query = @cloudprovider.instance.dns_name
37
- deploy_cmd = 'sudo chef-client -o "recipe[lift_envs::app_deploy]" -l debug'
38
- manual = true
39
- @configprovider.ssh(query, deploy_cmd, manual)
40
- end
41
-
42
- def run_tests
43
- unless bootstrap
44
- deploy_stacks
45
- deploy_apps
46
- end
47
- query = @cloudprovider.instance.dns_name
48
- deploy_cmd = 'sudo chef-client -o "recipe[lift_envs::app_testing]" -l debug'
49
- manual = true
50
- @configprovider.ssh(query, deploy_cmd, manual)
51
- end
52
-
53
- def destroy
54
- if @cloudprovider.instance.exist?
55
- @configprovider.instance.destroy([@cloudprovider.instance.id])
56
- else
57
- @configprovider.instance.destroy([])
58
- end
59
- end
60
-
61
- def deploy
62
- if @cloudprovider.instance.exist?
63
- if @environment == 'branch'
64
- query = @cloudprovider.instance.dns_name
65
- manual = true
66
- else
67
- query = "role:#{@role}"
68
- manual = false
69
- end
70
- @configprovider.ssh(query, @deploy_cmd, manual)
71
- end
72
- end
73
-
74
- def update_instance_dns
75
- @dns_array.each do |dns|
76
- puts "Setting DNS #{dns} ..."
77
- @dnsprovider.zone.record.new(@dnsprovider.zone, dns, [@cloudprovider.instance.public_ip_address], "A", "10")
78
- puts "DNS #{dns} updated"
79
- end
80
- end
81
-
82
- def instances_list
83
- @cloudprovider.instances_list
84
- end
85
-
86
- def stop
87
- @cloudprovider.instance.stop
88
- end
89
-
90
- def start
91
- @cloudprovider.instance.start
92
- update_instance_dns
93
- end
94
-
95
- def bootstrap
96
- if @cloudprovider.instance.status == :running
97
- return true
98
- elsif @cloudprovider.instance.status == :stopped
99
- start
100
- return true
101
- elsif @cloudprovider.instance.exist? == false
102
- @configprovider.instance.bootstrap
103
- @configprovider.instance.set_role
104
- return false
105
- else
106
- raise ArgumentError.new('Error during connecting instance')
107
- end
108
- end
109
- end