Class: Dapp::Dapp
- Inherits:
-
Object
show all
- Extended by:
- Helper::Trivia
- Includes:
- Chef, Command::Common, Command::Slug, DappConfig, Dappfile, Deps::Base, Deps::Gitartifact, Deps::Toolchain, GitArtifact, Lock, Logging::Base, Logging::I18n, Logging::Paint, Logging::Process, OptionTags, Sentry, Shellout::Base, Slug, 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/slug.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/option_tags.rb,
lib/dapp/dapp/command/slug.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/command/common.rb,
lib/dapp/dapp/deps/toolchain.rb,
lib/dapp/dapp/logging/process.rb,
lib/dapp/dapp/deps/gitartifact.rb,
lib/dapp/dapp/shellout/streaming.rb
Defined Under Namespace
Modules: Chef, Command, DappConfig, Dappfile, Deps, GitArtifact, Lock, Logging, OptionTags, Sentry, Shellout, Slug, SshAgent
Constant Summary
Constants included
from Deps::Base
Deps::Base::BASE_VERSION
Deps::Gitartifact::GITARTIFACT_VERSION
Deps::Toolchain::TOOLCHAIN_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
check_path?, check_subpath?, class_to_lowercase, class_to_lowercase, delete_file, ignore_path?, ignore_path_base, kwargs, make_path, path_checker, search_file_upward
default_env_keys, included, #shellout, #shellout!, #shellout_cmd_should_succeed!, #shellout_pack
Methods included from Deps::Base
#base_container, #base_container_name, #dappdeps_base_path, #sudo_command, #sudo_format_user
#git_bin, #gitartifact_container, #gitartifact_container_name
#toolchain_container, #toolchain_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, #default_ssh_keys, included, #run_ssh_agent, #setup_ssh_agent, #ssh_agent_exist?, #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, #service_stream, #with_log_indent
#slug
#dimg_registry, #option_repo, #shortcut_or_key, #shortcuts
Methods included from Slug
#consistent_uniq_slug_reg, #consistent_uniq_slugify, #should_be_slugged?
Methods included from OptionTags
#branch_tags, #build_tags, #ci_tags, #commit_tags, #option_tags, #plain_tags, #slug_tags, #tagging_schemes, #tags_by_scheme
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?, #download_dappfile_yml_bin, #expand_path, #load_dappfile_ruby, #load_dappfile_yml
#dimgstage_g_a_commit_label, #dimgstage_g_a_type_label
Methods included from Lock
#_lock, #lock, #locks_dir
Constructor Details
#initialize(options: {}) ⇒ Dapp
Returns a new instance of Dapp.
36
37
38
39
40
41
42
43
|
# File 'lib/dapp/dapp.rb', line 36
def initialize(options: {})
self.class.options.merge!(options)
Logging::I18n.initialize
validate_config_options!
Logging::Paint.initialize(option_color)
@_call_before_terminate = []
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
34
35
36
|
# File 'lib/dapp/dapp.rb', line 34
def options
@options
end
|
Class Method Details
.docker_credentials ⇒ Object
223
224
225
226
227
228
229
|
# File 'lib/dapp/dapp.rb', line 223
def docker_credentials
if options.key?(:registry_username) && options.key?(:registry_password)
[options[:registry_username], options[:registry_password]]
elsif ENV.key?('CI_JOB_TOKEN')
['gitlab-ci-token', ENV['CI_JOB_TOKEN']]
end
end
|
.home_dir ⇒ Object
177
178
179
|
# File 'lib/dapp/dapp.rb', line 177
def home_dir
File.join(Dir.home, ".dapp")
end
|
.host_docker ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/dapp/dapp.rb', line 185
def host_docker
@host_docker ||= begin
min_docker_minor_version = Gem::Version.new('1.10')
unless host_docker_minor_version > min_docker_minor_version
raise Error::Dapp, code: :docker_version, data: { min_version: min_docker_minor_version.to_s,
version: host_docker_minor_version.to_s }
end
[].tap do |cmd|
cmd << host_docker_bin
cmd << "--config #{host_docker_config_dir}"
end.join(' ')
end
end
|
.host_docker_bin ⇒ Object
200
201
202
203
|
# File 'lib/dapp/dapp.rb', line 200
def host_docker_bin
raise Error::Dapp, code: :docker_not_found if (res = shellout('which docker')).exitstatus.nonzero?
res.stdout.strip
end
|
.host_docker_config_dir ⇒ Object
209
210
211
212
213
214
215
216
217
|
# File 'lib/dapp/dapp.rb', line 209
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_minor_version ⇒ Object
205
206
207
|
# File 'lib/dapp/dapp.rb', line 205
def host_docker_minor_version
Gem::Version.new(shellout!("#{host_docker_bin} --version").stdout.strip[/\d+\.\d+/])
end
|
.host_docker_tmp_config_dir ⇒ Object
231
232
233
|
# File 'lib/dapp/dapp.rb', line 231
def host_docker_tmp_config_dir
@host_docker_tmp_config_dir ||= Dir.mktmpdir('dapp-', tmp_base_dir)
end
|
.options ⇒ Object
181
182
183
|
# File 'lib/dapp/dapp.rb', line 181
def options
@options ||= {}
end
|
.options_with_docker_credentials? ⇒ Boolean
219
220
221
|
# File 'lib/dapp/dapp.rb', line 219
def options_with_docker_credentials?
!docker_credentials.nil?
end
|
.tmp_base_dir ⇒ Object
235
236
237
|
# File 'lib/dapp/dapp.rb', line 235
def tmp_base_dir
File.expand_path(options[:tmp_dir_prefix] || '/tmp')
end
|
Instance Method Details
#build_dir ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/dapp/dapp.rb', line 114
def build_dir
@build_dir ||= begin
if option_build_dir
Pathname.new(option_build_dir)
else
dir = File.join(self.class.home_dir, "builds", self.name)
Pathname.new(dir)
end.expand_path.tap(&:mkpath)
end
end
|
#build_path(*path) ⇒ Object
125
126
127
|
# File 'lib/dapp/dapp.rb', line 125
def build_path(*path)
make_path(build_dir, *path)
end
|
#git_own_repo ⇒ Object
94
95
96
97
98
99
|
# File 'lib/dapp/dapp.rb', line 94
def git_own_repo
@git_own_repo ||= Dimg::GitRepo::Own.new(self)
rescue Dimg::Error::Rugged => e
raise unless e.net_status[:code] == :local_git_repository_does_not_exist
nil
end
|
#git_own_repo_exist? ⇒ Boolean
90
91
92
|
# File 'lib/dapp/dapp.rb', line 90
def git_own_repo_exist?
!git_own_repo.nil?
end
|
#git_url ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/dapp/dapp.rb', line 82
def git_url
return unless git_own_repo_exist?
git_own_repo.remote_origin_url
rescue Dimg::Error::Rugged => e
return if e.net_status[:code] == :git_repository_without_remote_url
raise
end
|
#host_docker ⇒ Object
151
152
153
|
# File 'lib/dapp/dapp.rb', line 151
def host_docker
self.class.host_docker
end
|
#host_docker_login(repo) ⇒ Object
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/dapp/dapp.rb', line 165
def host_docker_login(repo)
return unless self.class.options_with_docker_credentials?
username, password = self.class.docker_credentials
if ::Dapp::Dapp.host_docker_minor_version >= Gem::Version.new('17.07')
shellout!("#{host_docker} login --username '#{username}' --password-stdin '#{repo}'", input: password)
else
shellout!("#{host_docker} login --username '#{username}' --password '#{password}' '#{repo}'")
end
end
|
#host_docker_tmp_config_dir ⇒ Object
155
156
157
|
# File 'lib/dapp/dapp.rb', line 155
def host_docker_tmp_config_dir
self.class.host_docker_tmp_config_dir
end
|
#local_git_artifact_exclude_paths(&blk) ⇒ Object
129
130
131
132
133
134
135
136
|
# File 'lib/dapp/dapp.rb', line 129
def local_git_artifact_exclude_paths(&blk)
super do |exclude_paths|
build_path_relpath = Pathname.new(build_path).subpath_of(File.dirname(git_own_repo.path))
exclude_paths << build_path_relpath.to_s if build_path_relpath
yield exclude_paths if block_given?
end
end
|
#name ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/dapp/dapp.rb', line 61
def name
@name ||= begin
n = begin
if (name = options[:name])
name
elsif git_own_repo_exist?
if git_url
repo_name = git_url.split('/').last
repo_name = repo_name[/.*(?=\.git)/] if repo_name.end_with? '.git'
repo_name
else
File.basename(File.dirname(git_own_repo.path)).to_s
end
else
path.basename.to_s
end
end
consistent_uniq_slugify(n)
end
end
|
#path(*path) ⇒ Object
105
106
107
108
|
# File 'lib/dapp/dapp.rb', line 105
def path(*path)
@path ||= make_path(work_dir)
make_path(@path, *path)
end
|
#settings ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/dapp/dapp.rb', line 49
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
138
139
140
|
# File 'lib/dapp/dapp.rb', line 138
def stage_cache
"dimgstage-#{name}"
end
|
#stage_dapp_label ⇒ Object
142
143
144
|
# File 'lib/dapp/dapp.rb', line 142
def stage_dapp_label
name
end
|
#terminate ⇒ Object
146
147
148
149
|
# File 'lib/dapp/dapp.rb', line 146
def terminate
@_call_before_terminate.each {|on_terminate| on_terminate.call(self)}
FileUtils.rmtree(host_docker_tmp_config_dir)
end
|
#tmp_base_dir ⇒ Object
110
111
112
|
# File 'lib/dapp/dapp.rb', line 110
def tmp_base_dir
self.class.tmp_base_dir
end
|
#try_host_docker_login ⇒ Object
159
160
161
162
163
|
# File 'lib/dapp/dapp.rb', line 159
def try_host_docker_login
return unless option_repo
validate_repo_name!(option_repo)
host_docker_login(option_repo)
end
|
#work_dir ⇒ Object
101
102
103
|
# File 'lib/dapp/dapp.rb', line 101
def work_dir
File.expand_path(options[:dir] || Dir.pwd)
end
|