capistrano-hivequeen 7.4.0 → 7.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 67f903743b80936b84b7805fb2696cc374f8cce0
4
- data.tar.gz: 236886bf3acf2d21c448110b8dd199fd9ce7ff10
2
+ SHA256:
3
+ metadata.gz: 72b660b02784362a5c9a2f8a96a3355a3fd18fb399b57d138942488f89b16b10
4
+ data.tar.gz: da9503dc5137e661476abba23820112d59bd4033d0775dbd015e449a0ee889f2
5
5
  SHA512:
6
- metadata.gz: 2dbeb44a087ed1cf83309119aa99720c06c098093f37af06b101f0886a2d63cef9ccb50a766418917ecff474cf113cb678bd6a8802111ada46acc7c8dbbf9ad0
7
- data.tar.gz: a5e4df1174d6c591143ee1451caa23d713b9f0cdfe28771c3c7bfba78f4cc620ec6cd25f31163e6f00c04244dc38f6a37edda16da276a164100b61b7c8b4f1fb
6
+ metadata.gz: 96e6bb88e860b84984b32501ac7be9135364b4ad16a4a644540e8b3cb9f30e655f20f829b5bdcf085e4fc8ba4ddc54d18cc1f36a9a59bef356de48af5f37080a
7
+ data.tar.gz: ca952a870f3db6dafbc36701dcb6708a2902d611fd1abf57783be5607bd3fc0b62523f81ebfd2e7c8f19b45741a549ab7704d79b548c56220185392069bcb6ed
data/README.rdoc CHANGED
@@ -27,6 +27,12 @@ And in your config/deploy.rb:
27
27
 
28
28
  cap staging deploy -s branch=some_feature
29
29
 
30
+ === Releasing a new version
31
+ First, bump the version in lib/capistrano/hivequeen/version.rb. Then:
32
+
33
+ gem build capistrano-hivequeen.gemspec
34
+ gem push capistrano-hivequeen-$VERSION.gem
35
+
30
36
  == License
31
37
 
32
38
  @copy; Copyright Kickstarter, PBC.
@@ -38,6 +38,8 @@ Gem::Specification.new do |s|
38
38
 
39
39
  ## List your runtime dependencies here. Runtime dependencies are those
40
40
  ## that are needed for an end user to actually USE your code.
41
+ s.add_dependency('aws-sdk-ec2', '~> 1.0')
42
+ s.add_dependency('aws-sdk-ec2instanceconnect', '~> 1.0')
41
43
  s.add_dependency('capistrano', '>= 2.11.0')
42
44
  s.add_dependency('activesupport', '>= 3.0.0')
43
45
  s.add_dependency('json')
@@ -15,6 +15,9 @@ Capistrano::Configuration.instance(:must_exist).load do
15
15
  # From the command line, use -s override=true to force a deployment
16
16
  set :override, false
17
17
 
18
+ # Don't mark deployments as canary deployments by default
19
+ set :canary, false
20
+
18
21
  # Command to get the changes being deployed
19
22
  set :changelog_command do
20
23
  `git log #{current_commit}...#{real_revision} --pretty="%n%h %an: %s (%ar)" --stat --no-color`
@@ -75,7 +78,7 @@ Capistrano::Configuration.instance(:must_exist).load do
75
78
  if exists?(:az)
76
79
  servers = servers.select {|s| s['availability_zone'] == az}
77
80
  end
78
- role(role_name.to_sym) { servers.map {|s| s['public_dns']} }
81
+ role(role_name.to_sym) { servers.map {|s| s['public_dns'] || s['private_dns']} }
79
82
  end
80
83
 
81
84
  # Ensure some server designated as db server
@@ -94,14 +97,18 @@ Capistrano::Configuration.instance(:must_exist).load do
94
97
  command_format = "ssh -t -A -l %s %s"
95
98
  env['roles'].keys.each do |role_name|
96
99
  task role_name do
