faaso up now supports remote call

This commit is contained in:
Roberto Alsina 2024-06-30 15:38:51 -03:00
parent 58813cbd27
commit 394a004d8d
3 changed files with 40 additions and 2 deletions

View File

@ -48,6 +48,18 @@ ReversePath "/admin/" "http://127.0.0.1:3000/"
proxy_config proxy_config
end end
# Bring up the funko
get "/funko/:name/up/" do |env|
name = env.params.url["name"]
response = run_faaso(["up", name])
if response["exit_code"] != 0
halt env, status_code: 500, response: response.to_json
else
response.to_json
end
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

View File

@ -105,7 +105,7 @@ module Faaso
end end
end end
# Bring up one or more funkos. # Bring up one or more funkos by name.
# #
# This doesn't guarantee that they will be running the latest # This doesn't guarantee that they will be running the latest
# version, and it will try to recicle paused and exited containers. # version, and it will try to recicle paused and exited containers.
@ -124,8 +124,26 @@ module Faaso
end end
def run def run
funkos = Funko.from_paths(@arguments) funkos = Funko.from_names(@arguments)
funkos.each do |funko| funkos.each do |funko|
local = @options.@bool["local"]
if !local
begin
response = Crest.get("#{FAASO_API}funko/#{funko.name}/up/",
user: "admin", password: "admin")
body = JSON.parse(response.body)
puts body["stdout"]
next
rescue ex : Crest::InternalServerError
puts "Error bringing up #{funko.name}"
body = JSON.parse(ex.response.body)
puts body["stdout"]
puts body["stderr"]
exit 1
end
end
if funko.image_history.empty? if funko.image_history.empty?
puts "Error: no images available for #{funko.name}:latest" puts "Error: no images available for #{funko.name}:latest"
next next

View File

@ -47,6 +47,14 @@ class Funko
} }
end end
# Create an array of funkos just from names. These are limited in function
# and can't call `prepare_build` or some other functionality
def self.from_names(names : Array(String)) : Array(Funko)
names.map { |name|
Funko.from_yaml("name: #{name}")
}
end
# Setup the target directory `path` with all the files needed # Setup the target directory `path` with all the files needed
# to build a docker image # to build a docker image
def prepare_build(path : Path) def prepare_build(path : Path)