Compare commits
2 Commits
3b2297e954
...
main
Author | SHA1 | Date | |
---|---|---|---|
21893fe612 | |||
665b4f9ab7 |
6
TODO.md
6
TODO.md
@ -14,9 +14,9 @@
|
|||||||
* ✅ Nodejs + Express
|
* ✅ Nodejs + Express
|
||||||
* Create a site
|
* Create a site
|
||||||
* Document
|
* Document
|
||||||
* How to create a runtime
|
* FaaSO for app developers
|
||||||
* How to create a funko
|
* FaaSO for runtime developers
|
||||||
* How to setup the proxy
|
* FaaSO server setup
|
||||||
* APIs
|
* APIs
|
||||||
* Sanitize all inputs
|
* Sanitize all inputs
|
||||||
* ✅ Streaming responses in slow operations like scaling down
|
* ✅ Streaming responses in slow operations like scaling down
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css" />
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css" />
|
||||||
<script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.colors.min.css" /> <script src="https://unpkg.com/htmx.org@2.0.0"></script>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -11,15 +11,20 @@
|
|||||||
<header class="container">
|
<header class="container">
|
||||||
<h1>FaaSO Admin Interface</h1>
|
<h1>FaaSO Admin Interface</h1>
|
||||||
</header>
|
</header>
|
||||||
<main class=container>
|
<article>
|
||||||
<h2>Your Funko Collection
|
<nav>
|
||||||
<button id="update-funkos" style="float:right; display:inline;" hx-trigger="load, click, every 60s"
|
<ul>
|
||||||
|
<li><strong style="font-size: 200%;">Your Funko Collection</strong></li>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><button id="update-funkos" style="float:right; display:inline;" hx-trigger="load, click, every 60s"
|
||||||
hx-get="funkos/?format=html" hx-target="#funko-list">
|
hx-get="funkos/?format=html" hx-target="#funko-list">
|
||||||
Refresh
|
Refresh
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</ul>
|
||||||
|
</nav>
|
||||||
<span id="message"></span>
|
<span id="message"></span>
|
||||||
<table hx-target="#message">
|
<table hx-target="#message" class="striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
@ -31,23 +36,27 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<div id="terminal" style="resize: vertical; overflow: auto;"></div>
|
<div id="terminal" style="resize: vertical; overflow: auto;"></div>
|
||||||
</main>
|
</article>
|
||||||
<script>
|
<script>
|
||||||
update_funkos = function () {
|
update_funkos = function () {
|
||||||
document.getElementById("update-funkos").click()
|
document.getElementById("update-funkos").click()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<main class=container>
|
<article>
|
||||||
<h2>
|
<nav>
|
||||||
Your Secrets
|
<ul>
|
||||||
<button id="update-secrets" style="float:right; display:inline;" hx-trigger="load, click, every 60s"
|
<li><strong style="font-size: 200%;">Your Secrets</strong>
|
||||||
|
</ul>
|
||||||
|
<ul>
|
||||||
|
<li><button id="update-secrets" style="float:right; display:inline;" hx-trigger="load, click, every 60s"
|
||||||
hx-get="secrets/?format=html" hx-target="#secret-list">
|
hx-get="secrets/?format=html" hx-target="#secret-list">
|
||||||
Refresh
|
Refresh
|
||||||
</button>
|
</button>
|
||||||
<button style="float:right; display:inline;" onclick="show_new_secret()">
|
<li><button style="float:right; display:inline;" onclick="show_new_secret()">
|
||||||
Add
|
Add
|
||||||
</button>
|
</button>
|
||||||
</h2>
|
</ul>
|
||||||
|
</nav>
|
||||||
<span id="message"></span>
|
<span id="message"></span>
|
||||||
<table hx-target="#message">
|
<table hx-target="#message">
|
||||||
<thead>
|
<thead>
|
||||||
@ -60,14 +69,20 @@
|
|||||||
<tbody id="secret-list">
|
<tbody id="secret-list">
|
||||||
</tbody>
|
</tbody>
|
||||||
<dialog id="add-secret">
|
<dialog id="add-secret">
|
||||||
<topic>New Secret</topic>
|
<article>
|
||||||
|
<header>
|
||||||
|
New Secret
|
||||||
|
</header>
|
||||||
<form hx-post="secrets/">
|
<form hx-post="secrets/">
|
||||||
<input placeholder="funko name" id="new-secret-funko" name="funko">
|
<input placeholder="funko name" id="new-secret-funko" name="funko">
|
||||||
<input placeholder="secret name" id="new-secret-name" name="name">
|
<input placeholder="secret name" id="new-secret-name" name="name">
|
||||||
<input placeholder="secret value" type="password" id="new-secret-password" name="value">
|
<input placeholder="secret value" type="password" id="new-secret-password" name="value">
|
||||||
<button type="submit" hx-on:htmx:after-request="hide_new_secret()">CREATE</button>
|
<fieldset role="group" style="text-align: right;">
|
||||||
|
<button style="width:9em; display: inline;" type="submit" hx-on:htmx:after-request="hide_new_secret()">CREATE</button>
|
||||||
|
<button style="width:9em; display: inline;" onclick="hide_new_secret(); close();" aria-label="Close" rel="prev">CLOSE</button>
|
||||||
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
<button onclick="hide_new_secret(); close();">CLOSE</button>
|
</article>
|
||||||
</dialog>
|
</dialog>
|
||||||
<script>
|
<script>
|
||||||
update_secrets = function() {
|
update_secrets = function() {
|
||||||
@ -87,5 +102,5 @@
|
|||||||
update_secrets()
|
update_secrets()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</main>
|
</article>
|
||||||
</body>
|
</body>
|
||||||
|
@ -44,10 +44,6 @@ shards:
|
|||||||
git: https://github.com/mamantoha/http_proxy.git
|
git: https://github.com/mamantoha/http_proxy.git
|
||||||
version: 0.10.3
|
version: 0.10.3
|
||||||
|
|
||||||
inotify:
|
|
||||||
git: https://github.com/petoem/inotify.cr.git
|
|
||||||
version: 1.0.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
|
||||||
|
@ -30,8 +30,6 @@ dependencies:
|
|||||||
docr:
|
docr:
|
||||||
github: ralsina/docr
|
github: ralsina/docr
|
||||||
branch: add_exposed_ports
|
branch: add_exposed_ports
|
||||||
inotify:
|
|
||||||
github: petoem/inotify.cr
|
|
||||||
kemal:
|
kemal:
|
||||||
github: kemalcr/kemal
|
github: kemalcr/kemal
|
||||||
kemal-basic-auth:
|
kemal-basic-auth:
|
||||||
|
@ -1,16 +1,11 @@
|
|||||||
require "./funko.cr"
|
require "./funko.cr"
|
||||||
require "docr"
|
require "docr"
|
||||||
require "inotify"
|
|
||||||
require "kemal"
|
require "kemal"
|
||||||
|
|
||||||
module Proxy
|
module Proxy
|
||||||
CADDY_CONFIG_PATH = "config/funkos"
|
CADDY_CONFIG_PATH = "config/Caddyfile"
|
||||||
@@current_config = File.read(CADDY_CONFIG_PATH)
|
CADDY_CONFIG_FUNKOS = "config/funkos"
|
||||||
|
@@current_config = File.read(CADDY_CONFIG_FUNKOS)
|
||||||
@@watcher = Inotify.watch(CADDY_CONFIG_PATH) do |_|
|
|
||||||
Log.info { "Reloading caddy config" }
|
|
||||||
Process.run(command: "caddy", args: ["reload", "--config", CADDY_CONFIG_PATH])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get current proxy config
|
# Get current proxy config
|
||||||
get "/proxy/" do
|
get "/proxy/" do
|
||||||
@ -25,7 +20,7 @@ module Proxy
|
|||||||
update_proxy_config
|
update_proxy_config
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.update_proxy_config
|
def self.update_proxy_config : Nil
|
||||||
docker_api = Docr::API.new(Docr::Client.new)
|
docker_api = Docr::API.new(Docr::Client.new)
|
||||||
containers = docker_api.containers.list(all: true)
|
containers = docker_api.containers.list(all: true)
|
||||||
|
|
||||||
@ -50,13 +45,13 @@ module Proxy
|
|||||||
|
|
||||||
if @@current_config != config
|
if @@current_config != config
|
||||||
Log.info { "Updating proxy config" }
|
Log.info { "Updating proxy config" }
|
||||||
File.open(CADDY_CONFIG_PATH, "w") do |file|
|
File.open(CADDY_CONFIG_FUNKOS, "w") do |file|
|
||||||
file << config
|
file << config
|
||||||
end
|
end
|
||||||
# Reload config
|
# Reload config
|
||||||
@@current_config = config
|
@@current_config = config
|
||||||
|
Process.run(command: "caddy", args: ["reload", "--config", CADDY_CONFIG_PATH])
|
||||||
end
|
end
|
||||||
config
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,39 +1,32 @@
|
|||||||
<%- result.each do |f| -%>
|
<%- result.each do |f| -%>
|
||||||
<tr hx-indicator="#spinner-<%= f["name"] %>">
|
<tr hx-indicator="#spinner-<%= f["name"] %>">
|
||||||
<td>
|
<td style="vertical-align: top;">
|
||||||
<%= f["name"] %>
|
<%= f["name"] %>
|
||||||
<img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
|
<img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td style="vertical-align: top;">
|
||||||
<table>
|
<%- f["containers"].as(Array(Docr::Types::ContainerSummary)).each do |c| -%>
|
||||||
<thead>
|
<div class="grid">
|
||||||
<th>ID</th>
|
<div>
|
||||||
<th>Current?</th>
|
<tt><%= c.@names[0].split("-")[-1] %></tt>
|
||||||
<th>Actions</th>
|
</div>
|
||||||
</thead>
|
<div>
|
||||||
<tbody>
|
|
||||||
<%- f["containers"].as(Array(Docr::Types::ContainerSummary)).each do |c| -%>
|
|
||||||
<tr>
|
|
||||||
<td><tt><%= c.@names[0].split("-")[-1] %></tt></td>
|
|
||||||
<td>
|
|
||||||
<%- if c.image_id == f["latest_image"] -%>
|
<%- if c.image_id == f["latest_image"] -%>
|
||||||
<span style="color:green;""> 🟢</span>
|
<span style="color:green;""> 🟢</span>
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<span style="color:red;""> 🟢</span>
|
<span style="color:red;""> 🟢</span>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</td>
|
</div>
|
||||||
<td>
|
<div role="group">
|
||||||
<button hx-target="#terminal" hx-get="funkos/terminal/logs/<%= c.@names[0].lstrip("/") %>/">Logs</button>
|
<button hx-target="#terminal" hx-get="funkos/terminal/logs/<%= c.@names[0].lstrip("/") %>/">Logs</button>
|
||||||
<button hx-target="#terminal" hx-get="funkos/terminal/shell/<%= c.@names[0].lstrip("/") %>/">Shell</button>
|
<button hx-target="#terminal" hx-get="funkos/terminal/shell/<%= c.@names[0].lstrip("/") %>/">Shell</button>
|
||||||
</td>
|
</div>
|
||||||
</tr>
|
</div>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</tbody>
|
|
||||||
</p>
|
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
</table>
|
|
||||||
<td>
|
<td>
|
||||||
|
<div role="group">
|
||||||
<%- if f["name"] == "proxy" -%>
|
<%- if f["name"] == "proxy" -%>
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<%- if f["scale"].as(String).to_i > 0 -%>
|
<%- if f["scale"].as(String).to_i > 0 -%>
|
||||||
@ -47,6 +40,7 @@
|
|||||||
<%- end -%>
|
<%- end -%>
|
||||||
<button hx-get="funkos/<%= f["name"] %>/restart" hx-on:htmx:after-request="update_funkos()">Restart</button>
|
<button hx-get="funkos/<%= f["name"] %>/restart" hx-on:htmx:after-request="update_funkos()">Restart</button>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
Reference in New Issue
Block a user