brighter_planet_deploy 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless RUBY_VERSION >= '1.9'
4
+ require 'rubygems'
5
+ end
6
+ require 'brighter_planet_deploy'
7
+
8
+ module BrighterPlanet
9
+ class Deploy
10
+ class CLI < ::Thor
11
+ desc 'write', 'takes a bunch of config options and saves them with brighter_planet_deploy'
12
+ method_option :rails_root, :type => :string, :default => ::Dir.pwd
13
+ method_option :resque_redis_url, :type => :string
14
+ method_option :incoming_queue, :type => :string
15
+ method_option :color, :type => :string
16
+ method_option :role, :type => :string
17
+ method_option :environment, :type => :string
18
+ method_option :log_dir, :type => :string
19
+ method_option :phase, :type => :string
20
+ method_option :carrier, :type => :string
21
+ method_option :ey_app, :type => :string
22
+ method_option :service, :type => :string
23
+ def write
24
+ me = ::BrighterPlanet.deploy.servers.me
25
+ me.rails_root = options[:rails_root]
26
+ options.each do |k, v|
27
+ me.send("#{k}=", v)
28
+ end
29
+ me.save
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ BrighterPlanet::Deploy::CLI.start
@@ -22,5 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency 'test-unit'
23
23
  s.add_development_dependency 'fakeweb'
24
24
  s.add_development_dependency 'fakefs'
25
+ s.add_development_dependency 'net-dns'
26
+ s.add_development_dependency 'activesupport'
27
+ s.add_development_dependency 'i18n'
25
28
  s.add_dependency 'eat'
26
29
  end
@@ -0,0 +1,35 @@
1
+ require 'net/dns/resolver'
2
+ module BrighterPlanet
3
+ class Deploy
4
+ class AuthoritativeDnsResolver
5
+ # sabshere 5/4/11 last updated
6
+ NAMESERVERS = {
7
+ 'ns1.easydns.com' => '66.225.199.10',
8
+ 'ns2.easydns.com' => '72.52.2.1',
9
+ }
10
+
11
+ class << self
12
+ def getaddress(domain)
13
+ new(domain).getaddress
14
+ end
15
+ end
16
+
17
+ attr_reader :domain
18
+
19
+ def initialize(domain)
20
+ @domain = domain
21
+ end
22
+
23
+ def getaddress
24
+ resolver = ::Net::DNS::Resolver.new :nameservers => NAMESERVERS.values, :use_tcp => false, :config_file => empty_config_file_path
25
+ packet = resolver.search domain, ::Net::DNS::A, ::Net::DNS::IN
26
+ packet.answer[0].address.to_s
27
+ end
28
+
29
+ # net-dns always looks for this, so give it something empty
30
+ def empty_config_file_path
31
+ ::File.expand_path '../../../support/empty_resolv.conf', __FILE__
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,7 +3,9 @@ module BrighterPlanet
3
3
  class EmissionEstimateService
4
4
  include ::Singleton
5
5
  include ReadsFromPublicUrl
6
-
6
+
7
+ RED_IP = '184.73.240.13'
8
+
7
9
  WANTS = [
8
10
  :resque_redis_url,
9
11
  :incoming_queue,
@@ -14,16 +16,29 @@ module BrighterPlanet
14
16
  :phase,
15
17
  :carrier, # amazon
16
18
  :ey_app, # cm1_edge_blue
19
+ :service
17
20
  ]
18
-
21
+
22
+ def domain
23
+ 'carbon.brighterplanet.com'
24
+ end
25
+
19
26
  def endpoint
20
- 'http://carbon.brighterplanet.com'
27
+ "http://#{domain}"
21
28
  end
22
29
 
23
30
  def name
24
31
  'EmissionEstimateService'
25
32
  end
26
-
33
+
34
+ def color
35
+ if Deploy.instance.servers.me.service == 'EmissionEstimateService'
36
+ (AuthoritativeDnsResolver.getaddress(domain) == RED_IP) ? 'red' : 'blue'
37
+ else
38
+ from_public_url :color
39
+ end
40
+ end
41
+
27
42
  def method_missing(method_id, *args)
28
43
  if args.length == 0 and not block_given?
29
44
  from_public_url method_id
@@ -13,7 +13,7 @@ module BrighterPlanet
13
13
  from_file public_brighter_planet_deploy_path(k)
14
14
  end
15
15
 
16
- def write_config(config = {})
16
+ def write(config = {})
17
17
  [ :public, :private ].each do |loc|
18
18
  config[loc].each do |k, v|
19
19
  path = send("#{loc}_brighter_planet_deploy_path", k)
@@ -23,7 +23,7 @@ module BrighterPlanet
23
23
  end
24
24
  end
25
25
 
26
- def save_config
26
+ def save
27
27
  public = {}
28
28
  private = {}
29
29
  instance_variables.each do |k|
@@ -37,7 +37,7 @@ module BrighterPlanet
37
37
  end
38
38
  end
39
39
  end
40
- write_config :public => public, :private => private
40
+ write :public => public, :private => private
41
41
  end
42
42
 
43
43
  private
@@ -1,5 +1,5 @@
1
1
  module BrighterPlanet
2
2
  class Deploy
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -11,6 +11,7 @@ module BrighterPlanet
11
11
 
12
12
  autoload :Server, 'brighter_planet_deploy/server'