97
- cmd = command_format % [user, roles[role_name.to_sym].servers.first]
100
+ server = roles[role_name.to_sym].servers.sample
101
+ HiveQueen.ec2_instance_connect(server.host)
102
+ cmd = command_format % [user, server]
98
103
  puts "Executing #{cmd}"
99
104
  exec cmd
100
105
  end
101
106
  end
102
107
 
103
108
  task :default do
104
- cmd = command_format % [user, roles.values.sample.servers.sample]
109
+ server = roles.values.sample.servers.sample
110
+ HiveQueen.ec2_instance_connect(server.host)
111
+ cmd = command_format % [user, server]
105
112
  puts "Executing #{cmd}"
106
113
  exec cmd
107
114
  end
@@ -111,14 +118,18 @@ Capistrano::Configuration.instance(:must_exist).load do
111
118
  command_format = "ssh -t -A -l %s %s 'source /etc/profile; cd /apps/#{HiveQueen.project}/current && bundle exec rails console'"
112
119
  env['roles'].keys.each do |role_name|
113
120
  task role_name do
121
+ server = roles[role_name.to_sym].servers.sample
122
+ HiveQueen.ec2_instance_connect(server.host)
114
123
  puts "Opening console"
115
- exec command_format % [user, roles[role_name.to_sym].servers.first]
124
+ exec command_format % [user, server]
116
125
  end
117
126
  end
118
127
 
119
128
  task :default do
129
+ server = roles.values.sample.servers.sample
130
+ HiveQueen.ec2_instance_connect(server.host)
120
131
  puts "Opening console"
121
- exec command_format % [user, roles.values.sample.servers.sample]
132
+ exec command_format % [user, server]
122
133
  end
123
134
  end
124
135
  end
@@ -7,6 +7,8 @@ Capistrano::Configuration.instance.load do
7
7
  before "deploy:stage", "hivequeen:start"
8
8
  before 'hivequeen:start', 'hivequeen:check_commit'
9
9
  on :start, "hivequeen:require_environment", :except => HiveQueen.environment_names
10
+ on :start, "hivequeen:ensure_canary_specifies_hosts"
11
+
10
12
  namespace :hivequeen do
11
13
 
12
14
  desc "[internal] abort if no environment specified"
@@ -14,6 +16,14 @@ Capistrano::Configuration.instance.load do
14
16
  abort "No environment specified." if !exists?(:environment)
15
17
  end
16
18
 
19
+ desc "[internal] abort if we're trying to do a canary deploy but HOSTS hasn't been defined"
20
+ task :ensure_canary_specifies_hosts do
21
+ # TODO: I suppose we could randomly select instance(s) in this case
22
+ if canary && !ENV.key?('HOSTS')
23
+ abort "You asked to do a canary deployment but didn't specify any hosts! \nPlease invoke like `cap HOSTS=foo.com deploy -s canary=true'"
24
+ end
25
+ end
26
+
17
27
  desc "[internal] Start a deployment in hivequeen"
18
28
  task :start do
19
29
  # TODO: is there a better way to determine what cap tasks are running?
@@ -22,7 +32,8 @@ Capistrano::Configuration.instance.load do
22
32
  params = {
23
33
  :task => tasks.join(' '),
24
34
  :commit => real_revision,
25
- :override => override
35
+ :override => override,
36
+ :canary => canary,
26
37
  }
27
38
 
28
39
  if current_commit
@@ -44,7 +55,7 @@ Capistrano::Configuration.instance.load do
44
55
 
45
56
  desc "[internal] Prompt if deploying the currently running commit, or if tests haven't passed"
46
57
  task :check_commit do
47
- if environment.to_s == 'production' && !override
58
+ if environment.to_s == 'production' && !override && !canary
48
59
  if current_commit == real_revision
