Module: Wukong::Runner::DeployPackLoader

Included in:
Wukong::Runner
Defined in:
lib/wukong/runner/deploy_pack_loader.rb

Overview

Lets Wukong bootstrap by requiring an enclosing deploy pack's environment file if available.

We use a simple heuristic (presence of 'Gemfile' and 'config/environment.rb' in a non-root parent directory) to determine whether or not we are in a deploy pack.

Instance Method Summary collapse

Instance Method Details

#deploy_pack_dirString

Return the directory of the enclosing deploy pack. Will return the root ('/') if no deeper directory is identified as a deploy pack.

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/wukong/runner/deploy_pack_loader.rb', line 50

def deploy_pack_dir
  return File.dirname(ENV["BUNDLE_GEMFILE"]) if ENV["BUNDLE_GEMFILE"] && is_deploy_pack_dir?(File.dirname(ENV["BUNDLE_GEMFILE"]))
  return @deploy_pack_dir if @deploy_pack_dir
  wd     = Dir.pwd
  parent = File.dirname(wd)
  until wd == parent
    return wd if is_deploy_pack_dir?(wd)
    wd     = parent
    parent = File.dirname(wd)
  end
  @deploy_pack_dir = wd
end

#environment_fileString

The default environment file that will be require'd when booting.

Returns:



41
42
43
# File 'lib/wukong/runner/deploy_pack_loader.rb', line 41

def environment_file
  File.join(deploy_pack_dir, 'config', 'environment.rb')
end

#in_deploy_pack?true, false

Is execution likely happening within a deploy pack?

See Wukong::Deploy for more information on deploy packs.

Returns:

  • (true, false)


23
24
25
26
# File 'lib/wukong/runner/deploy_pack_loader.rb', line 23

def in_deploy_pack?
  return @in_deploy_pack unless @in_deploy_pack.nil?
  @in_deploy_pack = (deploy_pack_dir != '/')
end

#load_deploy_packObject

Load the actual deploy pack environment. Will not swallow any load errors.



14
15
16
# File 'lib/wukong/runner/deploy_pack_loader.rb', line 14

def load_deploy_pack
  load_ruby_file(environment_file) if in_deploy_pack?
end

#loaded_deploy_pack?true, false

Have we already loaded the environment of a deploy pack?

See Wukong::Deploy for more information on deploy packs.

Returns:

  • (true, false)


33
34
35
# File 'lib/wukong/runner/deploy_pack_loader.rb', line 33

def loaded_deploy_pack?
  in_deploy_pack? && defined?(::Wukong::Deploy)
end