Nth redesign of the funkos dashboard

This commit is contained in:
Roberto Alsina 2024-07-04 17:48:22 -03:00
parent ead5cfdcc6
commit 6698bbd67a
5 changed files with 55 additions and 18 deletions

View File

@ -12,4 +12,13 @@ http://localhost:8888 {
handle_path /admin/* { handle_path /admin/* {
reverse_proxy /* http://127.0.0.1:3000 reverse_proxy /* http://127.0.0.1:3000
} }
}
handle_path /faaso/hello/* {
reverse_proxy /* http://faaso-hello-8t3u59:3000 http://faaso-hello-5epnbg:3000 http://faaso-hello-zt5j6g:3000 {
health_uri /ping
fail_duration 30s
}
}
}

View File

@ -23,9 +23,7 @@
<thead> <thead>
<tr> <tr>
<th>Name</th> <th>Name</th>
<th>Scale</th> <th>Instances</th>
<th>Containers</th>
<th>Images</th>
<th>Actions</th> <th>Actions</th>
</tr> </tr>
</thead> </thead>

View File

@ -79,14 +79,14 @@ module Funko
get "/funkos/" do |env| get "/funkos/" do |env|
funkos = Funko.from_docker funkos = Funko.from_docker
funkos.sort! { |a, b| a.name <=> b.name } funkos.sort! { |a, b| a.name <=> b.name }
result = [] of Hash(String, String) result = [] of Hash(String, String | Array(Docr::Types::ContainerSummary))
funkos.each do |funko| funkos.each do |funko|
result << { result << {
"name" => funko.name, "name" => funko.name,
"scale" => funko.scale.to_s, "scale" => funko.scale.to_s,
"containers" => funko.containers.size.to_s, "containers" => funko.containers,
"images" => funko.images.size.to_s, "latest_image" => funko.latest_image,
} }
end end

View File

@ -178,8 +178,12 @@ module Funko
end end
end end
def latest_image
image_history.first
end
# Get all running containers related to this funko # Get all running containers related to this funko
def containers def containers : Array(Docr::Types::ContainerSummary)
docker_api = Docr::API.new(Docr::Client.new) docker_api = Docr::API.new(Docr::Client.new)
docker_api.containers.list(all: true).select { |container| docker_api.containers.list(all: true).select { |container|
container.@names.any?(&.starts_with?("/faaso-#{name}-")) && container.@names.any?(&.starts_with?("/faaso-#{name}-")) &&

View File

@ -1,13 +1,42 @@
<%- result.each do |f| -%> <%- result.each do |f| -%>
<tr hx-indicator="#spinner-<%= f["name"] %>"> <tr hx-indicator="#spinner-<%= f["name"] %>">
<td><%= f["name"] %></td> <td>
<td><%= f["scale"] %></td> <%= f["name"] %>
<td><%= f["containers"] %></td> <img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
<td><%= f["images"] %></td> </td>
<td>
<table>
<thead>
<th>ID</th>
<th>Current?</th>
<th>Actions</th>
</thead>
<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"] -%>
<span style="color:green;""> 🟢</span>
<%- else -%>
<span style="color:red;""> 🟢</span>
<%- end -%>
</td>
<td>
<button hx-target="#terminal" hx-get="funkos/<%= f["name"] %>/terminal/logs/">Logs</button>
<button hx-target="#terminal" hx-get="funkos/<%= f["name"] %>/terminal/shell/">Shell</button>
</td>
</tr>
<%- end -%>
</tbody>
</p>
</td>
</table>
<td> <td>
<%- if f["name"] == "proxy" -%> <%- if f["name"] == "proxy" -%>
<%- else -%> <%- else -%>
<%- if f["scale"].to_i > 0 -%> <%- if f["scale"].as(String).to_i > 0 -%>
<button disabled hx-get="funkos/<%= f["name"] %>/start">Start</button> <button disabled hx-get="funkos/<%= f["name"] %>/start">Start</button>
<button hx-get="funkos/<%= f["name"] %>/stop" hx-on:htmx:after-request="update_funkos()">Stop</button> <button hx-get="funkos/<%= f["name"] %>/stop" hx-on:htmx:after-request="update_funkos()">Stop</button>
<%- else -%> <%- else -%>
@ -15,10 +44,7 @@
<button disabled hx-get="funkos/<%= f["name"] %>/stop" hx-on:htmx:after-request="update_funkos()">Stop</button> <button disabled hx-get="funkos/<%= f["name"] %>/stop" hx-on:htmx:after-request="update_funkos()">Stop</button>
<%- 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>
<button hx-target="#terminal" hx-get="funkos/<%= f["name"] %>/terminal/logs/">Logs</button>
<button hx-target="#terminal" hx-get="funkos/<%= f["name"] %>/terminal/shell/">Shell</button>
<%- end -%> <%- end -%>
<img id="spinner-<%= f["name"] %>" src="bars.svg" class="htmx-indicator">
</td> </td>
</tr> </tr>
<%- end -%> <%- end -%>