Packages

Elixir library to manage automatic docker-compose redeployments for new docker images

Current section

6 Versions

Jump to

Compare versions

5 files changed
+51 additions
-7 deletions
  @@ -6,7 +6,8 @@
6 6 {<<"files">>,
7 7 [<<"lib/ex_factory.ex">>,<<"lib/mix/docker/compose/deploy_containers.ex">>,
8 8 <<"lib/mix/docker/compose/pull_new_images.ex">>,
9 - <<"lib/mix/docker/compose/stop_containers.ex">>,<<"lib/util/cmd.ex">>,
9 + <<"lib/mix/docker/compose/stop_containers.ex">>,
10 + <<"lib/mix/install_on_debian.ex">>,<<"lib/util/cmd.ex">>,
10 11 <<"lib/web/action_plug/redeploy.ex">>,<<"lib/web/authorization.ex">>,
11 12 <<"lib/web/router.ex">>,<<"mix.exs">>]}.
12 13 {<<"licenses">>,[<<"MIT">>]}.
  @@ -21,5 +22,9 @@
21 22 [{<<"app">>,<<"plug">>},
22 23 {<<"name">>,<<"plug">>},
23 24 {<<"optional">>,false},
24 - {<<"requirement">>,<<"~> 1.0">>}]]}.
25 - {<<"version">>,<<"0.1.0">>}.
25 + {<<"requirement">>,<<"~> 1.0">>}],
26 + [{<<"app">>,<<"distillery">>},
27 + {<<"name">>,<<"distillery">>},
28 + {<<"optional">>,false},
29 + {<<"requirement">>,<<"~> 1.5">>}]]}.
30 + {<<"version">>,<<"0.1.1">>}.
  @@ -7,7 +7,7 @@ defmodule Mix.Tasks.Docker.Compose.StopContainers do
7 7 """
8 8 def run(_) do
9 9 command = "docker-compose"
10 - args = ["pull"]
10 + args = ["down"]
11 11 exec(command, args)
12 12 end
13 13 end
  @@ -0,0 +1,37 @@
1 + defmodule Mix.Tasks.InstallOnDebian do
2 + use Mix.Task
3 +
4 + @service_name "ex_factory"
5 + @service_file "/lib/systemd/system/#{@service_name}.service"
6 + @service_content """
7 + [Unit]
8 + Description=Daemon to manage automatic docker-compose redeployments for the new image releases
9 +
10 + [Service]
11 + Type=simple
12 + Restart=on-failure
13 + Environment=MIX_ENV=prod
14 + Environment=LANG=en_US.UTF-8
15 +
16 + WorkingDirectory=#{System.cwd()}
17 + ExecStart=/usr/local/bin/mix run --no-halt
18 +
19 + [Install]
20 + WantedBy=multi-user.target
21 + """ |> String.trim()
22 +
23 + @doc """
24 + Install as Debian service.
25 + """
26 + def run(service_file) when is_bitstring(service_file) do
27 + unless File.exists?(service_file) do
28 + IO.inspect(service_file)
29 + File.write(service_file, @service_content)
30 + IO.puts("Service was successfully installed, start with `sudo systemctl restart ex_factory.service`, enable (safe from reboots) with `systemctl enable ex_factory.service`")
31 + else
32 + IO.puts("Service have been already installed as #{@service_name}")
33 + :ok
34 + end
35 + end
36 + def run(_), do: run(@service_file)
37 + end
\ No newline at end of file
  @@ -10,7 +10,8 @@ defmodule ExFactory.Util.Cmd do
10 10 """
11 11 @spec exec(String.t, [String.t]) :: generic_response
12 12 def exec(command, args) do
13 - case System.cmd(command, args, stderr_to_stdout: true) do
13 + workdir = System.get_env("EX_FACTORY_WORKDIR") || System.cwd()
14 + case System.cmd(command, args, stderr_to_stdout: true, cd: workdir) do
14 15 {_, 0} ->
15 16 :ok
16 17 {error_message, _exit_code} ->
  @@ -4,7 +4,7 @@ defmodule ExFactory.Mixfile do
4 4 def project do
5 5 [
6 6 app: :ex_factory,
7 - version: "0.1.0",
7 + version: "0.1.1",
8 8 elixir: "~> 1.5",
9 9 description: "Elixir library to manage automatic docker-compose redeployments for new docker images",
10 10 docs: [extras: ["README.md"]],
  @@ -44,7 +44,8 @@ defmodule ExFactory.Mixfile do
44 44 [
45 45 {:cowboy, "~> 1.0"},
46 46 {:plug, "~> 1.0"},
47 - {:ex_doc, ">= 0.0.0", only: :dev}
47 + {:ex_doc, ">= 0.0.0", only: :dev},
48 + {:distillery, "~> 1.5", runtime: false}
48 49 ]
49 50 end