diff --git a/Makefile b/Makefile index b464ecd..91ff75f 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/daemon/funkos.cr b/src/daemon/funkos.cr index d99855b..45674f5 100644 --- a/src/daemon/funkos.cr +++ b/src/daemon/funkos.cr @@ -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 diff --git a/src/funko.cr b/src/funko.cr index 34f6b20..2fe9537 100644 --- a/src/funko.cr +++ b/src/funko.cr @@ -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 diff --git a/src/views/funkos.ecr b/src/views/funkos.ecr index c6dcd68..b108734 100644 --- a/src/views/funkos.ecr +++ b/src/views/funkos.ecr @@ -1,7 +1,26 @@ -<%- funkos.each do |funko| -%> +<%- result.each do |f| -%>