diff --git a/src/daemon.cr b/src/daemon.cr new file mode 100644 index 0000000..d4f88f9 --- /dev/null +++ b/src/daemon.cr @@ -0,0 +1,32 @@ +require "docr" +require "kemal" + +get "/" do + "Updating routing" + # Get all the funkos, create routes for them all + docker_api = Docr::API.new(Docr::Client.new) + containers = docker_api.containers.list(all: true) + + funkos = [] of String + containers.each { |container| + names = container.names.select &.starts_with? "/faaso-" + next if names.empty? + funkos << names[0][7..] + } + + proxy_config = %( +Port 8888 +Listen 0.0.0.0 +Timeout 600 +Allow 0.0.0.0/0 +ReverseOnly Yes +ReverseMagic Yes +ReversePath "/admin/" "http://127.0.0.1:3000/" +) + funkos.map { |funko| %(ReversePath "/faaso/#{funko}/" "http://#{funko}:3000/") }.join("\n") + + File.open("/etc/tinyproxy/tinyproxy.conf", "w") do |file| + file << proxy_config + end +end + +Kemal.run diff --git a/tinyproxy/tinyproxy.conf b/tinyproxy/tinyproxy.conf deleted file mode 100644 index 7b18bde..0000000 --- a/tinyproxy/tinyproxy.conf +++ /dev/null @@ -1,7 +0,0 @@ -Port 8888 -Listen 0.0.0.0 -Timeout 600 -Allow 0.0.0.0/0 -ReverseOnly Yes -ReversePath "/faaso/hello/" "http://hello:3000/" -ReverseMagic Yes