From 2644cd4b866027a960c67dd35da5a6134231936a Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Fri, 5 Jul 2024 12:04:36 -0300 Subject: [PATCH] Fix rucksack and bugs --- Caddyfile | 19 +++++++++---------- Dockerfile | 4 ++-- Makefile | 3 ++- src/commands/build.cr | 37 +++++++++++++++++++------------------ src/daemon/funko.cr | 5 ++++- src/funko.cr | 1 + src/main.cr | 3 ++- 7 files changed, 39 insertions(+), 33 deletions(-) diff --git a/Caddyfile b/Caddyfile index aa42be0..082b626 100644 --- a/Caddyfile +++ b/Caddyfile @@ -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 + } } diff --git a/Dockerfile b/Dockerfile index 92efc88..e3fb7da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/Makefile b/Makefile index 1baa5b0..9b4f600 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/src/commands/build.cr b/src/commands/build.cr index 405e310..b9b34d4 100644 --- a/src/commands/build.cr +++ b/src/commands/build.cr @@ -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 diff --git a/src/daemon/funko.cr b/src/daemon/funko.cr index 836f589..acc4ff5 100644 --- a/src/daemon/funko.cr +++ b/src/daemon/funko.cr @@ -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, diff --git a/src/funko.cr b/src/funko.cr index f121c62..1358cdc 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -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, diff --git a/src/main.cr b/src/main.cr index ce239e6..3ae36d2 100644 --- a/src/main.cr +++ b/src/main.cr @@ -46,7 +46,7 @@ doc = <<-DOC FaaSO CLI tool. Usage: - faaso build FOLDER ... [-v ] [-l] + faaso build FOLDER ... [-v ] [-l] [--no-runtime] faaso export SOURCE DESTINATION [-v ] faaso new -r runtime FOLDER [-v ] faaso scale FUNKO [SCALE] [-v ] [-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