Module: Carafe::DSL

Defined in:
lib/carafe.rb

Overview

The methods in this module are made available to all Capistrano tasks.

Instance Method Summary collapse

Instance Method Details

#app_hostsObject

Returns an array of application nodes, to be consumed by capistrano’s on method like this:

task :my_task do
  on app_hosts do
    ...
  end
end


79
80
81
82
83
84
85
# File 'lib/carafe.rb', line 79

def app_hosts
  hosts = roles(:app)

  raise "No hosts have been configured with role 'app'" if hosts.none?

  hosts
end

#app_pathPathname

Returns the path on the target hosts where releases are extracted and loaded from.

Returns:

  • (Pathname)


67
68
69
# File 'lib/carafe.rb', line 67

def app_path
  Pathname(fetch(:app_path) { raise "set :app_path node path where the release is unpacked an run" })
end

#build_hostObject

Returns the build host, to be consumed by capistrano’s on method like this:

task :my_task do
  on build_host do
    ...
  end
end


19
20
21
22
23
24
25
26
# File 'lib/carafe.rb', line 19

def build_host
  hosts = roles(:build)

  raise "No build host available." if hosts.none?
  raise "There can only be one build host." if hosts.length > 1

  hosts.first
end

#build_pathPathname

Returns the build path on the build host, can be used with capistrano’s within method like this:

task :my_task do
  on build_host do |host|
    within build_path do
      ...
    end
  end
end

Returns:

  • (Pathname)


39
40
41
# File 'lib/carafe.rb', line 39

def build_path
  Pathname(fetch(:build_path) { raise "no :build_path configured" })
end

#distillery_environmentString

Returns the distillery environment to use, defaulting to the result of mix_env. The distillery environment is configured in rel/config.exs.

Returns:

  • (String)


91
92
93
# File 'lib/carafe.rb', line 91

def distillery_environment
  fetch(:distillery_environment).to_s
end

#execute_elixir(elixir_string) ⇒ Object

Executes the given elixir code on the node, through the rpc interface. Fails if the code raises an exception or returns :error or {:error, _}.



97
98
99
100
# File 'lib/carafe.rb', line 97

def execute_elixir(elixir_string)
  script = fetch(:distillery_release)
  execute "bin/#{script}", "rpc", "Elixir.Carafe", "execute_elixir", elixir_string.shellescape
end

#mix_envString

Returns the mix environment to be used when preparing and creating the release. Can be used with capistrano’s with method like this:

task :my_task do
  on build_host do |host|
    within build_path do
      with mix_env: mix_env do
        ...
      end
    end
  end
end

Note that with upcases the key, such that the name of the OS environment variable will be MIX_ENV.

Returns:

  • (String)


60
61
62
# File 'lib/carafe.rb', line 60

def mix_env
  fetch(:mix_env).to_s
end