67 lines
2.1 KiB
Ruby
67 lines
2.1 KiB
Ruby
|
|
module Devops
|
|
module API2_0
|
|
module Routes
|
|
module DeployRoutes
|
|
|
|
def self.registered(app)
|
|
|
|
# Run chef-client on reserved server
|
|
#
|
|
# * *Request*
|
|
# - method : POST
|
|
# - headers :
|
|
# - Content-Type: application/json
|
|
# - body :
|
|
# {
|
|
# "names": [], -> array of servers chef node names to run chef-client
|
|
# "tags": [], -> array of tags to apply on each server before running chef-client
|
|
# "build_number": "", -> string, build number to deploy
|
|
# "run_list": [], -> array of strings to set run_list for chef-client
|
|
# }
|
|
#
|
|
# * *Returns* : text stream
|
|
app.post_with_headers "/deploy", :headers => [:content_type] do
|
|
check_privileges("server", "x")
|
|
|
|
if request["X-Stream"]
|
|
stream() do |out|
|
|
status = []
|
|
begin
|
|
status = Devops::API2_0::Handler::Deploy.new(request).deploy_stream(out)
|
|
out << create_status(status)
|
|
rescue IOError => e
|
|
logger.error e.message
|
|
break
|
|
end
|
|
end # stream
|
|
else
|
|
files = Devops::API2_0::Handler::Deploy.new(request).deploy()
|
|
sleep 1
|
|
json files
|
|
end
|
|
end
|
|
|
|
app.get "/deploy/data/:project/:env" do |project, env|
|
|
p = Devops::Db.connector.project project
|
|
data = p.deploy_info(env, params["build_number"])
|
|
content_type "application/json"
|
|
(JSON.pretty_generate data) << "\n"
|
|
end
|
|
|
|
app.get "/deploy/data/:file" do |file|
|
|
dir = DevopsConfig.config[:project_info_dir]
|
|
file_path = File.join(dir, file)
|
|
return [404, "Data for '#{file}' not found"] unless File.exists?(file_path)
|
|
content_type "application/json"
|
|
File.read(file_path) + "\n"
|
|
end
|
|
|
|
puts "Deploy routes initialized"
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|
|
end
|