More refactor

This commit is contained in:
Roberto Alsina 2024-06-30 00:49:48 -03:00
parent 777be22f0c
commit 00fe54aeb8
2 changed files with 27 additions and 17 deletions

View File

@ -117,23 +117,9 @@ module Faaso
# Deploy from scratch # Deploy from scratch
Faaso.setup_network # We need it Faaso.setup_network # We need it
puts "Creating new container" puts "Creating new container"
conf = Docr::Types::CreateContainerConfig.new( id = funko.create_container
image: "#{funko.name}:latest", puts "Starting container"
hostname: funko.name, docker_api.containers.start(id)
# 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)
(1..5).each { |_| (1..5).each { |_|
break if funko.running? break if funko.running?

View File

@ -105,4 +105,28 @@ class Funko
} }
docker_api.containers.restart(exited[0].@id) unless exited.empty? docker_api.containers.restart(exited[0].@id) unless exited.empty?
end 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 end