Akd v0.3.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 within
the do - end
block, using the main
, ensure
, and rollback
macros, with their
specific options. Once the block ends, it resolves all those operations into
an Akd.Hook.t
struct, which it then returns.
Once this hook is defined it can be used in a pipeline or an 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
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_envs
Examples
ensure "echo $GREET", Akd.Destination.local()
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_envs
, 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_envs: [{"GREET", "hello"}]
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}
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}
get_ops_acc(ops) View Source
Gets list of operations from the Agent that keeps track of operations while using the FormHook DSL
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_envs
Examples
main "echo hello", Akd.Destination.local()
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_envs
, 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_envs: [{"GREET", "hello"}]
put_ops_acc(ops, op) View Source
This adds an operation to the Agent that keeps track of operations while using the FormHook DSL
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_envs
Examples
rollback "echo $GREET", Akd.Destination.local()
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_envs
, 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_envs: [{"GREET", "hello"}]
start_ops_acc(ops \\ []) View Source
This starts an Agent that keeps track of added operations while using the FormHook DSL
stop_ops_acc(ops) View Source
This stops the Agent that keeps track of added operations while using the FormHook DSL
struct_hook(ops, opts) View Source
Converts a list of operations with options to an Akd.Hook.t
struct