diff --git a/src/faaso.cr b/src/faaso.cr index 2dd1577..de5b5d0 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -117,23 +117,9 @@ module Faaso # Deploy from scratch Faaso.setup_network # We need it puts "Creating new container" - conf = Docr::Types::CreateContainerConfig.new( - image: "#{funko.name}:latest", - hostname: funko.name, - # 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 - )]} - ) - ) - - response = docker_api.containers.create(name: container_name, config: conf) - response.@warnings.each { |msg| puts "Warning: #{msg}" } - docker_api.containers.start(response.@id) + id = funko.create_container + puts "Starting container" + docker_api.containers.start(id) (1..5).each { |_| break if funko.running? diff --git a/src/funko.cr b/src/funko.cr index 6fddef0..9e66db1 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -105,4 +105,28 @@ class Funko } docker_api.containers.restart(exited[0].@id) unless exited.empty? end + + # Create a container for this funko + def create_container : String + conf = Docr::Types::CreateContainerConfig.new( + image: "#{name}:latest", + hostname: name, + # Port in the container side + # FIXME: Maybe don't need this now we are using the proxy + exposed_ports: {"#{port}/tcp" => {} of String => String}, + host_config: Docr::Types::HostConfig.new( + network_mode: "faaso-net", + # Also probably not needed anymore + port_bindings: {"#{port}/tcp" => [Docr::Types::PortBinding.new( + host_port: "", # Host port, empty means random + host_ip: "127.0.0.1", # Host IP + )]} + ) + ) + + docker_api = Docr::API.new(Docr::Client.new) + response = docker_api.containers.create(name: "faaso-#{name}", config: conf) + response.@warnings.each { |msg| puts "Warning: #{msg}" } + response.@id + end end