2024-06-28 17:09:58 +00:00
|
|
|
require "commander"
|
2024-06-28 20:42:10 +00:00
|
|
|
require "docr"
|
|
|
|
require "docr/utils.cr"
|
2024-06-28 19:24:52 +00:00
|
|
|
require "file_utils"
|
|
|
|
require "uuid"
|
2024-06-28 17:09:58 +00:00
|
|
|
|
2024-06-28 15:41:21 +00:00
|
|
|
# TODO: Write documentation for `Faaso`
|
|
|
|
module Faaso
|
|
|
|
VERSION = "0.1.0"
|
|
|
|
|
2024-06-28 17:09:58 +00:00
|
|
|
module Commands
|
|
|
|
class Build
|
|
|
|
@arguments : Array(String) = [] of String
|
|
|
|
@options : Commander::Options
|
|
|
|
|
|
|
|
def initialize(options, arguments)
|
|
|
|
@options = options
|
|
|
|
@arguments = arguments
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
@arguments.each do |arg|
|
|
|
|
puts "Building function... #{arg}"
|
|
|
|
# A function is a folder with stuff in it
|
|
|
|
# TODO: decide template based on file extensions or other metadata
|
2024-06-28 19:24:52 +00:00
|
|
|
template = "templates/crystal"
|
2024-06-28 17:09:58 +00:00
|
|
|
# TODO: copy template and add function files to it
|
2024-06-28 19:24:52 +00:00
|
|
|
tmp_dir = "tmp/#{UUID.random}"
|
|
|
|
Dir.mkdir_p("tmp") unless File.exists? "tmp"
|
|
|
|
FileUtils.cp_r(template, tmp_dir)
|
|
|
|
Dir.glob(arg + "/**/*").each do |file|
|
|
|
|
FileUtils.cp(file, tmp_dir)
|
|
|
|
end
|
2024-06-28 17:09:58 +00:00
|
|
|
# TODO: build Docker image
|
2024-06-28 20:42:10 +00:00
|
|
|
docker_api = Docr::API.new(Docr::Client.new)
|
|
|
|
docker_api.images.build(context: tmp_dir, tags: ["func"]) { }
|
2024-06-28 17:09:58 +00:00
|
|
|
# TODO: push Docker image to registry
|
|
|
|
# TODO: return image name for testing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Up
|
|
|
|
@arguments : Array(String) = [] of String
|
|
|
|
@options : Commander::Options
|
|
|
|
|
|
|
|
def initialize(options, arguments)
|
|
|
|
@options = options
|
|
|
|
@arguments = arguments
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
@arguments.each do |arg|
|
|
|
|
puts "Starting function... #{arg}"
|
|
|
|
# TODO: Check that we have an image for the function
|
|
|
|
# TODO: Start a container with the image
|
|
|
|
# TODO: Run test for healthcheck
|
|
|
|
# TODO: Map route in reverse proxy to function
|
|
|
|
# TODO: Return function URL for testing
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Down
|
|
|
|
@arguments : Array(String) = [] of String
|
|
|
|
@options : Commander::Options
|
|
|
|
|
|
|
|
def initialize(options, arguments)
|
|
|
|
@options = options
|
|
|
|
@arguments = arguments
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
@arguments.each do |arg|
|
|
|
|
puts "Stopping function... #{arg}"
|
|
|
|
# TODO: check if function is running
|
|
|
|
# TODO: stop function container
|
|
|
|
# TODO: delete function container
|
|
|
|
# TODO: remove route from reverse proxy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2024-06-28 15:41:21 +00:00
|
|
|
end
|