Class: Dapp::Dapp
- Inherits:
-
Object
show all
- Extended by:
- Helper::Trivia
- Includes:
- Chef, DappConfig, Dappfile, Deps::Base, Deps::Gitartifact, GitArtifact, Lock, Logging::Base, Logging::I18n, Logging::Paint, Logging::Process, Sentry, Shellout::Base, SshAgent, Helper::Sha256, Helper::Tar, Helper::Trivia, Helper::Url
- Defined in:
- lib/dapp/dapp.rb,
lib/dapp/dapp/chef.rb,
lib/dapp/dapp/lock.rb,
lib/dapp/dapp/sentry.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, Sentry, Shellout, SshAgent
Constant Summary
Constants included
from Deps::Base
Deps::Base::BASE_VERSION
Deps::Gitartifact::GITARTIFACT_VERSION
Logging::Paint::FORMAT
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
class_to_lowercase, class_to_lowercase, delete_file, kwargs, make_path, search_file_upward
default_env_keys, included, #shellout, #shellout!, #shellout_pack
Methods included from Deps::Base
#base_container, #base_container_name, #sudo_command, #sudo_format_user
#git_bin, #gitartifact_container, #gitartifact_container_name
#get_host_from_git_url, #git_url_to_name
#tar_gz_read, #tar_read, #tar_write
#hashsum, #paths_content_hashsum, #sha256
Methods included from Sentry
#_make_sentry_params, #_sentry_extra_context, #_sentry_tags_context, #_sentry_user_context, #ensure_sentry_configured, #sentry_exception, #sentry_message
Methods included from SshAgent
#add_ssh_key, included, #run_ssh_agent, #setup_ssh_agent, #ssh_auth_sock
included, initialize, #paint_string, #paint_style, #unpaint
initialize, #t
#log_process, #log_secondary_process, #log_state
#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.
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
28
29
30
|
# File 'lib/dapp/dapp.rb', line 28
def options
@options
end
|
Class Method Details
.home_dir ⇒ Object
150
151
152
|
# File 'lib/dapp/dapp.rb', line 150
def home_dir
File.join(Dir.home, ".dapp")
end
|
.host_docker ⇒ Object
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/dapp/dapp.rb', line 158
def host_docker
@host_docker ||= begin
raise Error::Dapp, code: :docker_not_found if (res = shellout('which docker')).exitstatus.nonzero?
docker_bin = res.stdout.strip
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
[].tap do |cmd|
cmd << docker_bin
cmd << "--config #{host_docker_config_dir}"
end.join(' ')
end
end
|
.host_docker_config_dir ⇒ Object
177
178
179
180
181
182
183
184
185
|
# File 'lib/dapp/dapp.rb', line 177
def host_docker_config_dir
if options_with_docker_credentials? && !options[:repo].nil?
host_docker_tmp_config_dir
elsif ENV.key?('DAPP_DOCKER_CONFIG')
ENV['DAPP_DOCKER_CONFIG']
else
File.join(Dir.home, '.docker')
end
end
|
.host_docker_tmp_config_dir ⇒ Object
191
192
193
|
# File 'lib/dapp/dapp.rb', line 191
def host_docker_tmp_config_dir
@host_docker_tmp_config_dir ||= Dir.mktmpdir('dapp-', tmp_base_dir)
end
|
.options ⇒ Object
154
155
156
|
# File 'lib/dapp/dapp.rb', line 154
def options
@options ||= {}
end
|
.options_with_docker_credentials? ⇒ Boolean
187
188
189
|
# File 'lib/dapp/dapp.rb', line 187
def options_with_docker_credentials?
(options.key?(:registry_username) && options.key?(:registry_password)) || ENV.key?('CI_JOB_TOKEN')
end
|
.tmp_base_dir ⇒ Object
195
196
197
|
# File 'lib/dapp/dapp.rb', line 195
def tmp_base_dir
File.expand_path(options[:tmp_dir_prefix] || '/tmp')
end
|
Instance Method Details
#build_dir ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/dapp/dapp.rb', line 93
def build_dir
@build_dir ||= begin
if option_build_dir
Pathname.new(option_build_dir)
else
path('.dapp_build')
end.expand_path.tap(&:mkpath)
end
end
|
#build_path(*path) ⇒ Object
103
104
105
|
# File 'lib/dapp/dapp.rb', line 103
def build_path(*path)
make_path(build_dir, *path)
end
|
#git_config ⇒ Object
72
73
74
75
76
|
# File 'lib/dapp/dapp.rb', line 72
def git_config
@git_config ||= begin
IniFile.load(File.join(git_path, 'config')) if git_path
end
end
|
#git_path ⇒ Object
78
79
80
81
82
|
# File 'lib/dapp/dapp.rb', line 78
def git_path
defined?(@git_path) ? @git_path : begin
@git_path = search_file_upward('.git')
end
end
|
#git_url ⇒ Object
67
68
69
70
|
# File 'lib/dapp/dapp.rb', line 67
def git_url
return unless git_config
(git_config['remote "origin"'] || {})['url']
end
|
#host_docker ⇒ Object
128
129
130
|
# File 'lib/dapp/dapp.rb', line 128
def host_docker
self.class.host_docker
end
|
#host_docker_login ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/dapp/dapp.rb', line 136
def host_docker_login
return unless option_repo
validate_repo_name!(option_repo)
login = proc {|u, p| shellout!("#{host_docker} login -u '#{u}' -p '#{p}' '#{option_repo}'")}
if options.key?(:registry_username) && options.key?(:registry_password)
login.call(options[:registry_username], options[:registry_password])
elsif ENV.key?('CI_JOB_TOKEN')
login.call('gitlab-ci-token', ENV['CI_JOB_TOKEN'])
end
end
|
#host_docker_tmp_config_dir ⇒ Object
132
133
134
|
# File 'lib/dapp/dapp.rb', line 132
def host_docker_tmp_config_dir
self.class.host_docker_tmp_config_dir
end
|
#local_git_artifact_exclude_paths(&blk) ⇒ Object
107
108
109
110
111
112
113
114
|
# File 'lib/dapp/dapp.rb', line 107
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
|
#name ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/dapp/dapp.rb', line 53
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
84
85
86
87
|
# File 'lib/dapp/dapp.rb', line 84
def path(*path)
@path ||= expand_path(dappfile_path)
make_path(@path, *path)
end
|
#settings ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/dapp/dapp.rb', line 41
def settings
@settings ||= begin
settings_path = File.join(self.class.home_dir, "settings.toml")
if File.exists? settings_path
TomlRB.load_file(settings_path)
else
{}
end
end
end
|
#stage_cache ⇒ Object
116
117
118
|
# File 'lib/dapp/dapp.rb', line 116
def stage_cache
"dimgstage-#{name}"
end
|
#stage_dapp_label ⇒ Object
120
121
122
|
# File 'lib/dapp/dapp.rb', line 120
def stage_dapp_label
name
end
|
#terminate ⇒ Object
124
125
126
|
# File 'lib/dapp/dapp.rb', line 124
def terminate
FileUtils.rmtree(host_docker_tmp_config_dir)
end
|
#tmp_base_dir ⇒ Object
89
90
91
|
# File 'lib/dapp/dapp.rb', line 89
def tmp_base_dir
self.class.tmp_base_dir
end
|