Minor refactor

This commit is contained in:
Roberto Alsina 2024-07-08 07:37:01 -03:00
parent 379b4e2472
commit d93c8518da
2 changed files with 46 additions and 47 deletions

View File

@ -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

View File

@ -14,6 +14,7 @@ FaaSO CLI tool.
Usage:
faaso build FOLDER ... [-v <level>] [-l] [--no-runtime]
faaso deploy FUNKO [-v <level>] [-l]
faaso export SOURCE DESTINATION [-v <level>]
faaso login [-v <level>]
faaso new -r runtime FOLDER [-v <level>]