2024-06-29 23:26:14 +00:00
|
|
|
require "docr"
|
|
|
|
require "kemal"
|
2024-06-30 14:55:46 +00:00
|
|
|
require "kemal-basic-auth"
|
|
|
|
|
|
|
|
# FIXME: make configurable
|
|
|
|
basic_auth "admin", "admin"
|
2024-06-29 23:26:14 +00:00
|
|
|
|
2024-06-29 23:48:03 +00:00
|
|
|
current_config = ""
|
|
|
|
|
2024-06-29 23:26:14 +00:00
|
|
|
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..]
|
|
|
|
}
|
|
|
|
|
2024-06-29 23:48:03 +00:00
|
|
|
funkos.sort!
|
|
|
|
|
2024-06-29 23:26:14 +00:00
|
|
|
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")
|
|
|
|
|
2024-06-29 23:48:03 +00:00
|
|
|
if current_config != proxy_config
|
|
|
|
File.open("tinyproxy.conf", "w") do |file|
|
|
|
|
file << proxy_config
|
|
|
|
end
|
|
|
|
# Reload config
|
|
|
|
Process.run(command: "/usr/bin/killall", args: ["-USR1", "tinyproxy"])
|
|
|
|
current_config = proxy_config
|
2024-06-29 23:38:34 +00:00
|
|
|
end
|
|
|
|
proxy_config
|
2024-06-29 23:26:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Kemal.run
|