Class: Dapp::Dapp

Inherits:
Object
  • Object
show all
Includes:
Chef, DappConfig, Dappfile, Deps::Base, Deps::Gitartifact, GitArtifact, Lock, Logging::Base, Logging::I18n, Logging::Paint, Logging::Process, Shellout::Base, SshAgent, Helper::Sha256, Helper::Tar, Helper::Trivia
Defined in:
lib/dapp/dapp.rb,
lib/dapp/dapp/chef.rb,
lib/dapp/dapp/lock.rb,
lib/dapp/dapp/dappfile.rb,
lib/dapp/dapp/deps/base.rb,
lib/dapp/dapp/ssh_agent.rb,
lib/dapp/dapp/dapp_config.rb,
lib/dapp/dapp/git_artifact.rb,
lib/dapp/dapp/logging/base.rb,
lib/dapp/dapp/logging/i18n.rb,
lib/dapp/dapp/logging/paint.rb,
lib/dapp/dapp/shellout/base.rb,
lib/dapp/dapp/logging/process.rb,
lib/dapp/dapp/deps/gitartifact.rb,
lib/dapp/dapp/shellout/streaming.rb

Defined Under Namespace

Modules: Chef, DappConfig, Dappfile, Deps, GitArtifact, Lock, Logging, Shellout, SshAgent

Constant Summary

Constants included from Deps::Base

Deps::Base::BASE_VERSION

Constants included from Deps::Gitartifact

Deps::Gitartifact::GITARTIFACT_VERSION

Constants included from Logging::Paint

Logging::Paint::FORMAT

Constants included from Logging::Process

Logging::Process::DEFAULT_STYLE, Logging::Process::DEFAULT_TERMINAL_WIDTH

Constants included from DappConfig

DappConfig::SUPPORTED_CONFIG_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shellout::Base

default_env_keys, included, #shellout, #shellout!, #shellout_pack

Methods included from Deps::Base

#base_container, #base_container_name, #sudo_command, #sudo_format_user

Methods included from Deps::Gitartifact

#git_bin, #gitartifact_container, #gitartifact_container_name

Methods included from Helper::Tar

#tar_gz_read, #tar_read, #tar_write

Methods included from Helper::Trivia

class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs, #make_path, #search_file_upward

Methods included from Helper::Sha256

#hashsum, #paths_content_hashsum, #sha256

Methods included from SshAgent

#add_ssh_key, included, #run_ssh_agent, #setup_ssh_agent, #ssh_auth_sock

Methods included from Logging::Paint

included, initialize, #paint_string, #paint_style, #unpaint

Methods included from Logging::I18n

initialize, #t

Methods included from Logging::Process

#log_process, #log_secondary_process, #log_state

Methods included from Logging::Base

#dev_mode?, #dry_run?, #ignore_config_warning?, included, #introspect_before_error?, #introspect_error?, #log, #log_config_warning, #log_dimg_name_with_indent, #log_format_string, #log_indent, #log_indent_next, #log_indent_prev, #log_info, #log_quiet?, #log_secondary, #log_step, #log_step_with_indent, #log_time, #log_time?, #log_verbose?, #log_warning, #with_log_indent

Methods included from DappConfig

#config_options, #option_color, #option_dev, #validate_config_options!

Methods included from Chef

#builder_cookbook_path

Methods included from Dappfile

#config, #dappfile_exists?, #dappfile_path, #expand_path, #work_dir

Methods included from Lock

#_lock, #lock, #lock_path

Constructor Details

#initialize(options: {}) ⇒ Dapp

Returns a new instance of Dapp.



26
27
28
29
30
31
# File 'lib/dapp/dapp.rb', line 26

def initialize(options: {})
  @options = options
  Logging::I18n.initialize
  validate_config_options!
  Logging::Paint.initialize(option_color)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/dapp/dapp.rb', line 24

def options
  @options
end

Class Method Details

.host_docker_binObject



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dapp/dapp.rb', line 105

def self.host_docker_bin
  @host_docker_bin ||= begin
    raise Error::Dapp, code: :docker_not_found if (res = shellout('which docker')).exitstatus.nonzero?
    res.stdout.strip.tap do |docker_bin|
      current_docker_version = shellout!("#{docker_bin} --version").stdout.strip
      required_docker_version = '1.10.0'

      if Gem::Version.new(required_docker_version) >= Gem::Version.new(current_docker_version[/(\d+\.)+\d+/])
        raise Error::Dapp, code: :docker_version, data: { version: required_docker_version }
      end
    end
  end
end

Instance Method Details

#build_path(*path) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/dapp/dapp.rb', line 73

def build_path(*path)
  @build_path ||= begin
    if option_build_dir
      Pathname.new(option_build_dir)
    else
      path('.dapp_build')
    end.expand_path.tap(&:mkpath)
  end
  make_path(@build_path, *path)
end

#git_configObject



52
53
54
55
56
# File 'lib/dapp/dapp.rb', line 52

def git_config
  @git_config ||= begin
    IniFile.load(File.join(git_path, 'config')) if git_path
  end
end

#git_pathObject



58
59
60
61
62
# File 'lib/dapp/dapp.rb', line 58

def git_path
  defined?(@git_path) ? @git_path : begin
    @git_path = search_file_upward('.git')
  end
end

#git_urlObject



47
48
49
50
# File 'lib/dapp/dapp.rb', line 47

def git_url
  return unless git_config
  (git_config['remote "origin"'] || {})['url']
end

#host_docker_binObject



101
102
103
# File 'lib/dapp/dapp.rb', line 101

def host_docker_bin
  self.class.host_docker_bin
end

#local_git_artifact_exclude_paths(&blk) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/dapp/dapp.rb', line 84

def local_git_artifact_exclude_paths(&blk)
  super do |exclude_paths|
    build_path_relpath = Pathname.new(build_path).subpath_of(File.dirname(git_path))
    exclude_paths << build_path_relpath.to_s if build_path_relpath

    yield exclude_paths if block_given?
  end
end

#nameObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dapp/dapp.rb', line 33

def name
  @name ||= begin
    if git_url
      repo_name = git_url.split('/').last
      repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
      repo_name
    elsif git_path
      File.basename(File.dirname(git_path)).to_s
    else
      path.basename.to_s
    end
  end
end

#path(*path) ⇒ Object



64
65
66
67
# File 'lib/dapp/dapp.rb', line 64

def path(*path)
  @path ||= expand_path(dappfile_path)
  make_path(@path, *path)
end

#stage_cacheObject



93
94
95
# File 'lib/dapp/dapp.rb', line 93

def stage_cache
  "dimgstage-#{name}"
end

#stage_dapp_labelObject



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

def stage_dapp_label
  name
end

#tmp_base_dirObject



69
70
71
# File 'lib/dapp/dapp.rb', line 69

def tmp_base_dir
  File.expand_path(options[:tmp_dir_prefix] || '/tmp')
end