More refactor

This commit is contained in:
Roberto Alsina 2024-06-30 00:55:09 -03:00
parent 00fe54aeb8
commit ad520c222b
2 changed files with 7 additions and 7 deletions

View File

@ -23,6 +23,7 @@ module Faaso
end end
module Commands module Commands
# Build images for one or more funkos
class Build class Build
@arguments : Array(String) = [] of String @arguments : Array(String) = [] of String
@options : Commander::Options @options : Commander::Options
@ -35,6 +36,7 @@ module Faaso
def run def run
funkos = Funko.from_paths(@arguments) funkos = Funko.from_paths(@arguments)
funkos.each do |funko| funkos.each do |funko|
# FIXME: refactor lots of this into the Funko class
# Create temporary build location # Create temporary build location
tmp_dir = Path.new("tmp", UUID.random.to_s) tmp_dir = Path.new("tmp", UUID.random.to_s)
Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir
@ -113,13 +115,10 @@ module Faaso
puts "Restarting existing exited container" puts "Restarting existing exited container"
funko.start funko.start
else else
# FIXME: move into Funko class # Only have an image, deploy from scratch
# Deploy from scratch
Faaso.setup_network # We need it Faaso.setup_network # We need it
puts "Creating new container" puts "Creating and starting new container"
id = funko.create_container funko.create_container(autostart: true)
puts "Starting container"
docker_api.containers.start(id)
(1..5).each { |_| (1..5).each { |_|
break if funko.running? break if funko.running?

View File

@ -107,7 +107,7 @@ class Funko
end end
# Create a container for this funko # Create a container for this funko
def create_container : String def create_container( autostart : Bool = true) : String
conf = Docr::Types::CreateContainerConfig.new( conf = Docr::Types::CreateContainerConfig.new(
image: "#{name}:latest", image: "#{name}:latest",
hostname: name, hostname: name,
@ -127,6 +127,7 @@ class Funko
docker_api = Docr::API.new(Docr::Client.new) docker_api = Docr::API.new(Docr::Client.new)
response = docker_api.containers.create(name: "faaso-#{name}", config: conf) response = docker_api.containers.create(name: "faaso-#{name}", config: conf)
response.@warnings.each { |msg| puts "Warning: #{msg}" } response.@warnings.each { |msg| puts "Warning: #{msg}" }
docker_api.containers.start(response.@id) if autostart
response.@id response.@id
end end
end end