diff --git a/.gitignore b/.gitignore index 1866d50..c1b92e1 100644 --- a/.gitignore +++ b/.gitignore @@ -35,5 +35,5 @@ chronoscope-*.tar npm-debug.log /assets/node_modules/ -# IDE files +# Ignore IDE files. .elixir_ls/ diff --git a/lib/chronoscope/application.ex b/lib/chronoscope/application.ex index dbf3c4e..735d1ac 100644 --- a/lib/chronoscope/application.ex +++ b/lib/chronoscope/application.ex @@ -15,9 +15,10 @@ defmodule Chronoscope.Application do {Finch, name: Chronoscope.Finch}, # Start a worker by calling: Chronoscope.Worker.start_link(arg) # {Chronoscope.Worker, arg}, + {Task.Supervisor, name: Chronoscope.TaskSupervisor}, + Chronoscope.NTS.Client, # Start to serve requests, typically the last entry - ChronoscopeWeb.Endpoint, - Chronoscope.NTS.Client + ChronoscopeWeb.Endpoint ] # See https://hexdocs.pm/elixir/Supervisor.html diff --git a/lib/chronoscope/nts.ex b/lib/chronoscope/nts.ex index 8805987..02796bb 100644 --- a/lib/chronoscope/nts.ex +++ b/lib/chronoscope/nts.ex @@ -18,6 +18,6 @@ defmodule Chronoscope.NTS do end def key_establishment(host, port) do - GenServer.call(Client, {:key_establishment, %{host: host, port: port}}) + GenServer.call(Client, {:key_establishment, %{host: host, port: port}}, 10_000) end end diff --git a/lib/chronoscope/nts/client.ex b/lib/chronoscope/nts/client.ex index db3eda4..cad443e 100644 --- a/lib/chronoscope/nts/client.ex +++ b/lib/chronoscope/nts/client.ex @@ -68,8 +68,13 @@ defmodule Chronoscope.NTS.Client do end defp current_data(server, now) do + response = + Chronoscope.TaskSupervisor + |> Task.Supervisor.async(fn -> KeyEstablishmentClient.key_establishment(server) end) + |> Task.await(10_000) + %{ - key_establishment_response: KeyEstablishmentClient.key_establishment(server), + key_establishment_response: response, last_key_establishment: now } end diff --git a/lib/mix/tasks/deploy.ex b/lib/mix/tasks/deploy.ex new file mode 100644 index 0000000..392da48 --- /dev/null +++ b/lib/mix/tasks/deploy.ex @@ -0,0 +1,32 @@ +defmodule Mix.Tasks.Deploy do + use Mix.Task + + @moduledoc """ + Deploy this application to production. + """ + + @shortdoc "deploy to production" + + @spec run([...]) :: any + def run([host]) do + System.cmd( + "rsync", + [ + "--archive", + "--delete", + "--compress", + "--human-readable", + "--progress", + "--stats", + "--verbose", + "--exclude-from=.gitignore", + "--exclude=.git/", + "./", + "#{host}:chronoscope/" + ], + into: IO.stream() + ) + + System.cmd("ssh", [host, "cd chronoscope && buildah build -t chronoscope:latest && podman auto-update"], into: IO.stream()) + end +end