From 394a004d8db72297e5b9b120f429a2caa22e20cf Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Sun, 30 Jun 2024 15:38:51 -0300 Subject: [PATCH] faaso up now supports remote call --- src/daemon.cr | 12 ++++++++++++ src/faaso.cr | 22 ++++++++++++++++++++-- src/funko.cr | 8 ++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/daemon.cr b/src/daemon.cr index 6ea45ba..6faea8a 100644 --- a/src/daemon.cr +++ b/src/daemon.cr @@ -48,6 +48,18 @@ ReversePath "/admin/" "http://127.0.0.1:3000/" proxy_config 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" # TODO: This may take a while, consider using something like # mosquito-cr/mosquito to make it a job queue diff --git a/src/faaso.cr b/src/faaso.cr index ea86f77..9c3ee4b 100644 --- a/src/faaso.cr +++ b/src/faaso.cr @@ -105,7 +105,7 @@ module Faaso 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 # version, and it will try to recicle paused and exited containers. @@ -124,8 +124,26 @@ module Faaso end def run - funkos = Funko.from_paths(@arguments) + funkos = Funko.from_names(@arguments) 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? puts "Error: no images available for #{funko.name}:latest" next diff --git a/src/funko.cr b/src/funko.cr index c43aef7..8564005 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -47,6 +47,14 @@ class Funko } 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 # to build a docker image def prepare_build(path : Path)