From ad520c222b74a860df8e44b9dfae447ac551ce5f Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sun, 30 Jun 2024 00:55:09 -0300 Subject: [PATCH] More refactor --- src/faaso.cr | 11 +++++------ src/funko.cr | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/faaso.cr b/src/faaso.cr index de5b5d0..709e1c2 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -23,6 +23,7 @@ module Faaso end module Commands + # Build images for one or more funkos class Build @arguments : Array(String) = [] of String @options : Commander::Options @@ -35,6 +36,7 @@ module Faaso def run funkos = Funko.from_paths(@arguments) funkos.each do |funko| + # FIXME: refactor lots of this into the Funko class # Create temporary build location tmp_dir = Path.new("tmp", UUID.random.to_s) Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir @@ -113,13 +115,10 @@ module Faaso puts "Restarting existing exited container" funko.start else - # FIXME: move into Funko class - # Deploy from scratch + # Only have an image, deploy from scratch Faaso.setup_network # We need it - puts "Creating new container" - id = funko.create_container - puts "Starting container" - docker_api.containers.start(id) + puts "Creating and starting new container" + funko.create_container(autostart: true) (1..5).each { |_| break if funko.running? diff --git a/src/funko.cr b/src/funko.cr index 9e66db1..52cebb8 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -107,7 +107,7 @@ class Funko end # Create a container for this funko - def create_container : String + def create_container( autostart : Bool = true) : String conf = Docr::Types::CreateContainerConfig.new( image: "#{name}:latest", hostname: name, @@ -127,6 +127,7 @@ class Funko 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}" } + docker_api.containers.start(response.@id) if autostart response.@id end end