From baf60a1bf786b523e487d83682746e1ad5ae5d2e Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Tue, 2 Jul 2024 11:27:27 -0300 Subject: [PATCH] More reorg --- .ameba.yml | 6 +++--- Dockerfile | 7 ++++--- public/index.html | 34 ++++++++++++++++++++++++++++++++++ src/daemon/funkos.cr | 26 ++++++++++++++++++++++++++ src/daemon/main.cr | 3 ++- tinyproxy.conf | 19 ++++++++++--------- 6 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 public/index.html create mode 100644 src/daemon/funkos.cr diff --git a/.ameba.yml b/.ameba.yml index 4f52602..1a6a517 100644 --- a/.ameba.yml +++ b/.ameba.yml @@ -1,5 +1,5 @@ # This configuration file was generated by `ameba --gen-config` -# on 2024-07-01 13:11:14 UTC using Ameba version 1.6.1. +# on 2024-07-01 18:57:31 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. @@ -10,9 +10,9 @@ Documentation/DocumentationAdmonition: Timezone: UTC Excluded: - src/faaso.cr - - src/daemon.cr + - src/daemon/main.cr + - src/daemon/secrets.cr - src/funko.cr - - src/daemon-secrets.cr - spec/faaso_spec.cr Admonitions: - TODO diff --git a/Dockerfile b/Dockerfile index 69fe78e..b4f4770 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN addgroup -S app && adduser app -S -G app WORKDIR /home/app COPY shard.yml ./ RUN mkdir src/ -COPY src/* src/ +COPY src/ src/ RUN shards install RUN shards build -d --error-trace RUN strip bin/* @@ -16,8 +16,9 @@ RUN apk add tinyproxy multirun openssl zlib yaml pcre2 gc libevent libgcc libxml RUN addgroup -S app && adduser app -S -G app WORKDIR /home/app -RUN mkdir runtimes -COPY runtimes/* ./runtimes/ +RUN mkdir runtimes public +COPY runtimes/ runtimes/ +COPY public/ public/ COPY tinyproxy.conf ./ COPY --from=build /home/app/bin/faaso-daemon /home/app/bin/faaso /usr/bin/ diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..17433c5 --- /dev/null +++ b/public/index.html @@ -0,0 +1,34 @@ + + + + + + diff --git a/src/daemon/funkos.cr b/src/daemon/funkos.cr new file mode 100644 index 0000000..2bae06f --- /dev/null +++ b/src/daemon/funkos.cr @@ -0,0 +1,26 @@ +require "docr" +require "kemal" + +module Funkos + struct Funko + include JSON::Serializable + property name : String + + def initialize(@name : String) + end + end + + get "/funkos/" do |_| + docker_api = Docr::API.new(Docr::Client.new) + containers = docker_api.containers.list(all: true) + + funkos = [] of Funko + containers.each { |container| + names = container.names.select &.starts_with? "/faaso-" + next if names.empty? + funkos << Funko.new(name: names[0][7..]) + } + funkos.sort! { |a, b| a.name <=> b.name} + funkos.to_json + end +end diff --git a/src/daemon/main.cr b/src/daemon/main.cr index d941212..5e44861 100644 --- a/src/daemon/main.cr +++ b/src/daemon/main.cr @@ -1,5 +1,6 @@ -require "./secrets.cr" +require "./funkos.cr" require "./proxyconf.cr" +require "./secrets.cr" require "compress/gzip" require "crystar" require "docr" diff --git a/tinyproxy.conf b/tinyproxy.conf index b384ca6..ebd7e17 100644 --- a/tinyproxy.conf +++ b/tinyproxy.conf @@ -1,9 +1,10 @@ -UserName nobody -Port 8888 -Listen 0.0.0.0 -Timeout 600 -Allow 0.0.0.0/0 -ReverseOnly Yes -ReverseMagic Yes -ReversePath "/admin/" "http://127.0.0.1:3000/" -ReversePath "/faaso/hello/" "http://hello:3000/" \ No newline at end of file + + UserName nobody + Port 8888 + Listen 0.0.0.0 + Timeout 600 + Allow 0.0.0.0/0 + ReverseOnly Yes + ReverseMagic Yes + ReversePath "/admin/" "http://127.0.0.1:3000/" + ReversePath "/faaso/hello/" "http://hello:3000/" \ No newline at end of file