Akd v0.3.0 Akd.DeployHelper View Source

This module defines helper functions used to initialize, add hooks to, and execute a deployment.

Link to this section Summary

Functions

Adds a hook or hooks to deployment struct's hooks and returns the updated Deployment.t

Executes a Deployment. If there's a failure, it executes rollbacks/1 for all the called_hooks

This macro executes a pipeline (set of operations) defined in the current module with a set of params that can be used to initialize a Deployment struct

Initializes a Akd.Deployment struct with given params and sanitizes it

Link to this section Functions

Adds a hook or hooks to deployment struct's hooks and returns the updated Deployment.t

This function takes in a Deployment and hook variable.

hook variable can be an Akd.Hook.t struct or a tuple (with one element specifying type of hook/module and other opts)

Examples

When a deployment and a Hook.t is given.

iex> deployment = %Akd.Deployment{mix_env: "prod",
...> build_at: Akd.Destination.local("."),
...> publish_to: Akd.Destination.local("."),
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.add_hook(deployment, %Akd.Hook{})
%Akd.Deployment{build_at: %Akd.Destination{host: :local, path: ".",
      user: :current},
     hooks: [%Akd.Hook{ensure: [], ignore_failure: false, main: [],
     rollback: [], run_ensure: true}], mix_env: "prod", name: "name",
     publish_to: %Akd.Destination{host: :local, path: ".",
                  user: :current}, vsn: "0.1.1"}

When a deployment and a tuple is given, and the first element of tuple is a Hook.t

iex> deployment = %Akd.Deployment{mix_env: "prod",
...> build_at: Akd.Destination.local("."),
...> publish_to: Akd.Destination.local("."),
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.add_hook(deployment, {%Akd.Hook{}, []})
%Akd.Deployment{build_at: %Akd.Destination{host: :local, path: ".",
      user: :current},
     hooks: [%Akd.Hook{ensure: [], ignore_failure: false, main: [],
     rollback: [], run_ensure: true}], mix_env: "prod", name: "name",
     publish_to: %Akd.Destination{host: :local, path: ".",
                  user: :current}, vsn: "0.1.1"}

When a deployment and a tuple is given, and the first element of tuple is a Hook Module

iex> deployment = %Akd.Deployment{mix_env: "prod",
...> build_at: Akd.Destination.local("."),
...> publish_to: Akd.Destination.local("."),
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.add_hook(deployment, {Akd.Init.Release, []})
%Akd.Deployment{build_at: %Akd.Destination{host: :local, path: ".",
    user: :current},
   hooks: [%Akd.Hook{ensure: [
      %Akd.Operation{cmd: "rm -rf _build/prod", cmd_envs: [],
       destination: %Akd.Destination{host: :local, path: ".",
      user: :current}}], ignore_failure: false,
      main: [%Akd.Operation{cmd: "mix deps.get \n mix compile",
      cmd_envs: [{"MIX_ENV", "prod"}],
      destination: %Akd.Destination{host: :local, path: ".",
             user: :current}}], rollback: [], run_ensure: true}],
                      mix_env: "prod", name: "name",
                      publish_to: %Akd.Destination{host: :local, path: ".",
                                   user: :current}, vsn: "0.1.1"}

Executes a Deployment. If there's a failure, it executes rollbacks/1 for all the called_hooks.

Executes ensure/1 for all the called_hooks

Returns true if the deployment was executed successfully; otherwise, it returns false.

Examples

iex> deployment = %Akd.Deployment{mix_env: "prod",
...> build_at: Akd.Destination.local("."),
...> publish_to: Akd.Destination.local("."),
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.exec(deployment)
true
Link to this macro

execute(pipeline, list) View Source (macro)

This macro executes a pipeline (set of operations) defined in the current module with a set of params that can be used to initialize a Deployment struct.

Returns true if the deployment initialized was executed successfully; otherwise, it returns false.

Examples

iex> defmodule TestAkdDeployHelperExecute do
...>   import Akd.DeployHelper
...>   def pip(), do: []
...>   def run() do
...>     execute :pip, with: %{name: "node", build_at: {:local, "."},
...>       mix_env: "prod", publish_to: "user@host:~/path/to/dir", vsn: "0.1.0"}
...>   end
...> end
iex> TestAkdDeployHelperExecute.run()
true

Initializes a Akd.Deployment struct with given params and sanitizes it.

Examples

When no hooks are given:

iex> params = %{mix_env: "prod",
...> build_at: Akd.Destination.local("."),
...> publish_to: Akd.Destination.local("."),
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.init_deployment(params)
%Akd.Deployment{build_at: %Akd.Destination{host: :local, path: ".",
    user: :current}, hooks: [], mix_env: "prod", name: "name",
     publish_to: %Akd.Destination{host: :local, path: ".",
            user: :current}, vsn: "0.1.1"}

When hooks are given:

iex> params = %{mix_env: "prod",
...> build_at: Akd.Destination.local("."),
...> publish_to: Akd.Destination.local("."),
...> name: "name",
...> vsn: "0.1.1", hooks: [%Akd.Hook{}]}
iex> Akd.DeployHelper.init_deployment(params)
%Akd.Deployment{build_at: %Akd.Destination{host: :local, path: ".",
  user: :current}, hooks: [%Akd.Hook{}], mix_env: "prod", name: "name",
     publish_to: %Akd.Destination{host: :local, path: ".",
            user: :current}, vsn: "0.1.1"}

When build_at and publish_to are strings in the form: user@host:path

iex> params = %{mix_env: "prod",
...> build_at: "root@host:~/path",
...> publish_to: "root@host:~/path",
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.init_deployment(params)
%Akd.Deployment{build_at: %Akd.Destination{host: "host",
  path: "~/path", user: "root"}, hooks: [], mix_env: "prod",
  name: "name",
  publish_to: %Akd.Destination{host: "host", path: "~/path",
  user: "root"}, vsn: "0.1.1"}

When build_at and publish_to are strings, not in the form: user@host:path

iex> params = %{mix_env: "prod",
...> build_at: "some-random-string",
...> publish_to: "some-random-string",
...> name: "name",
...> vsn: "0.1.1"}
iex> Akd.DeployHelper.init_deployment(params)
** (MatchError) no match of right hand side value: ["some-random-string"]