Some more frontend

This commit is contained in:
Roberto Alsina 2024-07-02 17:39:18 -03:00
parent a4f722a1e0
commit 227c770b61
4 changed files with 45 additions and 10 deletions

View File

@ -3,7 +3,7 @@ build: shard.yml $(wildcard src/**/*cr)
proxy: build
docker build . -t faaso-proxy --no-cache
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

View File

@ -4,14 +4,31 @@ require "../funko.cr"
module Funkos
get "/funkos/" do |env|
funkos : Array(Funko) = Funko.from_docker
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,
}
end
if env.params.query.fetch("format", "json") == "html"
render "src/views/funkos.ecr"
else
funkos.to_json
result.to_json
end
end
end

View File

@ -70,12 +70,11 @@ class Funko
docker_api = Docr::API.new(Docr::Client.new)
names = Set(String).new
docker_api.images.list(all: true).select { |i|
next if i.@repo_tags.nil?
next if i.@repo_tags.nil?
i.@repo_tags.as(Array(String)).each { |tag|
names << tag.split(":", 2)[0].split("-", 2)[1] if tag.starts_with?("faaso-")
}
}
pp! names
from_names(names.to_a)
end

View File

@ -1,7 +1,26 @@
<%- funkos.each do |funko| -%>
<%- result.each do |f| -%>
<tr>
<td><%= funko.name %></td>
<td>sarasa</td>
<td><button>DOSTUFF</button></td>
<td><%= f["name"] %></td>
<td><%= f["state"] %></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>
<%- end -%>