Compare commits
4 Commits
a4f722a1e0
...
6ca518ae32
Author | SHA1 | Date | |
---|---|---|---|
6ca518ae32 | |||
2a6f64a53e | |||
1648f2f99e | |||
227c770b61 |
2
Makefile
2
Makefile
@ -3,7 +3,7 @@ build: shard.yml $(wildcard src/**/*cr)
|
|||||||
proxy: build
|
proxy: build
|
||||||
docker build . -t faaso-proxy --no-cache
|
docker build . -t faaso-proxy --no-cache
|
||||||
start-proxy:
|
start-proxy:
|
||||||
docker run --network=faaso-net -v /var/run/docker.sock:/var/run/docker.sock -v secrets:/home/app/secrets -p 8888:8888 faaso-proxy
|
docker run --name faaso_proxy --rm --network=faaso-net -v /var/run/docker.sock:/var/run/docker.sock -v secrets:/home/app/secrets -p 8888:8888 faaso-proxy
|
||||||
|
|
||||||
|
|
||||||
.PHONY: build proxy-image start-proxy
|
.PHONY: build proxy-image start-proxy
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css" />
|
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css" />
|
||||||
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<header class="container">
|
||||||
async function getFunkos() {
|
<h1>Your Funko Collection</h1>
|
||||||
const response = await fetch("funkos/");
|
</header>
|
||||||
funkos = await response.json();
|
<main class=container>
|
||||||
console.log(funkos);
|
|
||||||
}
|
|
||||||
getFunkos();
|
|
||||||
</script>
|
|
||||||
<button hx-get="funkos/?format=html" hx-target="#funko-list">Update</button>
|
<button hx-get="funkos/?format=html" hx-target="#funko-list">Update</button>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
@ -21,5 +20,6 @@
|
|||||||
<tbody id="funko-list">
|
<tbody id="funko-list">
|
||||||
</tbody>
|
</tbody>
|
||||||
</thead>
|
</thead>
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</head>
|
</head>
|
||||||
|
37
src/daemon/funko.cr
Normal file
37
src/daemon/funko.cr
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
require "docr"
|
||||||
|
require "kemal"
|
||||||
|
require "../funko.cr"
|
||||||
|
|
||||||
|
module Funko
|
||||||
|
extend self
|
||||||
|
|
||||||
|
get "/funkos/" do |env|
|
||||||
|
funkos = Funko.from_docker
|
||||||
|
funkos.sort! { |a, b| a.name <=> b.name }
|
||||||
|
result = [] of Hash(String, String)
|
||||||
|
|
||||||
|
funkos.each do |funko|
|
||||||
|
state = ""
|
||||||
|
case funko
|
||||||
|
when .running?
|
||||||
|
state = "running"
|
||||||
|
when .paused?
|
||||||
|
state = "paused"
|
||||||
|
else
|
||||||
|
state = "stopped"
|
||||||
|
end
|
||||||
|
|
||||||
|
result << {
|
||||||
|
"name" => funko.name,
|
||||||
|
"state" => state,
|
||||||
|
"status" => funko.status,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
if env.params.query.fetch("format", "json") == "html"
|
||||||
|
render "src/views/funkos.ecr"
|
||||||
|
else
|
||||||
|
result.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -1,17 +0,0 @@
|
|||||||
require "docr"
|
|
||||||
require "kemal"
|
|
||||||
require "../funko.cr"
|
|
||||||
|
|
||||||
module Funkos
|
|
||||||
get "/funkos/" do |env|
|
|
||||||
funkos : Array(Funko) = Funko.from_docker
|
|
||||||
|
|
||||||
funkos.sort! { |a, b| a.name <=> b.name }
|
|
||||||
|
|
||||||
if env.params.query.fetch("format", "json") == "html"
|
|
||||||
render "src/views/funkos.ecr"
|
|
||||||
else
|
|
||||||
funkos.to_json
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,4 +1,4 @@
|
|||||||
require "./funkos.cr"
|
require "./funko.cr"
|
||||||
require "./proxyconf.cr"
|
require "./proxyconf.cr"
|
||||||
require "./secrets.cr"
|
require "./secrets.cr"
|
||||||
require "compress/gzip"
|
require "compress/gzip"
|
||||||
|
@ -1,44 +1,10 @@
|
|||||||
require "kemal"
|
require "kemal"
|
||||||
|
require "../secrets.cr"
|
||||||
|
|
||||||
module Secrets
|
module Secrets
|
||||||
SECRETS = Hash(String, String).new
|
extend self
|
||||||
SECRET_PATH = "./secrets/"
|
|
||||||
|
|
||||||
# TODO: sanitize all inputs
|
# TODO: sanitize all inputs
|
||||||
|
|
||||||
# Store secrets in a tree of files
|
|
||||||
def self.update_secrets
|
|
||||||
# Save new secrets
|
|
||||||
SECRETS.map do |_name, value|
|
|
||||||
funko, name = _name.split("-", 2)
|
|
||||||
funko_dir = Path.new(SECRET_PATH, funko)
|
|
||||||
Dir.mkdir_p(funko_dir)
|
|
||||||
File.write(Path.new(funko_dir, name), value)
|
|
||||||
end
|
|
||||||
# Delete secrets not in the hash
|
|
||||||
Dir.glob(Path.new(SECRET_PATH, "*")).each do |funko_dir|
|
|
||||||
funko = File.basename(funko_dir)
|
|
||||||
Dir.glob(Path.new(funko_dir, "*")).each do |secret_file|
|
|
||||||
name = File.basename(secret_file)
|
|
||||||
unless SECRETS.has_key?("#{funko}-#{name}")
|
|
||||||
File.delete(secret_file)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Load secrets from the disk
|
|
||||||
def self.load_secrets
|
|
||||||
Dir.glob(Path.new(SECRET_PATH, "*")).each do |funko_dir|
|
|
||||||
funko = File.basename(funko_dir)
|
|
||||||
Dir.glob(Path.new(funko_dir, "*")).each do |secret_file|
|
|
||||||
name = File.basename(secret_file)
|
|
||||||
value = File.read(secret_file)
|
|
||||||
SECRETS["#{funko}-#{name}"] = value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Gets a secret in form {"name": "funko_name-secret_name", "value": "secret_value"}
|
# Gets a secret in form {"name": "funko_name-secret_name", "value": "secret_value"}
|
||||||
post "/secrets/" do |env|
|
post "/secrets/" do |env|
|
||||||
name = env.params.json["name"].as(String)
|
name = env.params.json["name"].as(String)
|
||||||
|
@ -38,7 +38,7 @@ module Faaso
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
funkos = Funko.from_paths(@arguments)
|
funkos = Funko::Funko.from_paths(@arguments)
|
||||||
local = @options.@bool["local"]
|
local = @options.@bool["local"]
|
||||||
|
|
||||||
if local
|
if local
|
||||||
@ -120,7 +120,7 @@ module Faaso
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
funkos = Funko.from_names(@arguments)
|
funkos = Funko::Funko.from_names(@arguments)
|
||||||
funkos.each do |funko|
|
funkos.each do |funko|
|
||||||
local = @options.@bool["local"]
|
local = @options.@bool["local"]
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ module Faaso
|
|||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
funkos = Funko.from_paths(@arguments)
|
funkos = Funko::Funko.from_paths(@arguments)
|
||||||
funkos.each do |funko|
|
funkos.each do |funko|
|
||||||
# Create temporary build location
|
# Create temporary build location
|
||||||
dst_path = Path.new("export", funko.name)
|
dst_path = Path.new("export", funko.name)
|
||||||
|
30
src/funko.cr
30
src/funko.cr
@ -3,7 +3,10 @@ require "file_utils"
|
|||||||
require "yaml"
|
require "yaml"
|
||||||
|
|
||||||
# A funko, built from its source metadata
|
# A funko, built from its source metadata
|
||||||
class Funko
|
module Funko
|
||||||
|
extend self
|
||||||
|
|
||||||
|
class Funko
|
||||||
include YAML::Serializable
|
include YAML::Serializable
|
||||||
|
|
||||||
# Required, the name of the funko. Must be unique across FaaSO
|
# Required, the name of the funko. Must be unique across FaaSO
|
||||||
@ -68,15 +71,19 @@ class Funko
|
|||||||
# Get all the funkos docker knows about.
|
# Get all the funkos docker knows about.
|
||||||
def self.from_docker : Array(Funko)
|
def self.from_docker : Array(Funko)
|
||||||
docker_api = Docr::API.new(Docr::Client.new)
|
docker_api = Docr::API.new(Docr::Client.new)
|
||||||
names = Set(String).new
|
names = [] of String
|
||||||
docker_api.images.list(all: true).select { |i|
|
funko_containers = docker_api.containers.list(
|
||||||
next if i.@repo_tags.nil?
|
all: true,
|
||||||
i.@repo_tags.as(Array(String)).each { |tag|
|
).each { |container|
|
||||||
names << tag.split(":", 2)[0].split("-", 2)[1] if tag.starts_with?("faaso-")
|
p! container.@names
|
||||||
|
container.@names.each { |name|
|
||||||
|
names << name.split("-", 2)[1].lstrip("/") if name.starts_with?("/faaso-")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pp! names
|
pp! names
|
||||||
from_names(names.to_a)
|
|
||||||
|
from_names(names.to_a.sort!)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Setup the target directory `path` with all the files needed
|
# Setup the target directory `path` with all the files needed
|
||||||
@ -137,6 +144,14 @@ class Funko
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Descriptive status for the funko
|
||||||
|
def status
|
||||||
|
status = self.containers.map { |container|
|
||||||
|
container.@status
|
||||||
|
}.join(", ")
|
||||||
|
status.empty? ? "Stopped" : status
|
||||||
|
end
|
||||||
|
|
||||||
# Is any instance of this funko running?
|
# Is any instance of this funko running?
|
||||||
def running?
|
def running?
|
||||||
self.containers.any? { |container|
|
self.containers.any? { |container|
|
||||||
@ -209,4 +224,5 @@ class Funko
|
|||||||
docker_api.containers.start(response.@id) if autostart
|
docker_api.containers.start(response.@id) if autostart
|
||||||
response.@id
|
response.@id
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
42
src/secrets.cr
Normal file
42
src/secrets.cr
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
module Secrets
|
||||||
|
extend self
|
||||||
|
SECRETS = Hash(String, String).new
|
||||||
|
SECRET_PATH = "./secrets/"
|
||||||
|
|
||||||
|
# TODO: sanitize all inputs
|
||||||
|
|
||||||
|
# Store secrets in a tree of files
|
||||||
|
def update_secrets
|
||||||
|
# Save new secrets
|
||||||
|
SECRETS.map do |_name, value|
|
||||||
|
funko, name = _name.split("-", 2)
|
||||||
|
funko_dir = Path.new(SECRET_PATH, funko)
|
||||||
|
Dir.mkdir_p(funko_dir)
|
||||||
|
File.write(Path.new(funko_dir, name), value)
|
||||||
|
end
|
||||||
|
# Delete secrets not in the hash
|
||||||
|
Dir.glob(Path.new(SECRET_PATH, "*")).each do |funko_dir|
|
||||||
|
funko = File.basename(funko_dir)
|
||||||
|
Dir.glob(Path.new(funko_dir, "*")).each do |secret_file|
|
||||||
|
name = File.basename(secret_file)
|
||||||
|
unless SECRETS.has_key?("#{funko}-#{name}")
|
||||||
|
File.delete(secret_file)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Load secrets from the disk
|
||||||
|
def load_secrets
|
||||||
|
Dir.glob(Path.new(SECRET_PATH, "*")).each do |funko_dir|
|
||||||
|
funko = File.basename(funko_dir)
|
||||||
|
Dir.glob(Path.new(funko_dir, "*")).each do |secret_file|
|
||||||
|
name = File.basename(secret_file)
|
||||||
|
value = File.read(secret_file)
|
||||||
|
SECRETS["#{funko}-#{name}"] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Secrets.load_secrets
|
@ -1,7 +1,26 @@
|
|||||||
<%- funkos.each do |funko| -%>
|
<%- result.each do |f| -%>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= funko.name %></td>
|
<td><%= f["name"] %></td>
|
||||||
<td>sarasa</td>
|
<td><%= f["status"] %></td>
|
||||||
<td><button>DOSTUFF</button></td>
|
<td>
|
||||||
|
<%- if f["state"] == "running" -%>
|
||||||
|
<button state="disabled">Start</button>
|
||||||
|
<button>Pause</button>
|
||||||
|
<button>Stop</button>
|
||||||
|
<button>Restart</button>
|
||||||
|
<%- end -%>
|
||||||
|
<%- if f["state"] == "paused" -%>
|
||||||
|
<button>Start</button>
|
||||||
|
<button disabled>Pause</button>
|
||||||
|
<button>Stop</button>
|
||||||
|
<button>Restart</button>
|
||||||
|
<%- end -%>
|
||||||
|
<%- if f["state"] == "stopped" -%>
|
||||||
|
<button>Start</button>
|
||||||
|
<button disabled>Pause</button>
|
||||||
|
<button disabled>Stop</button>
|
||||||
|
<button disabled>Restart</button>
|
||||||
|
<%- end -%>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
Loading…
Reference in New Issue
Block a user