dpl 1.7.10.travis.700.4 → 1.7.10.travis.701.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/dpl/provider/heroku/api.rb +31 -0
- data/spec/provider/heroku_api_spec.rb +63 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NWU1ZjI5ZjZlZTczYzEwMTBlMGI3NDk5NjRlZmRlMTk4MTM2MjUzNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MWQ3ZDNjNzkwM2ExYzE1ZmE0NzZhNzdhNjNlYzJmZTBiOWFjMGVkNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTMxOGQzY2Y1Yzc1MWE3N2ZiY2Y4YWJkYWM4YWUwZWFiOWQ2ODMxNmQ2Y2Ux
|
10
|
+
YjNlMDVkOTQ1ZWMyYjZjYjIwYjY4MzI2MDVjYThhMDdhNjdlY2Y0MjUxYjUz
|
11
|
+
NDM3MGI4NDQwYWJjODhkZmM5ZjNmNTg1MGIwNGJhOGJhNmVlMmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjVjYThhMWVjMDM4MmRmMzU3ZjEwZTM0YTVmMmEzM2E2OWJiY2FkYzY5MzM2
|
14
|
+
MDBiOTAwZmNhMzRiMmZmYmVlMGI4MDdiNmM2NmJkODE0MmI4NjE3NzEwODky
|
15
|
+
MTIzMjNjZjJkY2MzNzZhMDRjZjBhNTdjODY3MjQ4MzMyYTA3OTY=
|
@@ -5,10 +5,13 @@ module DPL
|
|
5
5
|
class Provider
|
6
6
|
module Heroku
|
7
7
|
class API < Generic
|
8
|
+
attr_reader :build_id
|
9
|
+
|
8
10
|
def push_app
|
9
11
|
pack_archive
|
10
12
|
upload_archive
|
11
13
|
trigger_build
|
14
|
+
verify_build
|
12
15
|
end
|
13
16
|
|
14
17
|
def archive_file
|
@@ -28,10 +31,27 @@ module DPL
|
|
28
31
|
def trigger_build
|
29
32
|
log "triggering new deployment"
|
30
33
|
response = post(:builds, source_blob: { url: get_url, version: version })
|
34
|
+
@build_id = response.fetch('id')
|
31
35
|
stream_url = response.fetch('stream_url')
|
32
36
|
context.shell "curl #{Shellwords.escape(stream_url)}"
|
33
37
|
end
|
34
38
|
|
39
|
+
def verify_build
|
40
|
+
loop do
|
41
|
+
response = get("builds/#{build_id}/result")
|
42
|
+
exit_code = response.fetch('exit_code')
|
43
|
+
if exit_code.nil?
|
44
|
+
log "heroku build still pending"
|
45
|
+
sleep 5
|
46
|
+
next
|
47
|
+
elsif exit_code == 0
|
48
|
+
break
|
49
|
+
else
|
50
|
+
error "deploy failed, build exited with code #{exit_code}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
35
55
|
def get_url
|
36
56
|
source_blob.fetch("get_url")
|
37
57
|
end
|
@@ -48,6 +68,17 @@ module DPL
|
|
48
68
|
@version ||= options[:version] || context.env['TRAVIS_COMMIT'] || `git rev-parse HEAD`.strip
|
49
69
|
end
|
50
70
|
|
71
|
+
def get(subpath, options = {})
|
72
|
+
options = {
|
73
|
+
method: :get,
|
74
|
+
path: "/apps/#{option(:app)}/#{subpath}",
|
75
|
+
headers: { "Accept" => "application/vnd.heroku+json; version=edge" },
|
76
|
+
expects: [200]
|
77
|
+
}.merge(options)
|
78
|
+
|
79
|
+
api.request(options).body
|
80
|
+
end
|
81
|
+
|
51
82
|
def post(subpath, body = nil, options = {})
|
52
83
|
options = {
|
53
84
|
method: :post,
|
@@ -31,4 +31,67 @@ describe DPL::Provider::Heroku do
|
|
31
31
|
expect(provider.api).to eq(api)
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
describe "#trigger_build" do
|
36
|
+
let(:response_body) { {
|
37
|
+
"created_at" => "2012-01-01T12:00:00Z",
|
38
|
+
"id" => "abc",
|
39
|
+
"status" => "pending",
|
40
|
+
"stream_url" => "http://example.com/stream",
|
41
|
+
"updated_at" => "2012-01-01T12:00:00Z",
|
42
|
+
"user" => { "id" => "01234567-89ab-cdef-0123-456789abcdef", "email" => "username@example.com" }
|
43
|
+
} }
|
44
|
+
example do
|
45
|
+
expect(provider).to receive(:log).with('triggering new deployment')
|
46
|
+
expect(provider).to receive(:get_url).and_return 'http://example.com/source.tgz'
|
47
|
+
expect(provider).to receive(:version).and_return 'sha'
|
48
|
+
expect(provider).to receive(:post).with(
|
49
|
+
:builds, source_blob: {url: 'http://example.com/source.tgz', version: 'sha'}
|
50
|
+
).and_return(response_body)
|
51
|
+
expect(provider.context).to receive(:shell).with('curl http://example.com/stream')
|
52
|
+
provider.trigger_build
|
53
|
+
expect(provider.build_id).to eq('abc')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#verify_build" do
|
58
|
+
def response_body(status, exit_code)
|
59
|
+
{
|
60
|
+
"build" => {
|
61
|
+
"id" => "01234567-89ab-cdef-0123-456789abcdef",
|
62
|
+
"status" => status
|
63
|
+
},
|
64
|
+
"exit_code" => exit_code
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
before do
|
69
|
+
allow(provider).to receive(:build_id).and_return('abc')
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'when build succeeds' do
|
73
|
+
example do
|
74
|
+
expect(provider).to receive(:get).with('builds/abc/result').and_return(response_body('succeeded', 0))
|
75
|
+
expect{ provider.verify_build }.not_to raise_error
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'when build fails' do
|
80
|
+
example do
|
81
|
+
expect(provider).to receive(:get).with('builds/abc/result').and_return(response_body('failed', 1))
|
82
|
+
expect{ provider.verify_build }.to raise_error("deploy failed, build exited with code 1")
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
context 'when build is pending, then succeeds' do
|
87
|
+
example do
|
88
|
+
expect(provider).to receive(:get).with('builds/abc/result').and_return(response_body('pending', nil), response_body('succeeded', 0))
|
89
|
+
expect(provider).to receive(:log).with('heroku build still pending')
|
90
|
+
expect(provider).to receive(:sleep).with(5) # stub sleep
|
91
|
+
expect{ provider.verify_build }.not_to raise_error
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
34
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dpl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.10.travis.
|
4
|
+
version: 1.7.10.travis.701.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|