From 897b2dd59e4f5a859ebb972be05a8a4d231f3303 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Fri, 28 Jun 2024 20:57:04 -0300 Subject: [PATCH] Support paused containers --- src/faaso.cr | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/faaso.cr b/src/faaso.cr index 6fa2b89..13182ce 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -71,6 +71,16 @@ module Faaso return 0 end + # If it is paused, unpause it + paused = containers.select { |c| + c.@image == tag && c.@state == "paused" + } + if (paused.size > 0) + puts "Resuming existing paused container" + docker_api.containers.unpause(paused[0].@id) + return 0 + end + # If it is exited, start it existing = containers.select { |c| c.@image == tag && c.@state == "exited" @@ -80,20 +90,23 @@ module Faaso if (existing.size > 0) puts "Restarting existing exited container" docker_api.containers.start(existing[0].@id) - else - conf = Docr::Types::CreateContainerConfig.new( - image: tag, - hostname: "foo", - host_config: Docr::Types::HostConfig.new - ) - # FIXME: name should be unique - response = docker_api.containers.create(name: "fungus", config: conf) - docker_api.containers.start(response.@id) + return 0 end - # TODO: Run test for healthcheck - # TODO: Map route in reverse proxy to function - # TODO: Return function URL for testing + + # Creating from scratch + puts "Creating new container" + conf = Docr::Types::CreateContainerConfig.new( + image: tag, + hostname: "foo", + host_config: Docr::Types::HostConfig.new + ) + # FIXME: name should be unique + response = docker_api.containers.create(name: "fungus", config: conf) + docker_api.containers.start(response.@id) end + # TODO: Run test for healthcheck + # TODO: Map route in reverse proxy to function + # TODO: Return function URL for testing end end