From 91466db97e256179bf3c19d82098e5e5c500cd4e Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 2 Jul 2024 19:37:08 -0300 Subject: [PATCH] Better detection of possible funkos --- .ameba.yml | 7 ++++--- src/funko.cr | 17 ++++++++++++----- src/views/funkos.ecr | 43 +++++++++++++++++++++++++------------------ 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/.ameba.yml b/.ameba.yml index 32237db..d514865 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -1,15 +1,16 @@ # This configuration file was generated by `ameba --gen-config` -# on 2024-07-02 16:33:24 UTC using Ameba version 1.6.1. +# on 2024-07-02 22:36:34 UTC using Ameba version 1.6.1. # The point is for the user to remove these configuration records # one by one as the reported problems are removed from the code base. -# Problems found: 11 +# Problems found: 12 # Run `ameba --only Documentation/DocumentationAdmonition` for details Documentation/DocumentationAdmonition: Description: Reports documentation admonitions Timezone: UTC Excluded: - src/faaso.cr + - src/secrets.cr - src/daemon/main.cr - src/daemon/secrets.cr - src/funko.cr @@ -29,7 +30,7 @@ Naming/BlockParameterName: AllowNamesEndingInNumbers: true Excluded: - src/faaso.cr - - src/daemon/funkos.cr + - src/daemon/funko.cr AllowedNames: - _ - e diff --git a/src/funko.cr b/src/funko.cr index 8519851..75ef3ca 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -72,18 +72,25 @@ module Funko def self.from_docker : Array(Funko) docker_api = Docr::API.new(Docr::Client.new) names = [] of String - funko_containers = docker_api.containers.list( + + # Get all containers that look like funkos + docker_api.containers.list( all: true, ).each { |container| - p! container.@names container.@names.each { |name| names << name.split("-", 2)[1].lstrip("/") if name.starts_with?("/faaso-") } } - pp! names - - from_names(names.to_a.sort!) + # Now get all images that look like funkos, since + # we can start them just fine. + docker_api.images.list.each { |image| + next if image.@repo_tags.nil? + image.@repo_tags.as(Array(String)).each { |tag| + names << tag.split("-", 2)[1].split(":", 2)[0] if tag.starts_with?("faaso-") + } + } + from_names(names.to_set.to_a.sort!) end # Setup the target directory `path` with all the files needed diff --git a/src/views/funkos.ecr b/src/views/funkos.ecr index 0e102e3..dcf51e2 100644 --- a/src/views/funkos.ecr +++ b/src/views/funkos.ecr @@ -1,25 +1,32 @@ <%- result.each do |f| -%> <%= f["name"] %> - <%= f["status"] %> + <%- if f["name"] == "proxy" -%> + Running + <%- else -%> + <%= f["status"] %> + <%- end -%> - <%- if f["state"] == "running" -%> - - - - - <%- end -%> - <%- if f["state"] == "paused" -%> - - - - - <%- end -%> - <%- if f["state"] == "stopped" -%> - - - - + <%- if f["name"] == "proxy" -%> + <%- else -%> + <%- if f["state"] == "running" -%> + + + + + <%- end -%> + <%- if f["state"] == "paused" -%> + + + + + <%- end -%> + <%- if f["state"] == "stopped" -%> + + + + + <%- end -%> <%- end -%>