Compare commits
No commits in common. "a4f722a1e08d2f483727472388afc23c9840172e" and "b3a465f5d8edd93f0620a333f26b002f553bfd17" have entirely different histories.
a4f722a1e0
...
b3a465f5d8
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,4 +4,3 @@
|
|||||||
*.dwarf
|
*.dwarf
|
||||||
tmp/
|
tmp/
|
||||||
export/
|
export/
|
||||||
secrets/
|
|
||||||
|
@ -16,7 +16,7 @@ RUN addgroup -S app && adduser app -S -G app
|
|||||||
WORKDIR /home/app
|
WORKDIR /home/app
|
||||||
USER app
|
USER app
|
||||||
|
|
||||||
COPY --from=build /home/app/bin/funko .
|
COPY --from=build /home/app/bin/function .
|
||||||
|
|
||||||
CMD ["./funko"]
|
CMD ["./function"]
|
||||||
HEALTHCHECK {{ healthcheck_options }} CMD {{ healthcheck_command }}
|
HEALTHCHECK {{ healthcheck_options }} CMD {{ healthcheck_command }}
|
@ -2,7 +2,7 @@ name: function
|
|||||||
version: 0.1.0
|
version: 0.1.0
|
||||||
|
|
||||||
targets:
|
targets:
|
||||||
funko:
|
function:
|
||||||
main: main.cr
|
main: main.cr
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
require "docr"
|
require "docr"
|
||||||
require "kemal"
|
require "kemal"
|
||||||
require "../funko.cr"
|
|
||||||
|
|
||||||
module Funkos
|
module Funkos
|
||||||
get "/funkos/" do |env|
|
struct Funko
|
||||||
funkos : Array(Funko) = Funko.from_docker
|
include JSON::Serializable
|
||||||
|
property name : String
|
||||||
|
|
||||||
|
def initialize(@name : String)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/funkos/" do |env|
|
||||||
|
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.sort! { |a, b| a.name <=> b.name }
|
||||||
|
|
||||||
if env.params.query.fetch("format", "json") == "html"
|
if env.params.query.fetch("format", "json") == "html"
|
||||||
|
30
src/funko.cr
30
src/funko.cr
@ -36,16 +36,6 @@ class Funko
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(json : JSON::Builder)
|
|
||||||
json.object do
|
|
||||||
json.field("name", name)
|
|
||||||
json.field("ship_packages", ship_packages)
|
|
||||||
json.field("devel_packages", devel_packages)
|
|
||||||
json.field("healthcheck_options", healthcheck_options)
|
|
||||||
json.field("healthcheck_command", healthcheck_command)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Create an Array of funkos from an Array of folders containing definitions
|
# Create an Array of funkos from an Array of folders containing definitions
|
||||||
def self.from_paths(paths : Array(String | Path)) : Array(Funko)
|
def self.from_paths(paths : Array(String | Path)) : Array(Funko)
|
||||||
paths.map { |path| Path.new(path, "funko.yml") }
|
paths.map { |path| Path.new(path, "funko.yml") }
|
||||||
@ -65,20 +55,6 @@ class Funko
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get all the funkos docker knows about.
|
|
||||||
def self.from_docker : Array(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?
|
|
||||||
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
|
|
||||||
|
|
||||||
# Setup the target directory `path` with all the files needed
|
# Setup the target directory `path` with all the files needed
|
||||||
# to build a docker image
|
# to build a docker image
|
||||||
def prepare_build(path : Path)
|
def prepare_build(path : Path)
|
||||||
@ -112,7 +88,7 @@ class Funko
|
|||||||
docker_api = Docr::API.new(Docr::Client.new)
|
docker_api = Docr::API.new(Docr::Client.new)
|
||||||
docker_api.images.build(
|
docker_api.images.build(
|
||||||
context: path.to_s,
|
context: path.to_s,
|
||||||
tags: ["faaso-#{name}:latest"]) { |x| Log.info { x } }
|
tags: ["#{name}:latest"]) { |x| Log.info { x } }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return a list of image IDs for this funko, most recent first
|
# Return a list of image IDs for this funko, most recent first
|
||||||
@ -120,7 +96,7 @@ class Funko
|
|||||||
docker_api = Docr::API.new(Docr::Client.new)
|
docker_api = Docr::API.new(Docr::Client.new)
|
||||||
begin
|
begin
|
||||||
docker_api.images.history(
|
docker_api.images.history(
|
||||||
name: "faaso-#{name}"
|
name: name
|
||||||
).sort { |i, j| j.@created <=> i.@created }.map(&.@id)
|
).sort { |i, j| j.@created <=> i.@created }.map(&.@id)
|
||||||
rescue ex : Docr::Errors::DockerAPIError
|
rescue ex : Docr::Errors::DockerAPIError
|
||||||
Log.error { "#{ex}" }
|
Log.error { "#{ex}" }
|
||||||
@ -188,7 +164,7 @@ class Funko
|
|||||||
secrets_mount = "#{Dir.current}/secrets/#{name}"
|
secrets_mount = "#{Dir.current}/secrets/#{name}"
|
||||||
Dir.mkdir_p(secrets_mount)
|
Dir.mkdir_p(secrets_mount)
|
||||||
conf = Docr::Types::CreateContainerConfig.new(
|
conf = Docr::Types::CreateContainerConfig.new(
|
||||||
image: "faaso-#{name}:latest",
|
image: "#{name}:latest",
|
||||||
hostname: name,
|
hostname: name,
|
||||||
# Port in the container side
|
# Port in the container side
|
||||||
host_config: Docr::Types::HostConfig.new(
|
host_config: Docr::Types::HostConfig.new(
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
<%- funkos.each do |funko| -%>
|
<%- funkos.each do |funko| -%>
|
||||||
<tr>
|
|
||||||
<td><%= funko.name %></td>
|
<td><%= funko.name %></td>
|
||||||
<td>sarasa</td>
|
<td>sarasa</td>
|
||||||
<td><button>DOSTUFF</button></td>
|
<td><button>DOSTUFF</button></td>
|
||||||
</tr>
|
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
|
Loading…
Reference in New Issue
Block a user