Tinyproxy + faaso-daemon docker image using multirun

This commit is contained in:
Roberto Alsina 2024-06-29 20:26:14 -03:00
parent 0f297e9714
commit 3d529019e6
2 changed files with 32 additions and 7 deletions

32
src/daemon.cr Normal file
View File

@ -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

View File

@ -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