Fix rucksack and bugs

This commit is contained in:
Roberto Alsina 2024-07-05 12:04:36 -03:00
parent 2eb20aa09b
commit 2644cd4b86
7 changed files with 39 additions and 33 deletions

View File

@ -1,19 +1,18 @@
{
http_port 8888
https_port 8887
local_certs
http_port 8888
https_port 8887
local_certs
}
http://*:8888 {
basicauth /admin/* {
# admin $2a$14$C35905PxPzICAZKc/O9jYOS7ipZNPBtrndja8Yu3bvs/UujckryHS
admin {$HTTP_BASIC_AUTH_PASSWORD}
}
handle_path /admin/terminal/* {
reverse_proxy /* http://127.0.0.1:7681
}
handle_path /admin/* {
reverse_proxy /* http://127.0.0.1:3000
}
handle_path /admin/terminal/* {
reverse_proxy /* http://127.0.0.1:7681
}
handle_path /admin/* {
reverse_proxy /* http://127.0.0.1:3000
}
}

View File

@ -5,9 +5,10 @@ WORKDIR /home/app
COPY shard.yml ./
RUN mkdir src/
COPY src/ src/
COPY runtimes/ runtimes/
RUN shards install
RUN shards build -d --error-trace
RUN strip bin/*
# RUN strip bin/*
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine as ship
RUN apk update && apk add caddy nss-tools multirun docker openssl zlib yaml pcre2 gc libevent libgcc libxml2 ttyd && apk cache clean
@ -17,7 +18,6 @@ RUN addgroup -S app && adduser app -S -G app
WORKDIR /home/app
RUN mkdir runtimes public
COPY runtimes/ runtimes/
COPY public/ public/
COPY Caddyfile ./
COPY --from=build /home/app/bin/faaso-daemon /home/app/bin/faaso /usr/bin/

View File

@ -1,5 +1,6 @@
build: shard.yml $(wildcard src/**/*cr)
build: shard.yml $(wildcard src/**/*) $(runtimes/**/*)
shards build
cat .rucksack >> bin/faaso
proxy: build
docker build . -t faaso-proxy
start-proxy:

View File

@ -4,26 +4,30 @@ module Faaso
struct Build
def run(options, folders : Array(String)) : Int32
funkos = Funko::Funko.from_paths(folders)
# Create temporary build location
if options["--local"]
funkos.each do |funko|
# Create temporary build location
tmp_dir = Path.new("tmp", UUID.random.to_s)
Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir
funko.prepare_build tmp_dir
funkos.each do |funko|
tmp_dir = Path.new("tmp", UUID.random.to_s)
Dir.mkdir_p(tmp_dir) unless File.exists? tmp_dir
Log.info { "Building function... #{funko.name} in #{tmp_dir}" }
funko.build tmp_dir
end
else # Running against a server
funkos.each do |funko|
funko.runtime = nil if options["--no-runtime"]
funko.prepare_build(path: tmp_dir)
if options["--local"]
funkos.each do |funko|
Log.info { "Building function... #{funko.name} in #{tmp_dir}" }
funko.build tmp_dir
end
else # Running against a server
# Create a tarball for the funko
buf = IO::Memory.new
Compress::Gzip::Writer.open(buf) do |gzip|
Crystar::Writer.open(gzip) do |tw|
Dir.glob("#{funko.path}/**/*").each do |path|
Log.debug { "Adding files to tarball" }
Dir.glob("#{tmp_dir}/**/*").each do |path|
next unless File.file? path
rel_path = Path[path].relative_to funko.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,
@ -52,12 +56,9 @@ module Faaso
)
Log.info { "Build finished successfully." }
body = JSON.parse(response.body)
Log.info { body["stdout"] }
Log.info { body["output"] }
rescue ex : Crest::InternalServerError
Log.error { "Error building funko #{funko.name} from #{funko.path}" }
body = JSON.parse(ex.response.body)
Log.info { body["stdout"] }
Log.error { body["stderr"] }
Log.error(exception: ex) { "Error building funko #{funko.name} from #{funko.path}" }
return 1
end
end

View File

@ -56,6 +56,8 @@ module Funko
Compress::Gzip::Reader.open(file) do |gzip|
Crystar::Reader.open(gzip) do |tar|
tar.each_entry do |entry|
dst = Path.new(tmp_dir, entry.name)
Dir.mkdir_p dst.dirname
File.open(Path.new(tmp_dir, entry.name), "w") do |dst|
IO.copy entry.io, dst
end
@ -64,7 +66,7 @@ module Funko
end
# Build the thing
response = run_faaso(["build", tmp_dir.to_s])
response = run_faaso(["build", tmp_dir.to_s, "--no-runtime"])
if response["exit_code"] != 0
halt env, status_code: 500, response: response.to_json
@ -148,6 +150,7 @@ module Funko
output: output,
error: output,
)
Log.debug { "faaso output: #{output.to_s}" }
result = {
"exit_code" => status.exit_code,
"output" => output.to_s,

View File

@ -151,6 +151,7 @@ module Funko
# Build image using docker in path previously prepared using `prepare_build`
def build(path : Path)
Log.info { "Building image for #{name} in #{path}" }
docker_api = Docr::API.new(Docr::Client.new)
docker_api.images.build(
context: path.to_s,

View File

@ -46,7 +46,7 @@ doc = <<-DOC
FaaSO CLI tool.
Usage:
faaso build FOLDER ... [-v <level>] [-l]
faaso build FOLDER ... [-v <level>] [-l] [--no-runtime]
faaso export SOURCE DESTINATION [-v <level>]
faaso new -r runtime FOLDER [-v <level>]
faaso scale FUNKO [SCALE] [-v <level>] [-l]
@ -59,6 +59,7 @@ Options:
-d --delete Delete
-h --help Show this screen
-l --local Run commands locally instead of against a FaaSO server
--no-runtime Don't merge a runtime into the funko
-r runtime Runtime for the new funko (use -r list for examples)
-v level Control the logging verbosity, 0 to 5 [default: 3]
DOC