capistrano-hivequeen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,16 @@
1
+ == HiveQueen client
2
+
3
+ Makes your capistrano scripts aware of HiveQueen environments.
4
+
5
+ === Installation
6
+
7
+ In your Gemfile:
8
+
9
+ group :development do
10
+ gem 'capistrano/hivequeen', :require => nil
11
+ end
12
+
13
+ And in your config/deploy.rb:
14
+
15
+ set :hivequeen_endpoint, "http://your.hivequeen.com"
16
+ require 'hivequeen_client'
@@ -0,0 +1,48 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+
5
+ ## Leave these as is they will be modified for you by the rake gemspec task.
6
+ ## If your rubyforge_project name is different, then edit it and comment out
7
+ ## the sub! line in the Rakefile
8
+ s.name = 'capistrano-hivequeen'
9
+ s.version = '0.1.0'
10
+ s.date = '2011-10-03'
11
+
12
+ ## Make sure your summary is short. The description may be as long
13
+ ## as you like.
14
+ s.summary = "Capistrano extensions for interacting with HiveQueen"
15
+ s.description = "Capistrano extensions for interacting with HiveQueen"
16
+
17
+ ## List the primary authors. If there are a bunch of authors, it's probably
18
+ ## better to set the email to an email list or something. If you don't have
19
+ ## a custom homepage, consider using your GitHub URL or the like.
20
+ s.authors = ["Aaron Suggs"]
21
+ s.email = 'aaron@kickstarter.com'
22
+ s.homepage = 'http://github.com/kickstarter/capistrano-hivequeen'
23
+
24
+ ## This sections is only necessary if you have C extensions.
25
+ # s.require_paths << 'ext'
26
+ # s.extensions = %w[ext/extconf.rb]
27
+
28
+ ## If your gem includes any executables, list them here.
29
+ s.executables = []
30
+
31
+ ## Specify any RDoc options here. You'll want to add your README and
32
+ ## LICENSE files to the extra_rdoc_files list.
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.extra_rdoc_files = %w[README.rdoc]
35
+
36
+ ## List your runtime dependencies here. Runtime dependencies are those
37
+ ## that are needed for an end user to actually USE your code.
38
+ s.add_dependency('capistrano-ext')
39
+ s.add_dependency('capistrano')
40
+ s.add_dependency('json')
41
+
42
+ ## List your development dependencies here. Development dependencies are
43
+ ## those that are only needed during development
44
+ #s.add_development_dependency('rake')
45
+
46
+ s.files = `git ls-files`.split("\n")
47
+ s.test_files = `git ls-files -- {spec,tests}/*`.split("\n")
48
+ end
@@ -0,0 +1,53 @@
1
+ # Load environment configuration from HiveQueen
2
+ require "capistrano/hivequeen/server"
3
+
4
+ Capistrano::Configuration.instance(:must_exist).load do
5
+ HiveQueen.endpoint = hivequeen_endpoint
6
+ HiveQueen.logger = logger
7
+
8
+ # Redefine stage tasks from multistage extension
9
+ # Set the list of available stages
10
+ set :stages, HiveQueen.environment_names
11
+ # When no stage is specified, use staging
12
+ set :default_stage, :staging
13
+
14
+ set :repository, HiveQueen.repository
15
+
16
+ # Load capistrano multi-stage extension
17
+ require 'fileutils' # required until https://github.com/capistrano/capistrano-ext/commit/930ca840a0b4adad0ec53546790b3f5ffe726538 is released
18
+ require 'capistrano/ext/multistage'
19
+
20
+ # Redefine stage tasks from multistage extension
21
+ HiveQueen.environments.each do |env|
22
+ name = env['name']
23
+ hive_queen_id = env['id']
24
+
25
+ desc "Use environment #{name}"
26
+ task name do
27
+ set :stage, name.to_sym
28
+ set :environment_id, env['id']
29
+ environment = HiveQueen.roles(hive_queen_id)
30
+ # Check if environment is ready
31
+ unless environment['state'] == 'running'
32
+ abort "Environment #{name} is not ready. State: #{environment['state']}"
33
+ end
34
+
35
+ # Set servers for each role
36
+ environment['roles'].each do |role_name, role_config|
37
+ role(role_name.to_sym) { role_config['servers'] }
38
+ end
39
+
40
+ # Ensure some server designated as db server
41
+ unless roles.key?(:db)
42
+ # Prefer the bg server
43
+ db_server = roles[:bg].servers.first if roles.key?(:bg)
44
+
45
+ # Otherwise, use any server
46
+ db_server ||= roles.values.map{|x| x.servers}.flatten.compact.first
47
+ logger.trace "Using #{db_server} as primary db server"
48
+ role :db, db_server.to_s, :primary => true
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ # HTTP Client for Hive Queen environment configuration
2
+ require 'open-uri'
3
+ require 'json'
4
+ require 'fileutils'
5
+
6
+ # Special cases:
7
+ # - environment not found
8
+ # - environment not ready: fail
9
+ class HiveQueen
10
+ class << self
11
+ attr_accessor :endpoint, :logger
12
+
13
+ def project_data
14
+ @project_data ||= fetch('/projects/kickstarter')
15
+ end
16
+
17
+ def environments
18
+ project_data['environments']
19
+ end
20
+
21
+ def environment_names
22
+ environments.map{|e| e['name'].to_sym }
23
+ end
24
+
25
+ def repository
26
+ project_data['repo']
27
+ end
28
+
29
+ def roles(env_id)
30
+ env_id = env_id.to_sym
31
+ @roles ||= {}
32
+ @roles[env_id] ||= fetch("/environments/#{env_id}")
33
+ end
34
+
35
+ protected
36
+ def fetch(path)
37
+ url = endpoint + path + '.json'
38
+ logger.trace "Fetching #{url}"
39
+ JSON.parse(open(url).read)
40
+ end
41
+
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-hivequeen
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Aaron Suggs
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-03 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: capistrano-ext
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: capistrano
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: Capistrano extensions for interacting with HiveQueen
64
+ email: aaron@kickstarter.com
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ extra_rdoc_files:
70
+ - README.rdoc
71
+ files:
72
+ - README.rdoc
73
+ - capistrano-hivequeen.gemspec
74
+ - lib/capistrano/hivequeen.rb
75
+ - lib/capistrano/hivequeen/server.rb
76
+ has_rdoc: true
77
+ homepage: http://github.com/kickstarter/capistrano-hivequeen
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !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
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.6.2
107
+ signing_key:
108
+ specification_version: 2
109
+ summary: Capistrano extensions for interacting with HiveQueen
110
+ test_files: []
111
+