paratrooper 3.0.0.beta3 → 3.0.2

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
2
  SHA1:
3
- metadata.gz: f46fd762d6a6a118bf4a77be498de394fe17eb56
4
- data.tar.gz: a50f59f0e00017a1424d2608dfcaf822aaef8fa8
3
+ metadata.gz: ec0cd33678d37387bbfa8998b12b3b6a33e1cf06
4
+ data.tar.gz: 47667f7cb489b49eb5aec4fa9d2dac06c18590a6
5
5
  SHA512:
6
- metadata.gz: 124c08920a1a40499a1fa4791d4d99256b1807b90143f1d7636905c6e49cf30dbdaa1df081de7f92414865e41031058c9aa1e88d885e044571bcbed854624845
7
- data.tar.gz: 36b2abf903f42c80fc222cfba4b0dec516160ccd5d75647f58e17f5ccf3f2959fad16cd42c298cb15ae825220f4bfe0f1cbe90fce86c93ff35c3fe90679483f3
6
+ metadata.gz: 7b3977cf28e03eaa58661950e02ad15baa9c40638835b1881944fac32bd31a0251aaa09077cc9ed137ccd08e0d378d2f2b8f576e0ce70ee1ec28aebe22448b31
7
+ data.tar.gz: 0ed7a25f8aef3fbff257184625170a167c59c9462076bf342610354e62bd169b68724135e81e28cf99e80faa036f35651fb10b3c9ce6fff3cbe11681b0bc98c7
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.2
4
+
5
+ - Fixed reverse call on enumerator on `Paratrooper::HerokuWrapper#last_release_with_slug`
6
+
7
+ ## 3.0.1
8
+
9
+ - Migrated to platform-api gem from heroku
10
+
3
11
  ## 3.0.0.beta1
4
12
 
5
13
  - Moved all state into configuration object
data/README.md CHANGED
@@ -39,8 +39,8 @@ Paratrooper.deploy('amazing-app')
39
39
  You can also provide a tag:
40
40
 
41
41
  ```ruby
42
- Paratrooper.deploy('amazing-app') do |deploy|
43
- deploy.tag = 'staging'
42
+ Paratrooper.deploy('amazing-app') do |config|
43
+ config.tag = 'staging'
44
44
  end
45
45
  ```
46
46
 
@@ -51,8 +51,8 @@ You can authenticate your Heroku account in a few ways:
51
51
  * Provide an API Key
52
52
 
53
53
  ```ruby
54
- Paratrooper.deploy('app') do |deploy|
55
- deploy.api_key = 'API_KEY'
54
+ Paratrooper.deploy('app') do |config|
55
+ config.api_key = 'API_KEY'
56
56
  end
57
57
  ```
58
58
 
@@ -76,16 +76,16 @@ This method works via a local Netrc file handled via the [Heroku Toolbelt][] and
76
76
  If you use multiple SSH keys for managing multiple accounts, for example in your `.ssh/config`, you can set the `deployment_host` option:
77
77
 
78
78
  ```ruby
79
- Paratrooper.deploy('amazing-app') do |deploy|
80
- deploy.deployment_host = 'HOST'
79
+ Paratrooper.deploy('amazing-app') do |config|
80
+ config.deployment_host = 'HOST'
81
81
  end
82
82
  ```
83
83
 
84
84
  This also works if you're using the [heroku-accounts](https://github.com/ddollar/heroku-accounts) plugin:
85
85
 
86
86
  ```ruby
87
- Paratrooper.deploy('app') do |deploy|
88
- deploy.deployment_host: 'heroku.ACCOUNT_NAME'
87
+ Paratrooper.deploy('app') do |config|
88
+ config.deployment_host: 'heroku.ACCOUNT_NAME'
89
89
  end
90
90
  ```
91
91
 
@@ -149,13 +149,13 @@ to disable your application monitoring.
149
149
  namespace :deploy do
150
150
  desc 'Deploy app in production environment'
151
151
  task :production do
