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