This commit is contained in:
Roberto Alsina 2024-06-30 15:23:16 -03:00
parent f5467551a1
commit 58813cbd27

View File

@ -69,22 +69,29 @@ post "/funko/build/" do |env|
end end
# Build the thing # Build the thing
response = run_faaso(["build", tmp_dir.to_s])
if response["exit_code"] != 0
halt env, status_code: 500, response: response.to_json
else
response.to_json
end
end
def run_faaso(args : Array(String))
stderr = IO::Memory.new stderr = IO::Memory.new
stdout = IO::Memory.new stdout = IO::Memory.new
status = Process.run( status = Process.run(
command: "faaso", command: "faaso",
args: ["build", "-l", tmp_dir.to_s], args: args + ["-l"], # Always local in the server
output: stdout, output: stdout,
error: stderr, error: stderr,
) )
response = { {
"exit_code" => status.exit_code, "exit_code" => status.exit_code,
"stdout" => stdout.to_s, "stdout" => stdout.to_s,
"stderr" => stderr.to_s, "stderr" => stderr.to_s,
}.to_json }
halt env, status_code: 500, response: response if status.exit_code != 0
response
end end
Kemal.run Kemal.run