Faaso deploy command
This commit is contained in:
parent
2face37b19
commit
62d66a5286
@ -1,9 +1,7 @@
|
||||
module Faaso
|
||||
module Commands
|
||||
struct Deploy
|
||||
# FIXME: local only for now
|
||||
def run(options, funko_name : String) : Int32
|
||||
Log.info { "Deploying #{funko_name}" }
|
||||
def local(options, funko_name : String) : Int32
|
||||
funko = Funko::Funko.from_names([funko_name])[0]
|
||||
# Get scale, check for out-of-date containers
|
||||
current_scale = funko.scale
|
||||
@ -22,9 +20,9 @@ module Faaso
|
||||
# Failed to start, rollback
|
||||
Log.error(exception: ex) { "Failed to scale, rolling back" }
|
||||
docker_api = Docr::API.new(Docr::Client.new)
|
||||
new_containers.each do |container|
|
||||
docker_api.containers.stop(container.id)
|
||||
docker_api.containers.delete(container.id)
|
||||
new_containers.each do |container_id|
|
||||
docker_api.containers.stop(container_id)
|
||||
docker_api.containers.delete(container_id)
|
||||
end
|
||||
return 1
|
||||
end
|
||||
@ -36,6 +34,29 @@ module Faaso
|
||||
Log.info { "Deployed #{funko_name}" }
|
||||
0
|
||||
end
|
||||
|
||||
def remote(options, funko_name : String) : Int32
|
||||
user, password = Config.auth
|
||||
Faaso.check_version
|
||||
Crest.get(
|
||||
"#{Config.server}funkos/#{funko_name}/deploy/", \
|
||||
user: user, password: password) do |response|
|
||||
loop do
|
||||
Log.info { response.body_io.gets }
|
||||
break if response.body_io.closed?
|
||||
end
|
||||
end
|
||||
0
|
||||
end
|
||||
|
||||
def run(options, funko_name : String) : Int32
|
||||
Log.info { "Deploying #{funko_name}" }
|
||||
if options["--local"]
|
||||
local(options, funko_name)
|
||||
else
|
||||
remote(options, funko_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -24,6 +24,11 @@ module Funko
|
||||
run_faaso(["scale", name, scale], env)
|
||||
end
|
||||
|
||||
get "/funkos/:name/deploy" do |env|
|
||||
name = env.params.url["name"]
|
||||
run_faaso(["deploy", name], env)
|
||||
end
|
||||
|
||||
# Build image for funko received as "funko.tgz"
|
||||
# TODO: This may take a while, consider using something like
|
||||
# mosquito-cr/mosquito to make it a job queue
|
||||
|
16
src/funko.cr
16
src/funko.cr
@ -221,12 +221,22 @@ module Funko
|
||||
spawn do
|
||||
loop do
|
||||
if healthy
|
||||
channel.send(nil) if containers.count { |container|
|
||||
channel.send(nil) if containers.select { |container|
|
||||
begin
|
||||
container = docker_api.containers.inspect(container.@id)
|
||||
channel.send(nil) if !container.nil? && (container.state.health.status == "healthy")
|
||||
details = docker_api.containers.inspect(container.@id)
|
||||
if details.nil?
|
||||
false
|
||||
elsif details.state.nil?
|
||||
false
|
||||
elsif details.state.as(Docr::Types::ContainerState).health.nil?
|
||||
false
|
||||
elsif details.state.as(Docr::Types::ContainerState).health.as(Docr::Types::Health).status == "healthy"
|
||||
true
|
||||
end
|
||||
false
|
||||
rescue ex : Docr::Errors::DockerAPIError
|
||||
Log.error { "#{ex}" } unless ex.status_code == 304 # This just happens
|
||||
false
|
||||
end
|
||||
} == new_scale
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user