Compare commits
No commits in common. "b611ed199beaaaff79c1e2d24fa4b10965563058" and "c28239295fb5034a7257ddaed563f0cc7693573a" have entirely different histories.
b611ed199b
...
c28239295f
9
TODO.md
9
TODO.md
@ -4,7 +4,6 @@
|
||||
* Setting up password
|
||||
* Setting up hostname for Caddy's automatic HTTPS
|
||||
* Config UI in frontend?
|
||||
* Support tokens besides basic auth
|
||||
* Polish frontend UI **A LOT**
|
||||
* Version checks for consistency between client/server
|
||||
* Have 3 runtimes:
|
||||
@ -21,10 +20,4 @@
|
||||
or building
|
||||
* Make more things configurable / remove hardcoded stuff
|
||||
* CD for binaries and images for at least arm64/x86
|
||||
* Multi-container docker logs [faaso logs -f FUNKO]
|
||||
* 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
|
||||
* Multi-container docker logs
|
||||
|
@ -47,18 +47,14 @@ module Faaso
|
||||
|
||||
begin
|
||||
Log.info { "Uploading funko to #{FAASO_SERVER}" }
|
||||
Log.info { "Starting remote build:" }
|
||||
Crest.post(
|
||||
response = Crest.post(
|
||||
url,
|
||||
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
|
||||
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." }
|
||||
body = JSON.parse(response.body)
|
||||
Log.info { body["output"] }
|
||||
rescue ex : Crest::InternalServerError
|
||||
Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" }
|
||||
return 1
|
||||
|
@ -28,27 +28,21 @@ module Faaso
|
||||
|
||||
def remote(options, name, scale) : Int32
|
||||
if !scale
|
||||
Crest.get(
|
||||
response = Crest.get(
|
||||
"#{FAASO_SERVER}funkos/#{name}/scale/", \
|
||||
user: "admin", password: "admin") do |response|
|
||||
loop do
|
||||
Log.info { response.body_io.gets }
|
||||
break if response.body_io.closed?
|
||||
end
|
||||
end
|
||||
user: "admin", password: "admin")
|
||||
else
|
||||
Crest.post(
|
||||
response = Crest.post(
|
||||
"#{FAASO_SERVER}funkos/#{name}/scale/",
|
||||
{"scale" => scale}, user: "admin", password: "admin") do |response|
|
||||
loop do
|
||||
Log.info { response.body_io.gets }
|
||||
break if response.body_io.closed?
|
||||
end
|
||||
end
|
||||
{"scale" => scale}, user: "admin", password: "admin")
|
||||
end
|
||||
body = JSON.parse(response.body)
|
||||
Log.info { body["output"] }
|
||||
0
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -5,11 +5,6 @@ module Faaso
|
||||
funko = Funko::Funko.from_names([name])[0]
|
||||
status = funko.docker_status
|
||||
|
||||
if status.images.size == 0
|
||||
Log.error { "Unkown funko: #{name}" }
|
||||
return 1
|
||||
end
|
||||
|
||||
Log.info { "Name: #{status.@name}" }
|
||||
Log.info { "Scale: #{status.scale}" }
|
||||
|
||||
@ -26,17 +21,16 @@ module Faaso
|
||||
end
|
||||
|
||||
def remote(options, name) : Int32
|
||||
Crest.get(
|
||||
response = Crest.get(
|
||||
"#{FAASO_SERVER}funkos/#{name}/status/", \
|
||||
user: "admin", password: "admin") do |response|
|
||||
loop do
|
||||
Log.info { response.body_io.gets }
|
||||
break if response.body_io.closed?
|
||||
end
|
||||
end
|
||||
user: "admin", password: "admin")
|
||||
body = JSON.parse(response.body)
|
||||
Log.info { body["output"] }
|
||||
0
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -8,20 +8,39 @@ module Funko
|
||||
# Get the funko's status
|
||||
get "/funkos/:name/status/" do |env|
|
||||
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
|
||||
|
||||
# Get the funko's scale
|
||||
get "/funkos/:name/scale/" do |env|
|
||||
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
|
||||
|
||||
# Set the funko's scale
|
||||
post "/funkos/:name/scale/" do |env|
|
||||
name = env.params.url["name"]
|
||||
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
|
||||
|
||||
# Build image for funko received as "funko.tgz"
|
||||
@ -47,7 +66,13 @@ module Funko
|
||||
end
|
||||
|
||||
# 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
|
||||
|
||||
# Endpoints for the web frontend
|
||||
@ -125,23 +150,21 @@ module Funko
|
||||
"<iframe src='terminal/' width='100%' height='100%'></iframe>"
|
||||
end
|
||||
|
||||
# Helper to run faaso locally and respond via env
|
||||
def run_faaso(args : Array(String), env) : Bool
|
||||
# Helper to run faaso locally and get a response back
|
||||
def run_faaso(args : Array(String))
|
||||
Log.info { "Running faaso [#{args.join(", ")}, -l]" }
|
||||
Process.run(
|
||||
output = IO::Memory.new
|
||||
status = Process.run(
|
||||
command: "faaso",
|
||||
args: args + ["-l"], # Always local in the server
|
||||
) do |process|
|
||||
loop do
|
||||
env.response.print process.output.gets(chomp: false)
|
||||
env.response.flush
|
||||
Fiber.yield
|
||||
break if process.terminated?
|
||||
end
|
||||
p! process.error.peek
|
||||
true
|
||||
end
|
||||
# FIXME: find a way to raise an exception on failure
|
||||
# of the faaso process
|
||||
output: output,
|
||||
error: output,
|
||||
)
|
||||
Log.debug { "faaso output: #{output}" }
|
||||
result = {
|
||||
"exit_code" => status.exit_code,
|
||||
"output" => output.to_s,
|
||||
}
|
||||
result
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user