49
60
  banner = %q{
50
61
  ______ _ _ _ ___
@@ -0,0 +1,36 @@
1
+ class HiveQueen
2
+ def self.ec2_client
3
+ @ec2_client ||= Aws::EC2::Client.new
4
+ end
5
+
6
+ def self.ec2_instance_connect_client
7
+ @ec2_instance_connect_client ||= Aws::EC2InstanceConnect::Client.new
8
+ end
9
+
10
+ def self.ec2_instance_connect(*private_dns)
11
+ # EC2 Instance Connect
12
+ ssh_public_key = File.read(File.expand_path('~/.ssh/ksr_ed25519.pub'))
13
+ ec2_params = {
14
+ filters: [{
15
+ name: 'network-interface.private-dns-name',
16
+ values: private_dns
17
+ }]
18
+ }
19
+ logger.trace("ec2:DescribeInstances #{ec2_params.to_json}")
20
+ instances = ec2_client.describe_instances(**ec2_params).reservations.map(&:instances).flatten
21
+ threads = instances.map do |instance|
22
+ Thread.new do
23
+ ec2ic_params = {
24
+ availability_zone: instance.placement.availability_zone,
25
+ instance_id: instance.instance_id,
26
+ instance_os_user: 'ksr',
27
+ ssh_public_key: ssh_public_key,
28
+ }
29
+ logger.trace("ec2-instance-connect:SendSSHPublicKey #{ec2ic_params.to_json}")
30
+ ec2_instance_connect_client.send_ssh_public_key(**ec2ic_params)
31
+ end
32
+ end
33
+
34
+ threads.each(&:join)
35
+ end
36
+ end
@@ -1,6 +1,6 @@
1
1
  class HiveQueen
2
2
  class Version
3
- @@version = '7.4.0'
3
+ @@version = '7.7.0'
4
4
 
5
5
  def self.to_s
6
6
  @@version
@@ -1,12 +1,17 @@
1
1
  # HTTP Client for Hive Queen environment configuration
2
+ require 'base64'
3
+ require 'fileutils'
2
4
  require 'json'
5
+
3
6
  require 'active_support'
4
7
  require 'active_support/core_ext'
5
- require 'fileutils'
8
+ require 'aws-sdk-ec2'
9
+ require 'aws-sdk-ec2instanceconnect'
6
10
  require 'excon'
7
- require 'base64'
11
+
8
12
  require 'capistrano/hivequeen/version'
9
13
  require 'capistrano/hivequeen/multiio'
14
+ require 'capistrano/hivequeen/ec2_instance_connect'
10
15
 
11
16
  # Special cases:
12
17
  # - environment not found
@@ -135,4 +140,3 @@ class HiveQueen
135
140
  end
136
141
 
137
142
  require "capistrano/hivequeen/capistrano_configuration"
138
-
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-hivequeen
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.4.0
4
+ version: 7.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Suggs
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-25 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-ec2
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk-ec2instanceconnect
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: capistrano
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -93,6 +121,7 @@ files:
93
121
  - lib/capistrano/hivequeen.rb
94
122
  - lib/capistrano/hivequeen/capistrano_configuration.rb
95
123
  - lib/capistrano/hivequeen/deploy.rb
124
+ - lib/capistrano/hivequeen/ec2_instance_connect.rb
96
125
  - lib/capistrano/hivequeen/multiio.rb
97
126
  - lib/capistrano/hivequeen/setup.rb
98
127
  - lib/capistrano/hivequeen/version.rb
@@ -100,7 +129,7 @@ homepage: http://github.com/kickstarter/capistrano-hivequeen
100
129
  licenses:
101
130
  - MIT
102
131
  metadata: {}
103
- post_install_message:
132
+ post_install_message:
104
133
  rdoc_options:
105
134
  - "--charset=UTF-8"
106
135
  require_paths:
@@ -116,9 +145,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
145
  - !ruby/object:Gem::Version
117
146
  version: '0'
118
147
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.5.1
121
- signing_key:
148
+ rubygems_version: 3.3.7
149
+ signing_key:
122
150
  specification_version: 2
123
151
  summary: Capistrano extensions for interacting with HiveQueen
124
152
  test_files: []