From d93c8518daadcbbf34469ce72038698f3b7d9dff Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Mon, 8 Jul 2024 07:37:01 -0300 Subject: [PATCH] Minor refactor --- src/commands/build.cr | 92 +++++++++++++++++++++---------------------- src/main.cr | 1 + 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/src/commands/build.cr b/src/commands/build.cr index 65a243d..5530f05 100644 --- a/src/commands/build.cr +++ b/src/commands/build.cr @@ -16,56 +16,54 @@ module Faaso if options["--local"] Log.info { "Building function... #{funko.name} in #{tmp_dir}" } funko.build tmp_dir - else # Running against a server - Faaso.check_version - # Create a tarball for the funko - buf = IO::Memory.new - Compress::Gzip::Writer.open(buf) do |gzip| - Crystar::Writer.open(gzip) do |tw| - Log.debug { "Adding files to tarball" } - Dir.glob("#{tmp_dir}/**/*").each do |path| - next unless File.file? path - rel_path = Path[path].relative_to tmp_dir - Log.debug { "Adding #{rel_path}" } - file_info = File.info(path) - hdr = Crystar::Header.new( - name: rel_path.to_s, - mode: file_info.permissions.to_u32, - size: file_info.size, - ) - tw.write_header(hdr) - tw.write(File.read(path).to_slice) - end + next + end + Faaso.check_version + # Create a tarball for the funko + buf = IO::Memory.new + Compress::Gzip::Writer.open(buf) do |gzip| + Crystar::Writer.open(gzip) do |tw| + Log.debug { "Adding files to tarball" } + Dir.glob("#{tmp_dir}/**/*").each do |path| + next unless File.file? path + rel_path = Path[path].relative_to tmp_dir + Log.debug { "Adding #{rel_path}" } + file_info = File.info(path) + hdr = Crystar::Header.new( + name: rel_path.to_s, + mode: file_info.permissions.to_u32, + size: file_info.size, + ) + tw.write_header(hdr) + tw.write(File.read(path).to_slice) end end - - tmp = File.tempname - File.open(tmp, "w") do |outf| - outf << buf - end - - url = "#{Config.server}funkos/build/" - - begin - user, password = Config.auth - Log.info { "Uploading funko to #{Config.server}" } - Log.info { "Starting remote build:" } - Crest.post( - url, - {"funko.tgz" => File.open(tmp), "name" => "funko.tgz"}, - user: user, password: password - ) do |response| - loop do - Log.info { response.body_io.gets } - break if response.body_io.closed? - end - end - Log.info { "Build finished successfully." } - rescue ex : Crest::InternalServerError - Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" } - return 1 - end end + + tmp = File.tempname + File.open(tmp, "w") do |outf| + outf << buf + end + + url = "#{Config.server}funkos/build/" + + user, password = Config.auth + Log.info { "Uploading funko to #{Config.server}" } + Log.info { "Starting remote build:" } + Crest.post( + url, + {"funko.tgz" => File.open(tmp), "name" => "funko.tgz"}, + user: user, password: password + ) do |response| + loop do + Log.info { response.body_io.gets } + break if response.body_io.closed? + end + end + Log.info { "Build finished successfully." } + rescue ex : Crest::InternalServerError + Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" } + return 1 end 0 end diff --git a/src/main.cr b/src/main.cr index a08ddbd..c0c2f4d 100644 --- a/src/main.cr +++ b/src/main.cr @@ -14,6 +14,7 @@ FaaSO CLI tool. Usage: faaso build FOLDER ... [-v ] [-l] [--no-runtime] + faaso deploy FUNKO [-v ] [-l] faaso export SOURCE DESTINATION [-v ] faaso login [-v ] faaso new -r runtime FOLDER [-v ]