Working terminal/shell/logs but container selection is broken

This commit is contained in:
2024-07-04 14:44:16 -03:00
parent 56e59ae4a0
commit 05438d13cf
7 changed files with 37 additions and 15 deletions

View File

@ -124,6 +124,28 @@ module Funko
funko.wait_for(1, 1)
end
# Return an iframe that shows the container's logs
get "/funkos/:name/terminal/logs" do |env|
name = env.params.url["name"]
funko = Funko.from_names([name])[0]
# FIXME: Just getting the 1st one for now, it
# may not even be running
container_name = funko.containers.map { |c| c.@names[0] }[0]
Terminal.start_terminal(["docker", "logs", "-f", container_name.to_s])
"<iframe src='terminal/' width='100%' height='100%'></iframe>"
end
# Get an iframe with a shell into the container
get "/funkos/:name/terminal/shell" do |env|
name = env.params.url["name"]
funko = Funko.from_names([name])[0]
# FIXME: Just getting the 1st one for now, it
# may not even be running
container_name = funko.containers.map { |c| c.@names[0] }[0].lstrip("/")
Terminal.start_terminal(["docker", "exec", "-ti", container_name, "/bin/sh"], readonly: false)
"<iframe src='terminal/' width='100%' height='100%'></iframe>"
end
# Helper to run faaso locally and get a response back
def run_faaso(args : Array(String))
Log.info { "Running faaso [#{args.join(", ")}, -l]" }

View File

@ -47,7 +47,7 @@ localhost:8888 {
handle_path /faaso/#{funko.split("-")[0]}/* {
reverse_proxy /* http://#{funko}:3000
}
)}.join("\n") +"}"
) }.join("\n") + "}"
if @@current_config != config
File.open("Caddyfile", "w") do |file|

View File

@ -3,16 +3,19 @@ module Terminal
@@terminal_process : Process | Nil = nil
def start_terminal(_args = ["sh"], readonly = false)
def start_terminal(_args = ["sh"], readonly = true)
args = ["-p", "7681", "-c", "admin:admin", "-o"]
args += ["-W"] unless readonly
args += _args
args += _args
# We have a process there, kill it
@@terminal_process.as(Process).terminate if !@@terminal_process.nil?
begin
@@terminal_process.as(Process).terminate if !@@terminal_process.nil?
rescue e : RuntimeError
Log.error { "Error terminating terminal process: #{e.message}" }
end
@@terminal_process = Process.new(
command: "/usr/bin/ttyd",
args: args)
Log.info {"Terminal started on port 7681"}
Log.info { "Terminal started on port 7681" }
end
end