Start containers in isolated network

This commit is contained in:
Roberto Alsina 2024-06-29 18:58:49 -03:00
parent 69a6359ed1
commit e60bc2dd28
2 changed files with 23 additions and 0 deletions

View File

@ -16,6 +16,20 @@ module Faaso
# A simple persistent k/v store
store = Kiwi::FileStore.new(".kiwi")
# Ensure the faaso-net network exists
def self.setup_network
begin
docker_api = Docr::API.new(Docr::Client.new)
docker_api.networks.create(Docr::Types::NetworkConfig.new(
name: "faaso-net",
check_duplicate: false,
driver: "bridge"
))
rescue ex : Docr::Errors::DockerAPIError
raise ex if ex.status_code != 409 # Network already exists
end
end
module Commands
class Build
@arguments : Array(String) = [] of String
@ -142,6 +156,7 @@ module Faaso
end
# Deploy from scratch
Faaso.setup_network # We need it
puts "Creating new container"
conf = Docr::Types::CreateContainerConfig.new(
image: "#{funko.name}:latest",
@ -149,6 +164,7 @@ module Faaso
# Port in the container side
exposed_ports: {"#{funko.port}/tcp" => {} of String => String},
host_config: Docr::Types::HostConfig.new(
network_mode: "faaso-net",
port_bindings: {"#{funko.port}/tcp" => [Docr::Types::PortBinding.new(
host_port: "", # Host port, empty means random
host_ip: "127.0.0.1", # Host IP

7
tinyproxy/tinyproxy.conf Normal file
View File

@ -0,0 +1,7 @@
Port 8888
Listen 0.0.0.0
Timeout 600
Allow 0.0.0.0/0
ReverseOnly Yes
ReversePath "/faaso/hello" "http://localhost:32783"
ReverseMagic Yes