Akd v0.2.0-rc.0 Akd.Dsl.FormHook View Source

Defines a Hook.

This modules provides a DSL to define hooks Akd.Hook.t structs in a readable and organized manner.

This module provides a set of macros for generating hooks using operations specified by main, ensure and rollback macros.

Form Hook and Operations

Once form_hook is called, it is goes through all the operations defined inside the do - end block, using main, ensure and rollback macros, with their specific options. Once the block ends, it resolves all those operations into a Akd.Hook.t struct and returns that.

Once this hook is defined it can be used in a pipeline or a Akd.Hook module that returns a hook

For Example:

Use within an Akd.Hook module

defmodule DeployApp.CustomHook.Hook do
  use Akd.Hook

  def get_hooks(deployment, opts // []) do
    my_hook = form_hook opts do
      main "run this", deployment.build_at
      main "run this too", deployment.publish_to

      ensure "ensure this command runs", deployment.build_at

      rollback "call this only if the hook fails", deployment.publish_to
    end

    [my_hook]
  end
end

Please refer to Nomenclature for more information about the terms used.

Link to this section Summary

Functions

Adds an operation to the ensure category of a hook

Adds an operation to the ensure category of a hook

Forms a hook with a given block. This is the entry point to this DSL

Forms a hook with a given block. This is the entry point to this DSL

Gets list of operations from the Agent that keeps track of operations while using the FormHook DSL

Adds an operation to the main category of a hook

Adds an operation to the main category of a hook

This adds an operation to the Agent that keeps track of operations while using the FormHook DSL

Adds an operation to the rollback category of a hook

Adds an operation to the rollback category of a hook

This starts an Agent that keeps track of added operations while using the FormHook DSL

This stops the Agent that keeps track of added operations while using the FormHook DSL

Converts a list of operations with options to an Akd.Hook.t struct

Link to this section Functions

Link to this macro ensure(cmd, dest) View Source (macro)

Adds an operation to the ensure category of a hook

These commands are the commands that are ran after all the hooks are executed. Think of these commands as cleanup commands

Same as ensure/2 but without cmd_env

Examples

ensure “echo $GREET”, Akd.Destination.local()

Link to this macro ensure(cmd, dest, list) View Source (macro)

Adds an operation to the ensure category of a hook

These commands are the commands that are ran after all the hooks are executed. Think of these commands as cleanup commands

Takes a set of cmd_env, which is a list of tuples which represent the environment (system) variables that will be given before the operation is executed.

Examples

ensure “echo $GREET”, Akd.Destination.local(), cmd_env: [{“GREET”, “hello”}]

Link to this macro form_hook(list) View Source (macro)

Forms a hook with a given block. This is the entry point to this DSL.

Same as form_hook/2 but without opts

Examples

form_hook do

main "echo hello", Akd.Destination.local()

end

iex> import Akd.Dsl.FormHook
iex> form_hook do
...> main "echo hello", Akd.Destination.local()
...> main "run this cmd", Akd.Destination.local()
...> ensure "run this too", Akd.Destination.local()
...> rollback "roll this back", Akd.Destination.local()
...> end
%Akd.Hook{ensure: [%Akd.Operation{cmd: "run this too", cmd_envs: [],
         destination: %Akd.Destination{host: :local, path: ".",
          user: :current}}], ignore_failure: false,
     main: [%Akd.Operation{cmd: "echo hello", cmd_envs: [],
                   destination: %Akd.Destination{host: :local, path: ".",
                                  user: :current}},
                  %Akd.Operation{cmd: "run this cmd", cmd_envs: [],
            destination: %Akd.Destination{host: :local, path: ".",
                           user: :current}}],
     rollback: [%Akd.Operation{cmd: "roll this back", cmd_envs: [],
                   destination: %Akd.Destination{host: :local, path: ".",
                                  user: :current}}], run_ensure: true}
Link to this macro form_hook(opts, list) View Source (macro)

Forms a hook with a given block. This is the entry point to this DSL.

Examples

form_hook opts, do

main "echo hello", Akd.Destination.local()

end

iex> import Akd.Dsl.FormHook
iex> form_hook ignore_failure: true, run_ensure: false do
...> main "echo hello", Akd.Destination.local()
...> main "run this cmd", Akd.Destination.local()
...> ensure "run this too", Akd.Destination.local()
...> rollback "roll this back", Akd.Destination.local()
...> end
%Akd.Hook{ensure: [%Akd.Operation{cmd: "run this too", cmd_envs: [],
     destination: %Akd.Destination{host: :local, path: ".",
      user: :current}}], ignore_failure: true,
   main: [%Akd.Operation{cmd: "echo hello", cmd_envs: [],
     destination: %Akd.Destination{host: :local, path: ".",
      user: :current}},
    %Akd.Operation{cmd: "run this cmd", cmd_envs: [],
     destination: %Akd.Destination{host: :local, path: ".",
      user: :current}}],
   rollback: [%Akd.Operation{cmd: "roll this back", cmd_envs: [],
     destination: %Akd.Destination{host: :local, path: ".",
      user: :current}}], run_ensure: false}

Gets list of operations from the Agent that keeps track of operations while using the FormHook DSL

Link to this macro main(cmd, dest) View Source (macro)

Adds an operation to the main category of a hook

These commands are the main commands that are ran when a hook is first executed.

Same as main/2 but without cmd_env

Examples

main “echo hello”, Akd.Destination.local()

Link to this macro main(cmd, dest, list) View Source (macro)

Adds an operation to the main category of a hook

These commands are the main commands that are ran when a hook is first executed.

Takes a set of cmd_env, which is a list of tuples which represent the environment (system) variables that will be given before the operation is executed.

Examples

main “echo $GREET”, Akd.Destination.local(), cmd_env: [{“GREET”, “hello”}]

This adds an operation to the Agent that keeps track of operations while using the FormHook DSL

Link to this macro rollback(cmd, dest) View Source (macro)

Adds an operation to the rollback category of a hook

These commands are the commands that are ran after all the hooks are executed and if there is a failure.

Same as rollback/2 but without cmd_env

Examples

rollback “echo $GREET”, Akd.Destination.local()

Link to this macro rollback(cmd, dest, list) View Source (macro)

Adds an operation to the rollback category of a hook

These commands are the commands that are ran after all the hooks are executed and if there is a failure.

Takes a set of cmd_env, which is a list of tuples which represent the environment (system) variables that will be given before the operation is executed.

Examples

rollback “echo $GREET”, Akd.Destination.local(), cmd_env: [{“GREET”, “hello”}]

Link to this function start_ops_acc(ops \\ []) View Source

This starts an Agent that keeps track of added operations while using the FormHook DSL

This stops the Agent that keeps track of added operations while using the FormHook DSL

Converts a list of operations with options to an Akd.Hook.t struct