More refactor
This commit is contained in:
parent
00fe54aeb8
commit
ad520c222b
11
src/faaso.cr
11
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?
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user