Skip to content
This repository was archived by the owner on May 9, 2021. It is now read-only.

Commit a2fa95f

Browse files
committed
Deploy container with env, autodoc
1 parent e6f5050 commit a2fa95f

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

lib/agma/application.ex

+9-13
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ defmodule Agma.Application do
44
use Application
55

66
def start(_type, _args) do
7-
dsn =
8-
:agma
9-
|> Application.get_env(:singyeong_dsn)
10-
|> Singyeong.parse_dsn
7+
dsn = Application.get_env :agma, :singyeong_dsn
118

12-
children = [
13-
AgmaWeb.Telemetry,
14-
{Phoenix.PubSub, name: Agma.PubSub},
15-
AgmaWeb.Endpoint,
16-
{Singyeong.Client, dsn},
17-
Singyeong.Producer,
18-
Agma.Consumer,
19-
Agma.Stats,
20-
]
9+
children =
10+
[
11+
AgmaWeb.Telemetry,
12+
{Phoenix.PubSub, name: Agma.PubSub},
13+
AgmaWeb.Endpoint,
14+
]
15+
++ Mahou.Singyeong.child_specs(dsn, Agma.Consumer)
16+
++ [Agma.Stats]
2117

2218
opts = [strategy: :one_for_one, name: Agma.Supervisor]
2319
Supervisor.start_link(children, opts)

lib/agma/consumer.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ defmodule Agma.Consumer do
4242
Logger.info "deploy: apps: #{Enum.count apps} total"
4343
for app <- apps do
4444
name = Docker.app_name app
45-
Docker.create app.image, name, %{Labels.namespace() => app.namespace}
45+
Docker.create app.image, name, %{Labels.namespace() => app.namespace}, app.env
4646
Logger.info "deploy: app: created #{name}"
4747
end
4848
for app <- apps do

lib/agma/docker.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Agma.Docker do
3434
@doc """
3535
Create a new
3636
"""
37-
def create(image, name, labels, command \\ nil) do
37+
def create(image, name, labels, env, command \\ nil) do
3838
# TODO: Error-check image names
3939
if not String.match?(name, ~r/^\/?[a-zA-Z0-9][a-zA-Z0-9_.-]+$/) do
4040
{:error, :invalid_name}
@@ -46,6 +46,7 @@ defmodule Agma.Docker do
4646
"HostConfig" => %{
4747
"AutoRemove" => true,
4848
},
49+
"Env": Enum.map(env, fn {k, v} -> "#{k}=#{v}" end)
4950
}
5051

5152
opts = if command, do: Map.put(opts, "Cmd", command), else: opts

lib/agma/stats.ex

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
defmodule Agma.Stats do
22
use GenServer
33
alias Agma.Docker
4+
alias Mahou.Docs
5+
alias Mahou.Message.{ChangeContainerStatus, CreateContainer}
46
require Logger
57

68
def start_link(opts) do
79
GenServer.start_link __MODULE__, opts, name: __MODULE__
810
end
911

10-
def init(opts) do
12+
def init(_) do
1113
Logger.info "[STATS] I'm mangling #{length Docker.managed_container_ids()} containers at boot."
1214
tick()
13-
{:ok, opts}
15+
docs =
16+
Docs.docs_metadata [
17+
input_messages: [ChangeContainerStatus, CreateContainer],
18+
output_messages: [],
19+
phx_routers: [AgmaWeb.Router]
20+
]
21+
22+
{:ok, %{docs: docs}}
1423
end
1524

1625
def handle_info(:tick, state) do
@@ -23,7 +32,7 @@ defmodule Agma.Stats do
2332
free_memory: mem_free,
2433
} = Map.new :memsup.get_system_memory_data()
2534

26-
Singyeong.Client.update_metadata %{
35+
%{
2736
cpu_count: %{
2837
type: "integer",
2938
value: cpus,
@@ -67,8 +76,12 @@ defmodule Agma.Stats do
6776
container_count: %{
6877
type: "integer",
6978
value: Enum.count(Docker.managed_container_ids()),
70-
}
79+
},
7180
}
81+
|> Map.merge(%{
82+
Docs.docs_key() => state.docs,
83+
})
84+
|> Singyeong.Client.update_metadata
7285
tick()
7386
{:noreply, state}
7487
end

mix.exs

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,12 @@ defmodule Agma.MixProject do
3838
{:telemetry_poller, "~> 0.4"},
3939
{:jason, "~> 1.0"},
4040
{:plug_cowboy, "~> 2.0"},
41-
{:singyeong, "~> 0.4.0"},
4241
# gun 1.3.3 needs a lower version :pensive:
4342
{:cowlib, "~> 2.9.0", override: true},
4443
{:tesla, "~> 1.4"},
4544
{:castore, "~> 0.1"},
4645
{:typed_struct, "~> 0.2.1"},
47-
{:libmahou, git: "[email protected]:queer/libmahou.git"},
46+
{:mahou, git: "[email protected]:queer/libmahou.git"},
4847
]
4948
end
5049

