forked from eBayClassifiedsGroup/orlo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployer.rb
executable file
·110 lines (88 loc) · 2.43 KB
/
deployer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env ruby
require 'json'
require 'net/http'
require 'openssl'
require 'uri'
def orlo_request(method, url, body = nil)
if $http.nil?
return
end
puts " -> %s" % [ url ]
request = method.new(url, initheader = {
"Content-Type" => "application/json"
})
request.basic_auth("testuser", "blabla")
if ! body.nil?
request.body = JSON(body)
end
response = $http.request(request)
if ! response.kind_of?(Net::HTTPSuccess)
raise "#{request.path} returned #{response.code}"
end
if ! response.body.nil? and response.body.length > 0
JSON.parse(response.body)
end
end
def orlo_get(url)
orlo_request(Net::HTTP::Get, url)
end
def orlo_post(url, body = nil)
orlo_request(Net::HTTP::Post, url, body)
end
puts "Dummy Deployer v0.1"
if ENV["ORLO_URL"].nil?
$http = nil
else
$uri = URI.parse(ENV["ORLO_URL"])
$http = Net::HTTP.new($uri.host, $uri.port)
if $uri.is_a?(URI::HTTPS)
$http.use_ssl = true
# $http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
end
if ENV["ORLO_RELEASE"]
releases = orlo_get("/releases/#{ENV["ORLO_RELEASE"]}")
release = releases["releases"][0]
deployables = release["packages"].collect do |package|
[ package["name"], package["version"] ]
end
else
release = orlo_post("/releases", {
"user" => ENV["ORLO_USER"],
"team" => ENV["ORLO_TEAM"],
"platforms" => ENV["ORLO_PLATFORMS"],
"references" => ENV["ORLO_REFERENCES"],
})
deployables = ARGV.collect do |deployable|
deployable.split("=")
end
end
if release
puts "Orlo release ID #{release["id"]}"
end
deployables.each do |deployable|
pkgname, version = deployable
if release
package = orlo_post("/releases/#{release["id"]}/packages", {
"name" => pkgname,
"version" => version,
"rollback" => !ENV["ORLO_ROLLBACK"].nil?,
})
end
puts "Installing #{pkgname} version #{version}"
if release
orlo_post("/releases/#{release["id"]}/packages/#{package["id"]}/start")
end
puts "# apt-get install #{pkgname}=#{version}"
sleep 1 # ... wow, much install ...
if release
orlo_post("/releases/#{release["id"]}/packages/#{package["id"]}/stop", {
"success" => true,
})
end
end
if release
orlo_post("/releases/#{release["id"]}/stop")
end
puts "Finished!"
exit 0