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
|
# File 'lib/vulcan/cli.rb', line 31
def build
app = read_config[:app] || "need a server first, use vulcan create"
source = options[:source] || Dir.pwd
name = options[:name] || File.basename(source, File.extname(source))
output = options[:output] || "/tmp/#{name}.tgz"
prefix = options[:prefix] || "/app/vendor/#{name}"
command = options[:command] || "./configure --prefix #{prefix} && make install"
deps = options[:deps] || []
server = URI.parse(ENV["VULCAN_HOST"] || "http://#{app}.herokuapp.com")
source_is_url = URI.parse(source).scheme
Dir.mktmpdir do |dir|
unless source_is_url
input_tgz = "#{dir}/input.tgz"
if File.directory?(source)
action "Packaging local directory" do
%x{ cd #{source} && tar czvf #{input_tgz} . 2>&1 }
end
else
input_tgz = source
end
input = File.open(input_tgz, "r")
end
make_options = {
"command" => command,
"prefix" => prefix,
"secret" => config[:secret],
"deps" => deps
}
if source_is_url
make_options["code_url"] = source
else
make_options["code"] = UploadIO.new(input, "application/octet-stream", "input.tgz")
end
request = Net::HTTP::Post::Multipart.new "/make", make_options
if source_is_url
print "Initializing build... "
else
print "Uploading source package... "
end
response = Net::HTTP.start(server.host, server.port) do |http|
http.request(request) do |response|
response.read_body do |chunk|
unless chunk == 0.chr + "\n"
print chunk if options[:verbose]
end
end
end
end
error "Unknown error, no build output given" unless response["X-Make-Id"]
puts ">> Downloading build artifacts to: #{output}"
output_url = "#{server}/output/#{response["X-Make-Id"]}"
puts " (available at #{output_url})"
File.open(output, "w") do |output|
begin
output.print RestClient.get(output_url)
rescue Exception => ex
puts ex.inspect
end
end
end
rescue Interrupt
error "Aborted by user"
rescue Errno::EPIPE
error "Could not connect to build server: #{server}"
end
|