Compare commits

..

No commits in common. "b611ed199beaaaff79c1e2d24fa4b10965563058" and "c28239295fb5034a7257ddaed563f0cc7693573a" have entirely different histories.

5 changed files with 63 additions and 63 deletions

View File

@ -4,7 +4,6 @@
* Setting up password * Setting up password
* Setting up hostname for Caddy's automatic HTTPS * Setting up hostname for Caddy's automatic HTTPS
* Config UI in frontend? * Config UI in frontend?
* Support tokens besides basic auth
* Polish frontend UI **A LOT** * Polish frontend UI **A LOT**
* Version checks for consistency between client/server * Version checks for consistency between client/server
* Have 3 runtimes: * Have 3 runtimes:
@ -21,10 +20,4 @@
or building or building
* Make more things configurable / remove hardcoded stuff * Make more things configurable / remove hardcoded stuff
* CD for binaries and images for at least arm64/x86 * CD for binaries and images for at least arm64/x86
* Multi-container docker logs [faaso logs -f FUNKO] * Multi-container docker logs
* Direct error and above to stderr, others to stdout, while keeping
logging level configurable
# Things to do but not before release
* Propagate errors from `run_faaso` to the remote client

View File

@ -47,18 +47,14 @@ module Faaso
begin begin
Log.info { "Uploading funko to #{FAASO_SERVER}" } Log.info { "Uploading funko to #{FAASO_SERVER}" }
Log.info { "Starting remote build:" } response = Crest.post(
Crest.post(
url, url,
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"}, {"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
user: "admin", password: "admin" user: "admin", password: "admin"
) do |response| )
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
Log.info { "Build finished successfully." } Log.info { "Build finished successfully." }
body = JSON.parse(response.body)
Log.info { body["output"] }
rescue ex : Crest::InternalServerError rescue ex : Crest::InternalServerError
Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" } Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" }
return 1 return 1

View File

@ -28,27 +28,21 @@ module Faaso
def remote(options, name, scale) : Int32 def remote(options, name, scale) : Int32
if !scale if !scale
Crest.get( response = Crest.get(
"#{FAASO_SERVER}funkos/#{name}/scale/", \ "#{FAASO_SERVER}funkos/#{name}/scale/", \
user: "admin", password: "admin") do |response| user: "admin", password: "admin")
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
else else
Crest.post( response = Crest.post(
"#{FAASO_SERVER}funkos/#{name}/scale/", "#{FAASO_SERVER}funkos/#{name}/scale/",
{"scale" => scale}, user: "admin", password: "admin") do |response| {"scale" => scale}, user: "admin", password: "admin")
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
end end
body = JSON.parse(response.body)
Log.info { body["output"] }
0 0
rescue ex : Crest::InternalServerError rescue ex : Crest::InternalServerError
Log.error(exception: ex) { "Error scaling funko #{name}" } Log.error { "Error scaling funko #{name}" }
body = JSON.parse(ex.response.body)
Log.info { body["output"] }
1 1
end end

View File

@ -5,11 +5,6 @@ module Faaso
funko = Funko::Funko.from_names([name])[0] funko = Funko::Funko.from_names([name])[0]
status = funko.docker_status status = funko.docker_status
if status.images.size == 0
Log.error { "Unkown funko: #{name}" }
return 1
end
Log.info { "Name: #{status.@name}" } Log.info { "Name: #{status.@name}" }
Log.info { "Scale: #{status.scale}" } Log.info { "Scale: #{status.scale}" }
@ -26,17 +21,16 @@ module Faaso
end end
def remote(options, name) : Int32 def remote(options, name) : Int32
Crest.get( response = Crest.get(
"#{FAASO_SERVER}funkos/#{name}/status/", \ "#{FAASO_SERVER}funkos/#{name}/status/", \
user: "admin", password: "admin") do |response| user: "admin", password: "admin")
loop do body = JSON.parse(response.body)
Log.info { response.body_io.gets } Log.info { body["output"] }
break if response.body_io.closed?
end
end
0 0
rescue ex : Crest::InternalServerError rescue ex : Crest::InternalServerError
Log.error(exception: ex) { "Error scaling funko #{name}" } Log.error { "Error scaling funko #{name}" }
body = JSON.parse(ex.response.body)
Log.info { body["output"] }
1 1
end end

View File

@ -8,20 +8,39 @@ module Funko
# Get the funko's status # Get the funko's status
get "/funkos/:name/status/" do |env| get "/funkos/:name/status/" do |env|
name = env.params.url["name"] name = env.params.url["name"]
run_faaso(["status", name], env) response = run_faaso(["status", name])
if response["exit_code"] != 0
halt env, status_code: 500, response: response.to_json
else
response.to_json
end
end end
# Get the funko's scale # Get the funko's scale
get "/funkos/:name/scale/" do |env| get "/funkos/:name/scale/" do |env|
name = env.params.url["name"] name = env.params.url["name"]
run_faaso(["scale", name], env) response = run_faaso(["scale", name])
if response["exit_code"] != 0
halt env, status_code: 500, response: response.to_json
else
response.to_json
end
end end
# Set the funko's scale # Set the funko's scale
post "/funkos/:name/scale/" do |env| post "/funkos/:name/scale/" do |env|
name = env.params.url["name"] name = env.params.url["name"]
scale = env.params.body["scale"].as(String) scale = env.params.body["scale"].as(String)
run_faaso(["scale", name, scale], env) response = run_faaso(["scale", name, scale])
if response["exit_code"] != 0
Log.error { response }
halt env, status_code: 500, response: response.to_json
else
Log.info { response }
response.to_json
end
end end
# Build image for funko received as "funko.tgz" # Build image for funko received as "funko.tgz"
@ -47,7 +66,13 @@ module Funko
end end
# Build the thing # Build the thing
run_faaso(["build", tmp_dir.to_s, "--no-runtime"], env) response = run_faaso(["build", tmp_dir.to_s, "--no-runtime"])
if response["exit_code"] != 0
halt env, status_code: 500, response: response.to_json
else
response.to_json
end
end end
# Endpoints for the web frontend # Endpoints for the web frontend
@ -125,23 +150,21 @@ module Funko
"<iframe src='terminal/' width='100%' height='100%'></iframe>" "<iframe src='terminal/' width='100%' height='100%'></iframe>"
end end
# Helper to run faaso locally and respond via env # Helper to run faaso locally and get a response back
def run_faaso(args : Array(String), env) : Bool def run_faaso(args : Array(String))
Log.info { "Running faaso [#{args.join(", ")}, -l]" } Log.info { "Running faaso [#{args.join(", ")}, -l]" }
Process.run( output = IO::Memory.new
status = Process.run(
command: "faaso", command: "faaso",
args: args + ["-l"], # Always local in the server args: args + ["-l"], # Always local in the server
) do |process| output: output,
loop do error: output,
env.response.print process.output.gets(chomp: false) )
env.response.flush Log.debug { "faaso output: #{output}" }
Fiber.yield result = {
break if process.terminated? "exit_code" => status.exit_code,
end "output" => output.to_s,
p! process.error.peek }
true result
end
# FIXME: find a way to raise an exception on failure
# of the faaso process
end end
end end