From e60bc2dd284643787d7da7f49ba568ee4110980e Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sat, 29 Jun 2024 18:58:49 -0300 Subject: [PATCH] Start containers in isolated network --- src/faaso.cr | 16 ++++++++++++++++ tinyproxy/tinyproxy.conf | 7 +++++++ 2 files changed, 23 insertions(+) create mode 100644 tinyproxy/tinyproxy.conf diff --git a/src/faaso.cr b/src/faaso.cr index 0835e02..46cb4cd 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -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 diff --git a/tinyproxy/tinyproxy.conf b/tinyproxy/tinyproxy.conf new file mode 100644 index 0000000..6bed1e4 --- /dev/null +++ b/tinyproxy/tinyproxy.conf @@ -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