faaso build works both local and remote. Basic auth for faaso API (lame, hardcoded)
This commit is contained in:
parent
eb063beb2c
commit
f5467551a1
36
.ameba.yml
36
.ameba.yml
@ -1,9 +1,9 @@
|
|||||||
# This configuration file was generated by `ameba --gen-config`
|
# This configuration file was generated by `ameba --gen-config`
|
||||||
# on 2024-06-30 14:55:35 UTC using Ameba version 1.6.1.
|
# on 2024-06-30 18:10:12 UTC using Ameba version 1.6.1.
|
||||||
# The point is for the user to remove these configuration records
|
# The point is for the user to remove these configuration records
|
||||||
# one by one as the reported problems are removed from the code base.
|
# one by one as the reported problems are removed from the code base.
|
||||||
|
|
||||||
# Problems found: 9
|
# Problems found: 10
|
||||||
# Run `ameba --only Documentation/DocumentationAdmonition` for details
|
# Run `ameba --only Documentation/DocumentationAdmonition` for details
|
||||||
Documentation/DocumentationAdmonition:
|
Documentation/DocumentationAdmonition:
|
||||||
Description: Reports documentation admonitions
|
Description: Reports documentation admonitions
|
||||||
@ -19,3 +19,35 @@ Documentation/DocumentationAdmonition:
|
|||||||
- BUG
|
- BUG
|
||||||
Enabled: true
|
Enabled: true
|
||||||
Severity: Warning
|
Severity: Warning
|
||||||
|
|
||||||
|
# Problems found: 1
|
||||||
|
# Run `ameba --only Naming/BlockParameterName` for details
|
||||||
|
Naming/BlockParameterName:
|
||||||
|
Description: Disallows non-descriptive block parameter names
|
||||||
|
MinNameLength: 3
|
||||||
|
AllowNamesEndingInNumbers: true
|
||||||
|
Excluded:
|
||||||
|
- src/faaso.cr
|
||||||
|
AllowedNames:
|
||||||
|
- _
|
||||||
|
- e
|
||||||
|
- i
|
||||||
|
- j
|
||||||
|
- k
|
||||||
|
- v
|
||||||
|
- x
|
||||||
|
- y
|
||||||
|
- ex
|
||||||
|
- io
|
||||||
|
- ws
|
||||||
|
- op
|
||||||
|
- tx
|
||||||
|
- id
|
||||||
|
- ip
|
||||||
|
- k1
|
||||||
|
- k2
|
||||||
|
- v1
|
||||||
|
- v2
|
||||||
|
ForbiddenNames: []
|
||||||
|
Enabled: true
|
||||||
|
Severity: Convention
|
||||||
|
@ -16,6 +16,8 @@ RUN apk add tinyproxy multirun openssl zlib yaml pcre2 gc libevent libgcc libxml
|
|||||||
RUN addgroup -S app && adduser app -S -G app
|
RUN addgroup -S app && adduser app -S -G app
|
||||||
WORKDIR /home/app
|
WORKDIR /home/app
|
||||||
|
|
||||||
|
RUN mkdir runtimes
|
||||||
|
COPY runtimes/* ./runtimes/
|
||||||
COPY tinyproxy.conf ./
|
COPY tinyproxy.conf ./
|
||||||
COPY --from=build /home/app/bin/faaso-daemon /home/app/bin/faaso /usr/bin/
|
COPY --from=build /home/app/bin/faaso-daemon /home/app/bin/faaso /usr/bin/
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
get "/" do
|
get "/" do
|
||||||
"Hello World Crystal!"
|
"Hello World Crystal!"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
12
shard.lock
12
shard.lock
@ -8,6 +8,10 @@ shards:
|
|||||||
git: https://github.com/mrrooijen/commander.git
|
git: https://github.com/mrrooijen/commander.git
|
||||||
version: 0.4.0
|
version: 0.4.0
|
||||||
|
|
||||||
|
crest:
|
||||||
|
git: https://github.com/mamantoha/crest.git
|
||||||
|
version: 1.3.13
|
||||||
|
|
||||||
crinja:
|
crinja:
|
||||||
git: https://github.com/straight-shoota/crinja.git
|
git: https://github.com/straight-shoota/crinja.git
|
||||||
version: 0.8.1
|
version: 0.8.1
|
||||||
@ -24,6 +28,14 @@ shards:
|
|||||||
git: https://github.com/crystal-loot/exception_page.git
|
git: https://github.com/crystal-loot/exception_page.git
|
||||||
version: 0.4.1
|
version: 0.4.1
|
||||||
|
|
||||||
|
http-client-digest_auth:
|
||||||
|
git: https://github.com/mamantoha/http-client-digest_auth.git
|
||||||
|
version: 0.6.0
|
||||||
|
|
||||||
|
http_proxy:
|
||||||
|
git: https://github.com/mamantoha/http_proxy.git
|
||||||
|
version: 0.10.3
|
||||||
|
|
||||||
kemal:
|
kemal:
|
||||||
git: https://github.com/kemalcr/kemal.git
|
git: https://github.com/kemalcr/kemal.git
|
||||||
version: 1.5.0
|
version: 1.5.0
|
||||||
|
@ -27,4 +27,6 @@ dependencies:
|
|||||||
crinja:
|
crinja:
|
||||||
github: straight-shoota/crinja
|
github: straight-shoota/crinja
|
||||||
crystar:
|
crystar:
|
||||||
github: naqvis/crystar
|
github: naqvis/crystar
|
||||||
|
crest:
|
||||||
|
github: mamantoha/crest
|
@ -73,7 +73,7 @@ post "/funko/build/" do |env|
|
|||||||
stdout = IO::Memory.new
|
stdout = IO::Memory.new
|
||||||
status = Process.run(
|
status = Process.run(
|
||||||
command: "faaso",
|
command: "faaso",
|
||||||
args: ["build", tmp_dir.to_s],
|
args: ["build", "-l", tmp_dir.to_s],
|
||||||
output: stdout,
|
output: stdout,
|
||||||
error: stderr,
|
error: stderr,
|
||||||
)
|
)
|
||||||
|
73
src/faaso.cr
73
src/faaso.cr
@ -1,9 +1,17 @@
|
|||||||
require "./funko.cr"
|
require "./funko.cr"
|
||||||
require "commander"
|
require "commander"
|
||||||
|
require "crest"
|
||||||
require "docr"
|
require "docr"
|
||||||
require "docr/utils.cr"
|
require "docr/utils.cr"
|
||||||
|
require "json"
|
||||||
require "uuid"
|
require "uuid"
|
||||||
|
|
||||||
|
# API if you just ran faaso-daemon
|
||||||
|
FAASO_API = "http://localhost:3000/"
|
||||||
|
|
||||||
|
# API if you are running the proxy image locally
|
||||||
|
# FAASO_API="http://localhost:8888/admin/"
|
||||||
|
|
||||||
# Functions as a Service, Ops!
|
# Functions as a Service, Ops!
|
||||||
module Faaso
|
module Faaso
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.0"
|
||||||
@ -34,14 +42,65 @@ module Faaso
|
|||||||
|
|
||||||
def run
|
def run
|
||||||
funkos = Funko.from_paths(@arguments)
|
funkos = Funko.from_paths(@arguments)
|
||||||
funkos.each do |funko|
|
local = @options.@bool["local"]
|
||||||
# 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
|
|
||||||
|
|
||||||
puts "Building function... #{funko.name} in #{tmp_dir}"
|
if local
|
||||||
funko.build tmp_dir
|
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
|
||||||
|
|
||||||
|
puts "Building function... #{funko.name} in #{tmp_dir}"
|
||||||
|
funko.build tmp_dir
|
||||||
|
end
|
||||||
|
else # Running against a server
|
||||||
|
funkos.each do |funko|
|
||||||
|
# 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|
|
||||||
|
next unless File.file? path
|
||||||
|
rel_path = Path[path].relative_to funko.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
|
||||||
|
end
|
||||||
|
|
||||||
|
tmp = File.tempname
|
||||||
|
File.open(tmp, "w") do |outf|
|
||||||
|
outf << buf
|
||||||
|
end
|
||||||
|
|
||||||
|
url = "#{FAASO_API}funko/build/"
|
||||||
|
|
||||||
|
begin
|
||||||
|
_response = Crest.post(
|
||||||
|
url,
|
||||||
|
{"funko.tgz" => File.open(tmp), "name" => "funko.tgz"},
|
||||||
|
user: "admin", password: "admin"
|
||||||
|
)
|
||||||
|
puts "Build finished successfully."
|
||||||
|
# body = JSON.parse(_response.body)
|
||||||
|
# puts body["stdout"]
|
||||||
|
# puts body["stderr"]
|
||||||
|
rescue ex : Crest::InternalServerError
|
||||||
|
puts "Error building image."
|
||||||
|
body = JSON.parse(ex.response.body)
|
||||||
|
puts body["stdout"]
|
||||||
|
puts body["stderr"]
|
||||||
|
puts "Error building funko #{funko.name} from #{funko.path}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -80,7 +80,7 @@ class Funko
|
|||||||
docker_api = Docr::API.new(Docr::Client.new)
|
docker_api = Docr::API.new(Docr::Client.new)
|
||||||
docker_api.images.build(
|
docker_api.images.build(
|
||||||
context: path.to_s,
|
context: path.to_s,
|
||||||
tags: ["#{name}:latest"]) { }
|
tags: ["#{name}:latest"]) { |x| puts x }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a list of image IDs for this funko, most recent first
|
# Return a list of image IDs for this funko, most recent first
|
||||||
|
@ -5,6 +5,15 @@ cli = Commander::Command.new do |cmd|
|
|||||||
cmd.use = "faaso"
|
cmd.use = "faaso"
|
||||||
cmd.long = "Functions as a Service, Open"
|
cmd.long = "Functions as a Service, Open"
|
||||||
|
|
||||||
|
cmd.flags.add do |flag|
|
||||||
|
flag.name = "local"
|
||||||
|
flag.short = "-l"
|
||||||
|
flag.long = "--local"
|
||||||
|
flag.description = "Run commands locally instead of against a FaaSO server."
|
||||||
|
flag.default = false
|
||||||
|
flag.persistent = true
|
||||||
|
end
|
||||||
|
|
||||||
cmd.commands.add do |command|
|
cmd.commands.add do |command|
|
||||||
command.use = "build"
|
command.use = "build"
|
||||||
command.short = "Build a funko"
|
command.short = "Build a funko"
|
||||||
|
Loading…
Reference in New Issue
Block a user