From 6698bbd67a5e90b6e5d19c22aa11a43db82e40f4 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 4 Jul 2024 17:48:22 -0300 Subject: [PATCH] Nth redesign of the funkos dashboard --- Caddyfile | 11 ++++++++++- public/index.html | 4 +--- src/daemon/funko.cr | 10 +++++----- src/funko.cr | 6 +++++- src/views/funkos.ecr | 42 ++++++++++++++++++++++++++++++++++-------- 5 files changed, 55 insertions(+), 18 deletions(-) diff --git a/Caddyfile b/Caddyfile index 2c16579..9f89473 100644 --- a/Caddyfile +++ b/Caddyfile @@ -12,4 +12,13 @@ http://localhost:8888 { handle_path /admin/* { 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 + } + } + +} \ No newline at end of file diff --git a/public/index.html b/public/index.html index bbf614e..1b5cb94 100644 --- a/public/index.html +++ b/public/index.html @@ -23,9 +23,7 @@ Name - Scale - Containers - Images + Instances Actions diff --git a/src/daemon/funko.cr b/src/daemon/funko.cr index 99f92a0..5f708c6 100644 --- a/src/daemon/funko.cr +++ b/src/daemon/funko.cr @@ -79,14 +79,14 @@ module Funko get "/funkos/" do |env| funkos = Funko.from_docker 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| result << { - "name" => funko.name, - "scale" => funko.scale.to_s, - "containers" => funko.containers.size.to_s, - "images" => funko.images.size.to_s, + "name" => funko.name, + "scale" => funko.scale.to_s, + "containers" => funko.containers, + "latest_image" => funko.latest_image, } end diff --git a/src/funko.cr b/src/funko.cr index b0003fd..543c6ef 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -178,8 +178,12 @@ module Funko end end + def latest_image + image_history.first + end + # 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.containers.list(all: true).select { |container| container.@names.any?(&.starts_with?("/faaso-#{name}-")) && diff --git a/src/views/funkos.ecr b/src/views/funkos.ecr index 7491e99..62e399b 100644 --- a/src/views/funkos.ecr +++ b/src/views/funkos.ecr @@ -1,13 +1,42 @@ <%- result.each do |f| -%> "> - <%= f["name"] %> - <%= f["scale"] %> - <%= f["containers"] %> - <%= f["images"] %> + + <%= f["name"] %> + " src="bars.svg" class="htmx-indicator"> + + + + + + + + + + <%- f["containers"].as(Array(Docr::Types::ContainerSummary)).each do |c| -%> + + + + + + <%- end -%> + +

+ + +
IDCurrent?Actions
<%= c.@names[0].split("-")[-1] %> + <%- if c.image_id == f["latest_image"] -%> + 🟢 + <%- else -%> + 🟢 + <%- end -%> + + + +
<%- if f["name"] == "proxy" -%> <%- else -%> - <%- if f["scale"].to_i > 0 -%> + <%- if f["scale"].as(String).to_i > 0 -%> <%- else -%> @@ -15,10 +44,7 @@ <%- end -%> - - <%- end -%> - " src="bars.svg" class="htmx-indicator"> <%- end -%>