152
- Paratrooper.deploy("amazing-production-app") do |deploy|
153
- deploy.add_callback(:before_setup) do |output|
152
+ Paratrooper.deploy("amazing-production-app") do |config|
153
+ config.add_callback(:before_setup) do |output|
154
154
  output.display("Totally going to turn off newrelic")
155
155
  system %Q[curl https://rpm.newrelic.com/accounts/ACCOUNT_ID/applications/APPLICATION_ID/ping_targets/disable -X POST -H "X-Api-Key: API_KEY"]
156
156
  end
157
157
 
158
- deploy.add_callback(:after_teardown) do |output|
158
+ config.add_callback(:after_teardown) do |output|
159
159
  system %Q[curl https://rpm.newrelic.com/accounts/ACCOUNT_ID/applications/APPLICATION_ID/ping_targets/enable -X POST -H "X-Api-Key: API_KEY"]
160
160
  output.display("Aaaannnd we're back")
161
161
  end
@@ -172,11 +172,11 @@ Or maybe you just want to run a rake task on your application. Since this task m
172
172
  namespace :deploy do
173
173
  desc 'Deploy app in production environment'
174
174
  task :production do
175
- Paratrooper.deploy("amazing-production-app") do |deploy|
176
- deploy.maintenance = true
177
- deploy.add_callback(:after_teardown) do |output|
175
+ Paratrooper.deploy("amazing-production-app") do |config|
176
+ config.maintenance = true
177
+ config.add_callback(:after_teardown) do |output|
178
178
  output.display("Running some task that needs to run")
179
- deploy.add_remote_task("rake some:task:to:run")
179
+ config.add_remote_task("rake some:task:to:run")
180
180
  end
181
181
  end
182
182
  end
@@ -1,4 +1,4 @@
1
- require 'heroku-api'
1
+ require 'platform-api'
2
2
  require 'rendezvous'
3
3
  require 'paratrooper/local_api_key_extractor'
4
4
  require 'paratrooper/error'
@@ -18,45 +18,56 @@ module Paratrooper
18
18
  @app_name = app_name
19
19
  @key_extractor = options[:key_extractor] || LocalApiKeyExtractor
20
20
  @api_key = options[:api_key] || key_extractor.get_credentials
21
- @heroku_api = options[:heroku_api] || Heroku::API.new(api_key: api_key)
21
+ @heroku_api = options[:heroku_api] || PlatformAPI.connect_oauth(api_key)
22
22
  @rendezvous = options[:rendezvous] || Rendezvous
23
23
  end
24
24
 
25
25
  def app_restart
26
- client(:post_ps_restart, app_name)
26
+ client(:dyno, :restart_all, app_name)
27
27
  end
28
28
 
29
29
  def app_maintenance_off
30
- app_maintenance('0')
30
+ client(:app, :update, app_name, 'maintenance' => 'false')
31
31
  end
32
32
 
33
33
  def app_maintenance_on
34
- app_maintenance('1')
34
+ client(:app, :update, app_name, 'maintenance' => 'true')
35
+ end
36
+
37
+ def releases
38
+ @releases ||= client(:release, :list, app_name)
35
39
  end
36
40
 
37
41
  def run_migrations
38
42
  run_task('rake db:migrate')
39
43
  end
40
44
 
41
- def run_task(task_name)
42
- data = client(:post_ps, app_name, task_name, attach: 'true').body
43
- rendezvous.start(url: data['rendezvous_url'])
45
+ def run_task(task)
46
+ payload = { 'command' => task, 'attach' => 'true' }
47
+ data = client(:dyno, :create, app_name, payload)
48
+ rendezvous.start(url: data['attach_url'])
44
49
  end
45
50
 
46
51
  def last_deploy_commit
47
- data = client(:get_releases, app_name).body
48
- return nil if data.empty?
49
- data.last['commit']
52
+ return nil if last_release_with_slug.nil?
53
+ slug_data = client(:slug, :info, app_name, get_slug_id(last_release_with_slug))
54
+ slug_data['commit']
55
+ end
56
+
57
+ def last_release_with_slug
58
+ # releases is an enumerator
59
+ releases.to_a.reverse.detect { |release| not release['slug'].nil? }
50
60
  end
51
61
 
52
62
  private
53
- def app_maintenance(flag)
54
- client(:post_app_maintenance, app_name, flag)
63
+
64
+ def get_slug_id(release)
65
+ release["slug"]["id"]
55
66
  end
56
67
 
57
- def client(method, *args)
58
- heroku_api.public_send(method, *args)
59
- rescue Heroku::API::Errors::Forbidden => e
68
+ def client(delegatee, method, *args)
69
+ heroku_api.public_send(delegatee).public_send(method, *args)
70
+ rescue Excon::Errors::Forbidden => e
60
71
  raise ErrorNoAccess.new(app_name)
61
72
  end
62
73
  end
@@ -1,3 +1,3 @@
1
1
  module Paratrooper
2
- VERSION = "3.0.0.beta3".freeze
2
+ VERSION = "3.0.2".freeze
3
3
  end
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.add_development_dependency 'rake'
23
23
  gem.add_development_dependency 'rspec', '~> 3.0'
24
24
  gem.add_development_dependency 'pry'
25
- gem.add_dependency 'heroku-api', '~> 0.3'
25
+ gem.add_dependency 'platform-api', '~> 2.0'
26
26
  gem.add_dependency 'rendezvous', '~> 0.1'
27
27
  gem.add_dependency 'netrc', '~> 0.7'
28
28
  gem.add_dependency 'excon', '>= 0.44.4'
@@ -45,69 +45,110 @@ describe Paratrooper::HerokuWrapper do
45
45
 
46
46
  describe '#app_restart' do
47
47
  it "calls down to heroku api" do
48
- expect(heroku_api).to receive(:post_ps_restart).with(app_name)
48
+ expect(heroku_api).to receive_message_chain(:dyno, :restart_all).with(app_name)
49
49
  wrapper.app_restart
50
50
  end
51
51
  end
52
52
 
53
53
  describe '#app_maintenance_off' do
54
54
  it "calls down to heroku api" do
55
- expect(heroku_api).to receive(:post_app_maintenance).with(app_name, '0')
55
+ expect(heroku_api).to receive_message_chain(:app, :update).with(app_name, 'maintenance' => 'false')
56
56
  wrapper.app_maintenance_off
57
57
  end
58
58
  end
59
59
 
60
60
  describe '#app_maintenance_on' do
61
61
  it "calls down to heroku api" do
62
- expect(heroku_api).to receive(:post_app_maintenance).with(app_name, '1')
62
+ expect(heroku_api).to receive_message_chain(:app, :update).with(app_name, 'maintenance' => 'true')
63
63
  wrapper.app_maintenance_on
64
64
  end
65
65
  end
66
66
 
67
67
  describe '#run_migrations' do
68
68
  it 'calls into the heroku api' do
69
- expect(heroku_api).to receive(:post_ps).with(app_name, 'rake db:migrate', attach: 'true').and_return(double(body: ''))
69
+ expect(heroku_api).to receive_message_chain(:dyno, :create).with(app_name, {'command' => 'rake db:migrate', 'attach' => 'true' }).and_return(Hash.new)
70
70
  wrapper.run_migrations
71
71
  end
72
72
 
73
73
  it 'uses waits for db migrations to run using rendezvous' do
74
- data = { 'rendezvous_url' => 'the_url' }
75
- allow(heroku_api).to receive_message_chain(:post_ps, :body).and_return(data)
76
- expect(rendezvous).to receive(:start).with(:url => data['rendezvous_url'])
74
+ data = { 'attach_url' => 'the_url' }
75
+ allow(heroku_api).to receive_message_chain(:dyno, :create).with(app_name, {'command' => 'rake db:migrate', 'attach' => 'true' }).and_return(data)
76
+ expect(rendezvous).to receive(:start).with(:url => data['attach_url'])
77
77
  wrapper.run_migrations
78
78
  end
79
79
  end
80
80
 
81
81
  describe "#last_deploy_commit" do
82
82
  context "when deploy data is returned" do
83
- let(:response) do
84
- double(:response, body: [{ 'commit' => 'SHA' }])
83
+ let(:slug_data) do
84
+ { 'commit' => 'SHA' }
85
+ end
86
+
87
+ let(:release_data) do
88
+ [{ 'slug' => { 'id' => '1' } }]
85
89
  end
90
+
86
91
  it "returns string of last deployed commit" do
87
- expect(heroku_api).to receive(:get_releases).with(app_name)
88
- .and_return(response)
92
+ slug_info = release_data.first["slug"]["id"]
93
+
94
+ allow(heroku_api).to receive_message_chain(:release, :list).and_return(release_data)
95
+ expect(heroku_api).to receive_message_chain(:slug, :info).with(app_name, slug_info)
96
+ .and_return(slug_data)
89
97
  expect(wrapper.last_deploy_commit).to eq('SHA')
90
98
  end
91
99
  end
92
100
 
93
101
  context "when no deploys have happened yet" do
94
102
  let(:response) do
95
- double(:response, body: [])
103
+ Array.new
104
+ end
105
+
106
+ let(:data) do
107
+ [{ 'slug' => { 'id' => '1' } }]
96
108
  end
97
109
 
98
110
  it "returns nil" do
99
- expect(heroku_api).to receive(:get_releases).with(app_name)
100
- .and_return(response)
111
+ slug_info = data.first["slug"]["id"].to_i
112
+
113
+ allow(heroku_api).to receive_message_chain(:release, :list).and_return(response)
101
114
  expect(wrapper.last_deploy_commit).to eq(nil)
102
115
  end
103
116
  end
104
117
  end
105
118
 
119
+ describe '#last_release_with_slug' do
120
+ let(:releases) do
121
+ [
122
+ { 'slug' => { 'id' => '1' }, 'updated_at' => '1990' },
123
+ { 'slug' => { 'id' => '2' }, 'updated_at' => '2015' },
124
+ { 'slug' => nil }
125
+ ]
126
+ end
127
+ it 'returns the most current release that has a slug attribute' do
128
+ allow(heroku_api).to receive_message_chain(:release, :list).and_return(releases)
129
+ expect(wrapper.last_release_with_slug['updated_at']).to eq '2015'
130
+
131
+ end
132
+
133
+ it 'returns nil if none of the releases have a slug attribute' do
134
+ data = [{ 'slug' => nil }]
135
+ allow(heroku_api).to receive_message_chain(:release, :list).and_return(data)
136
+ expect(wrapper.last_release_with_slug).to be_nil
137
+ end
138
+
139
+ it 'returns nil if the releases array is empty' do
140
+ data = []
141
+ allow(heroku_api).to receive_message_chain(:release, :list).and_return(data)
142
+ expect(wrapper.last_release_with_slug).to be_nil
143
+ end
144
+ end
145
+
106
146
  describe "#run_task" do
107
147
  it 'calls into the heroku api' do
108
148
  task = 'rake some:task:to:run'
109
- expect(heroku_api).to receive(:post_ps).with(app_name, task, attach: 'true').and_return(double(body: ''))
149
+ expect(heroku_api).to receive_message_chain(:dyno, :create).with(app_name, {'command' => task, 'attach' => 'true' }).and_return(Hash.new)
110
150
  wrapper.run_task(task)
111
151
  end
112
152
  end
153
+
113
154
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paratrooper
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.beta3
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Polito
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-16 00:00:00.000000000 Z
12
+ date: 2017-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -54,19 +54,19 @@ dependencies:
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
56
  - !ruby/object:Gem::Dependency
57
- name: heroku-api
57
+ name: platform-api
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0.3'
62
+ version: '2.0'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0.3'
69
+ version: '2.0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rendezvous
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -166,12 +166,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
166
  version: 1.9.2
167
167
  required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - ">"
169
+ - - ">="
170
170
  - !ruby/object:Gem::Version
171
- version: 1.3.1
171
+ version: '0'
172
172
  requirements: []
173
173
  rubyforge_project:
174
- rubygems_version: 2.4.5
174
+ rubygems_version: 2.6.11
175
175
  signing_key:
176
176
  specification_version: 4
177
177
  summary: Library to create task for deployment to Heroku