mix.lock

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
%{
2+
"annotatable": {:hex, :annotatable, "0.1.2", "29103613c986d7f56a80635a4548fa54a9c1011e4c419f4dbc8607f1c4bd3e9f", [:mix], [], "hexpm", "908ce0150bea70dbf201b57b62ea00a1134018265b1a13a20a59fb9f45c3a416"},
23
"castore": {:hex, :castore, "0.1.9", "eb08a94c12ebff92a92d844c6ccd90728dc7662aab9bdc8b3b785ba653c499d5", [:mix], [], "hexpm", "99c3a38ad9c0bab03fee1418c98390da1a31f3b85e317db5840d51a1443d26c8"},
34
"certifi": {:hex, :certifi, "2.5.3", "70bdd7e7188c804f3a30ee0e7c99655bc35d8ac41c23e12325f36ab449b70651", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "ed516acb3929b101208a9d700062d520f3953da3b6b918d866106ffa980e1c10"},
45
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
56
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.3.1", "ebd1a1d7aff97f27c66654e78ece187abdc646992714164380d8a041eda16754", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "3a6efd3366130eab84ca372cbd4a7d3c3a97bdfcfb4911233b035d117063f0af"},
67
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
8+
"ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"},
9+
"gen_json_schema": {:hex, :gen_json_schema, "0.1.0", "d6fe453c26b11d5938593a0b3040e86fdc1ff37f443fea620a6c08f675f538c5", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "abd940a8c6f4af66efa3299f09ff36e831e1f122278cc7fcbba9a562e76daa83"},
710
"gen_stage": {:hex, :gen_stage, "1.0.0", "51c8ae56ff54f9a2a604ca583798c210ad245f415115453b773b621c49776df5", [:mix], [], "hexpm", "1d9fc978db5305ac54e6f5fec7adf80cd893b1000cf78271564c516aa2af7706"},
811
"gun": {:hex, :gun, "1.3.3", "cf8b51beb36c22b9c8df1921e3f2bc4d2b1f68b49ad4fbc64e91875aa14e16b4", [:rebar3], [{:cowlib, "~> 2.7.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "3106ce167f9c9723f849e4fb54ea4a4d814e3996ae243a1c828b256e749041e0"},
912
"hackney": {:hex, :hackney, "1.17.0", "717ea195fd2f898d9fe9f1ce0afcc2621a41ecfe137fae57e7fe6e9484b9aa99", [:rebar3], [{:certifi, "~>2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "64c22225f1ea8855f584720c0e5b3cd14095703af1c9fbc845ba042811dc671c"},
1013
"httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"},
1114
"idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"},
1215
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
1316
"lens": {:hex, :lens, "1.0.0", "bad01a2ff90ce0e13ce486ed1750c92c06d96d271368e56771fe68d0415d4877", [:mix], [], "hexpm", "581349c3e42181696f71ead8b016cc548715eb125c41d003297dd1a670e46f21"},
14-
"libmahou": {:git, "[email protected]:queer/libmahou.git", "381e227ca723602c80d4c0e813383cedb5b55c0b", []},
17+
"libmahou": {:git, "[email protected]:queer/libmahou.git", "a2d531b0015c869981fd2493b81b24d55adb580c", []},
18+
"mahou": {:git, "[email protected]:queer/libmahou.git", "e93e278a0cd16b466a0c0cbb2bd73b32340466bf", []},
1519
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
1620
"mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"},
1721
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
@@ -23,7 +27,7 @@
2327
"plug_cowboy": {:hex, :plug_cowboy, "2.4.1", "779ba386c0915027f22e14a48919a9545714f849505fa15af2631a0d298abf0f", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d72113b6dff7b37a7d9b2a5b68892808e3a9a752f2bf7e503240945385b70507"},
2428
"plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"},
2529
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
26-
"singyeong": {:hex, :singyeong, "0.4.2", "bf21239f6d5e837ee7216ac062278a9231073b50b5dce59e8c94fa349ca0e9e0", [:mix], [{:gen_stage, "~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.7", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.2.1", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "490dd09bce877b4cecb28479b748d47a220214d494bf07714e2cb520e4f42506"},
30+
"singyeong": {:hex, :singyeong, "0.4.4", "8e0a04fb724b95e23e6b562b89f246ad916ceaeb57953489a85f4ef0ce571c41", [:mix], [{:gen_stage, "~> 1.0", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.7", [hex: :httpoison, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.2.1", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "b81ece7bc1e028d5f5b74be45897ca4abb783a506ecd64e8644f6f8cd944f19e"},
2731
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
2832
"telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"},
2933
"telemetry_metrics": {:hex, :telemetry_metrics, "0.6.0", "da9d49ee7e6bb1c259d36ce6539cd45ae14d81247a2b0c90edf55e2b50507f7b", [:mix], [{:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5cfe67ad464b243835512aa44321cee91faed6ea868d7fb761d7016e02915c3d"},

0 commit comments

Comments
 (0)