13
13
  autoload :EmissionEstimateService, 'brighter_planet_deploy/emission_estimate_service'
14
+ autoload :AuthoritativeDnsResolver, 'brighter_planet_deploy/authoritative_dns_resolver'
14
15
 
15
16
  # mixins
16
17
  autoload :ReadsFromLocalFilesystem, 'brighter_planet_deploy/reads_from_local_filesystem'
File without changes
data/test/helper.rb CHANGED
@@ -9,3 +9,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  require 'brighter_planet_deploy'
10
10
  class Test::Unit::TestCase
11
11
  end
12
+
13
+ require 'active_support/core_ext/module'
14
+ module Rails
15
+ mattr_accessor :root, :env
16
+ end
data/test/test_cm1.rb CHANGED
@@ -19,8 +19,8 @@ class TestCm1 < Test::Unit::TestCase
19
19
  FileUtils.mkdir_p '/data/randomeyappname/current/public/brighter_planet_deploy'
20
20
  File.open('/data/randomeyappname/current/public/brighter_planet_deploy/color', 'w') { |f| f.write 'blue' }
21
21
 
22
+ Rails.root = '/data/randomeyappname/current'
22
23
  @me = BrighterPlanet.deploy.servers.me
23
- @me.rails_root = '/data/randomeyappname/current'
24
24
  end
25
25
 
26
26
  def teardown
@@ -48,18 +48,17 @@ class TestCm1 < Test::Unit::TestCase
48
48
  assert @me.resque_redis_url.include?('active')
49
49
  end
50
50
 
51
- def test_006_write_config
52
- @me.write_config :public => { :color => '-bar-' }, :private => { :resque_redis_url => 'foo[COLOR]baz' }
51
+ def test_006_write
52
+ @me.write :public => { :color => '-bar-' }, :private => { :resque_redis_url => 'foo[COLOR]baz' }
53
53
  assert_equal '-bar-', @me.color
54
54
  assert_equal 'foo-bar-baz', @me.resque_redis_url
55
55
  end
56
56
 
57
- def test_007_save_config
57
+ def test_007_save
58
58
  @me.color = '-zzz-'
59
59
  @me.resque_redis_url = 'fie[COLOR]bang'
60
- @me.save_config
60
+ @me.save
61
61
  me2 = BrighterPlanet.deploy.servers.me
62
- me2.rails_root = '/data/randomeyappname/current'
63
62
  assert_equal '-zzz-', me2.color
64
63
  assert_equal 'fie-zzz-bang', me2.resque_redis_url
65
64
  end
@@ -68,4 +67,14 @@ class TestCm1 < Test::Unit::TestCase
68
67
  def test_008_phase
69
68
  assert_equal 'edge', @me.phase
70
69
  end
70
+
71
+ def test_009_color_from_cm1_itself
72
+ FakeFS.deactivate!
73
+ Rails.root = File.expand_path("../tmp", __FILE__)
74
+ @me.service = 'EmissionEstimateService'
75
+ @me.save
76
+ assert_equal 'red', BrighterPlanet.deploy.emission_estimate_service.color
77
+ ensure
78
+ FileUtils.rm_rf File.expand_path("../tmp", __FILE__)
79
+ end
71
80
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brighter_planet_deploy
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-04 00:00:00 Z
19
+ date: 2011-05-05 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: test-unit
@@ -61,7 +61,7 @@ dependencies:
61
61
  type: :development
62
62
  version_requirements: *id003
63
63
  - !ruby/object:Gem::Dependency
64
- name: eat
64
+ name: net-dns
65
65
  prerelease: false
66
66
  requirement: &id004 !ruby/object:Gem::Requirement
67
67
  none: false
@@ -72,13 +72,55 @@ dependencies:
72
72
  segments:
73
73
  - 0
74
74
  version: "0"
75
- type: :runtime
75
+ type: :development
76
76
  version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: activesupport
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: i18n
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :development
104
+ version_requirements: *id006
105
+ - !ruby/object:Gem::Dependency
106
+ name: eat
107
+ prerelease: false
108
+ requirement: &id007 !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ type: :runtime
118
+ version_requirements: *id007
77
119
  description: Brighter Planet deployment system, published as the gem brighter_planet_deploy. Internal use.
78
120
  email:
79
121
  - seamus@abshere.net
80
- executables: []
81
-
122
+ executables:
123
+ - brighter_planet_deploy
82
124
  extensions: []
83
125
 
84
126
  extra_rdoc_files: []
@@ -87,13 +129,16 @@ files:
87
129
  - .gitignore
88
130
  - Gemfile
89
131
  - Rakefile
132
+ - bin/brighter_planet_deploy
90
133
  - brighter_planet_deploy.gemspec
91
134
  - lib/brighter_planet_deploy.rb
135
+ - lib/brighter_planet_deploy/authoritative_dns_resolver.rb
92
136
  - lib/brighter_planet_deploy/emission_estimate_service.rb
93
137
  - lib/brighter_planet_deploy/reads_from_local_filesystem.rb
94
138
  - lib/brighter_planet_deploy/reads_from_public_url.rb
95
139
  - lib/brighter_planet_deploy/server.rb
96
140
  - lib/brighter_planet_deploy/version.rb
141
+ - support/empty_resolv.conf
97
142
  - test/helper.rb
98
143
  - test/test_cm1.rb
99
144
  homepage: ""