Compare commits

..

No commits in common. "3b2297e9542d60cfb69e9a46ddafb288d58f33f0" and "81ec0779287292341d335cfe12e89f962e8f1046" have entirely different histories.

9 changed files with 50 additions and 51 deletions

View File

@ -8,7 +8,6 @@ proxy:
all: build proxy
start-proxy:
docker network create faaso-net || true
docker run --name faaso-proxy-one \
--rm --network=faaso-net \
-e FAASO_SECRET_PATH=${PWD}/secrets \

View File

@ -12,7 +12,6 @@
* ✅ Crystal + Kemal
* ✅ Python + Flask
* ✅ Nodejs + Express
* Create a site
* Document
* How to create a runtime
* How to create a funko
@ -35,8 +34,7 @@
* ✅ Fix `export examples/hello_crystal` it has a `template/`
* ✅ Implement zero-downtime rollout (`faaso deploy`)
* ✅ Cleanup `tmp/whatever` after use
* ✅ `faaso scale` remote is broken
* ✅ Setup linters/pre-commit/etc
* `faaso scale` remote is broken
## Things to do but not before release

View File

@ -58,7 +58,10 @@ module Faaso
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
user: user, password: password
) do |response|
IO.copy(response.body_io, STDOUT)
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

View File

@ -41,7 +41,10 @@ module Faaso
Crest.get(
"#{Config.server}funkos/#{funko_name}/deploy/", \
user: user, password: password) do |response|
IO.copy(response.body_io, STDOUT)
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
0
end

View File

@ -10,14 +10,14 @@ module Faaso
# In both cases stopped instances after the required
# scale is reached are deleted.
struct Scale
def local(options, name : String, scale : Int | Nil) : Int32
def local(options, name : String, scale : Int) : Int32
funko = Funko::Funko.from_names([name])[0]
# Asked about scale
if funko.image_history.empty?
Log.error { "Unknown funko #{funko.name}" }
return 1
end
if scale.nil?
if !scale
Log.info { "Funko #{name} has a scale of #{funko.scale}" }
return 0
end
@ -26,21 +26,19 @@ module Faaso
0
end
def remote(options, name : String, scale : Int | Nil) : Int32
def remote(options, name : String, scale : Int) : Int32
user, password = Config.auth
Faaso.check_version
if scale.nil?
Crest.get(
if !scale
response = Crest.get(
"#{Config.server}funkos/#{name}/scale/", \
user: user, password: password) do |response|
IO.copy(response.body_io, STDOUT)
end
return 0
end
Crest.post(
user: user, password: password)
Log.info { " => " + response.body }
else
response = Crest.post(
"#{Config.server}funkos/#{name}/scale/",
{"scale" => scale}, user: user, password: password) do |response|
IO.copy(response.body_io, STDOUT)
{"scale" => scale}, user: user, password: password)
Log.info { " => " + response.body }
end
0
rescue ex : Crest::InternalServerError
@ -48,8 +46,7 @@ module Faaso
1
end
def run(options, name : String, scale) : Int32
scale = scale.try &.to_s.to_i
def run(options, name : String, scale : Int) : Int32
if options["--local"]
return local(options, name, scale)
end

View File

@ -31,7 +31,10 @@ module Faaso
Crest.get(
"#{Config.server}funkos/#{name}/status/", \
user: user, password: password) do |response|
IO.copy(response.body_io, STDOUT)
loop do
Log.info { response.body_io.gets }
break if response.body_io.closed?
end
end
0
rescue ex : Crest::InternalServerError

View File

@ -133,21 +133,20 @@ module Funko
end
# Helper to run faaso locally and respond via env
def run_faaso(args : Array(String), env)
args << "-l" # Always local in the server
Log.info { "Running faaso [#{args}" }
def run_faaso(args : Array(String), env) : Bool
Log.info { "Running faaso [#{args.join(", ")}, -l, 2>&1]" }
Process.run(
command: "faaso",
args: args,
env: {"FAASO_SERVER_SIDE" => "true"},
args: args + ["-l", "2>&1"], # Always local in the server
shell: true,
) do |process|
loop do
data = process.output.gets(chomp: false)
env.response.print data
env.response.print process.output.gets(chomp: false)
env.response.flush
Fiber.yield # Without this the process never ends
Fiber.yield
break if process.terminated?
end
true
end
# FIXME: find a way to raise an exception on failure
# of the faaso process

View File

@ -90,11 +90,7 @@ module Funko
docker_api = Docr::API.new(Docr::Client.new)
current_scale = self.scale
result = [] of String
if current_scale == new_scale
Log.info { "Funko #{name} already at scale #{new_scale}" }
return result
end
return result if current_scale == new_scale
Log.info { "Scaling #{name} from #{current_scale} to #{new_scale}" }
if new_scale > current_scale

View File

@ -35,28 +35,29 @@ Options:
DOC
ans = Docopt.docopt(doc, ARGV)
Oplog.setup(ans["-v"].to_s.to_i) unless ENV.fetch("FAASO_SERVER_SIDE", nil)
Oplog.setup(ans["-v"].to_s.to_i)
Log.debug { ans }
status : Int32 = 0
case ans
when .fetch("build", false)
exit Faaso::Commands::Build.new.run(ans, ans["FOLDER"].as(Array(String)))
status = Faaso::Commands::Build.new.run(ans, ans["FOLDER"].as(Array(String)))
when .fetch("deploy", false)
exit Faaso::Commands::Deploy.new.run(ans, ans["FUNKO"].as(String))
status = Faaso::Commands::Deploy.new.run(ans, ans["FUNKO"].as(String))
when .fetch("export", false)
exit Faaso::Commands::Export.new.run(ans, ans["SOURCE"].as(String), ans["DESTINATION"].as(String))
status = Faaso::Commands::Export.new.run(ans, ans["SOURCE"].as(String), ans["DESTINATION"].as(String))
when .fetch("login", false)
exit Faaso::Commands::Login.new.run(ans)
status = Faaso::Commands::Login.new.run(ans)
when .fetch("new", false)
exit Faaso::Commands::New.new.run(ans, ans["FOLDER"].as(Array(String))[0])
status = Faaso::Commands::New.new.run(ans, ans["FOLDER"].as(Array(String))[0])
when .fetch("scale", false)
exit Faaso::Commands::Scale.new.run(ans, ans["FUNKO"].as(String), ans["SCALE"])
status = Faaso::Commands::Scale.new.run(ans, ans["FUNKO"].as(String), ans["SCALE"].as(String).to_i)
when .fetch("secret", false)
exit Faaso::Commands::Secret.new.run(ans, ans["FUNKO"].as(String), ans["SECRET"].as(String))
status = Faaso::Commands::Secret.new.run(ans, ans["FUNKO"].as(String), ans["SECRET"].as(String))
when .fetch("status", false)
exit Faaso::Commands::Status.new.run(ans, ans["FUNKO"].as(String))
status = Faaso::Commands::Status.new.run(ans, ans["FUNKO"].as(String))
when .fetch("version", false)
Log.info { "#{version}" }
end
exit 0
exit(status)