Class: Dapp::Dapp
- Inherits:
-
Object
- Object
- Dapp::Dapp
- Extended by:
- Helper::Trivia
- Includes:
- Chef, Command::Common, Command::Sample::Common, Command::Sample::Create, Command::Sample::List, 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,
lib/dapp/dapp/command/sample/list.rb,
lib/dapp/dapp/command/sample/common.rb,
lib/dapp/dapp/command/sample/create.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
Constants included from Deps::Gitartifact
Deps::Gitartifact::GITARTIFACT_VERSION
Constants included from Deps::Toolchain
Deps::Toolchain::TOOLCHAIN_VERSION
Constants included from Logging::Paint
Constants included from Logging::Process
Logging::Process::DEFAULT_STYLE, Logging::Process::DEFAULT_TERMINAL_WIDTH
Constants included from Slug
Slug::SLUG_SEPARATOR, Slug::SLUG_V2_LIMIT_LENGTH
Constants included from DappConfig
DappConfig::SUPPORTED_CONFIG_OPTIONS
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
- .docker_credentials ⇒ Object
- .home_dir ⇒ Object
- .host_docker ⇒ Object
- .host_docker_bin ⇒ Object
- .host_docker_config_dir ⇒ Object
- .host_docker_minor_version ⇒ Object
- .host_docker_tmp_config_dir ⇒ Object
- .options ⇒ Object
- .options_with_docker_credentials? ⇒ Boolean
- .tmp_base_dir ⇒ Object
Instance Method Summary collapse
- #build_dir ⇒ Object
- #build_path(*path) ⇒ Object
- #git_own_repo ⇒ Object
- #git_own_repo_exist? ⇒ Boolean
- #git_url ⇒ Object
- #host_docker ⇒ Object
- #host_docker_login(repo) ⇒ Object
- #host_docker_tmp_config_dir ⇒ Object
-
#initialize(options: {}) ⇒ Dapp
constructor
A new instance of Dapp.
- #local_git_artifact_exclude_paths(&blk) ⇒ Object
- #name ⇒ Object
- #path(*path) ⇒ Object
- #settings ⇒ Object
- #stage_cache ⇒ Object
- #stage_dapp_label ⇒ Object
- #terminate ⇒ Object
- #tmp_base_dir ⇒ Object
- #try_host_docker_login ⇒ Object
- #work_dir ⇒ Object
Methods included from Helper::Trivia
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
Methods included from Shellout::Base
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
Methods included from Deps::Gitartifact
#git_bin, #gitartifact_container, #gitartifact_container_name
Methods included from Deps::Toolchain
#toolchain_container, #toolchain_container_name
Methods included from Helper::Url
#get_host_from_git_url, #git_url_to_name
Methods included from Helper::Tar
#tar_gz_read, #tar_read, #tar_write
Methods included from Helper::Sha256
#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
Methods included from Logging::Paint
included, initialize, #paint_string, #paint_style, #unpaint
Methods included from Logging::I18n
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, #service_stream, #with_log_indent
Methods included from Command::Sample::Create
#_sample_directory, #_sample_repo_blobs_entries, #_sample_slice_cwd, #sample_create, #sample_exist!, #sample_exist?
Methods included from Command::Sample::List
Methods included from Command::Sample::Common
#_sample_git_repo, #_sample_list, #_samples_dir, #_samples_git_repo_branch, #_samples_git_repo_url
Methods included from Command::Slug
Methods included from Command::Common
#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
Methods included from Dappfile
#config, #dappfile_exists?, #download_dappfile_yml_bin, #expand_path, #load_dappfile_ruby, #load_dappfile_yml
Methods included from GitArtifact
#dimgstage_g_a_commit_label, #dimgstage_g_a_type_label
Methods included from Lock
Constructor Details
#initialize(options: {}) ⇒ Dapp
Returns a new instance of Dapp.
39 40 41 42 43 44 45 46 |
# File 'lib/dapp/dapp.rb', line 39 def initialize(options: {}) self.class..merge!() Logging::I18n.initialize Logging::Paint.initialize(option_color) @_call_before_terminate = [] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
37 38 39 |
# File 'lib/dapp/dapp.rb', line 37 def @options end |
Class Method Details
.docker_credentials ⇒ Object
226 227 228 229 230 231 232 |
# File 'lib/dapp/dapp.rb', line 226 def docker_credentials if .key?(:registry_username) && .key?(:registry_password) [[:registry_username], [:registry_password]] elsif ENV.key?('CI_JOB_TOKEN') ['gitlab-ci-token', ENV['CI_JOB_TOKEN']] end end |
.home_dir ⇒ Object
180 181 182 |
# File 'lib/dapp/dapp.rb', line 180 def home_dir File.join(Dir.home, ".dapp") end |
.host_docker ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/dapp/dapp.rb', line 188 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
203 204 205 206 |
# File 'lib/dapp/dapp.rb', line 203 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
212 213 214 215 216 217 218 219 220 |
# File 'lib/dapp/dapp.rb', line 212 def host_docker_config_dir if && ![: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
208 209 210 |
# File 'lib/dapp/dapp.rb', line 208 def host_docker_minor_version Gem::Version.new(shellout!("#{host_docker_bin} --version").stdout.strip[/\d+\.\d+/]) end |
.host_docker_tmp_config_dir ⇒ Object
234 235 236 |
# File 'lib/dapp/dapp.rb', line 234 def host_docker_tmp_config_dir @host_docker_tmp_config_dir ||= Dir.mktmpdir('dapp-', tmp_base_dir) end |
.options ⇒ Object
184 185 186 |
# File 'lib/dapp/dapp.rb', line 184 def @options ||= {} end |
.options_with_docker_credentials? ⇒ Boolean
222 223 224 |
# File 'lib/dapp/dapp.rb', line 222 def !docker_credentials.nil? end |
.tmp_base_dir ⇒ Object
238 239 240 |
# File 'lib/dapp/dapp.rb', line 238 def tmp_base_dir File.([:tmp_dir_prefix] || '/tmp') end |
Instance Method Details
#build_dir ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/dapp/dapp.rb', line 117 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..tap(&:mkpath) end end |
#build_path(*path) ⇒ Object
128 129 130 |
# File 'lib/dapp/dapp.rb', line 128 def build_path(*path) make_path(build_dir, *path) end |
#git_own_repo ⇒ Object
97 98 99 100 101 102 |
# File 'lib/dapp/dapp.rb', line 97 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
93 94 95 |
# File 'lib/dapp/dapp.rb', line 93 def git_own_repo_exist? !git_own_repo.nil? end |
#git_url ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/dapp/dapp.rb', line 85 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
154 155 156 |
# File 'lib/dapp/dapp.rb', line 154 def host_docker self.class.host_docker end |
#host_docker_login(repo) ⇒ Object
168 169 170 171 172 173 174 175 176 177 |
# File 'lib/dapp/dapp.rb', line 168 def host_docker_login(repo) return unless self.class. 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
158 159 160 |
# File 'lib/dapp/dapp.rb', line 158 def host_docker_tmp_config_dir self.class.host_docker_tmp_config_dir end |
#local_git_artifact_exclude_paths(&blk) ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/dapp/dapp.rb', line 132 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/dapp/dapp.rb', line 64 def name @name ||= begin n = begin if (name = [: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
108 109 110 111 |
# File 'lib/dapp/dapp.rb', line 108 def path(*path) @path ||= make_path(work_dir) make_path(@path, *path) end |
#settings ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dapp/dapp.rb', line 52 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
141 142 143 |
# File 'lib/dapp/dapp.rb', line 141 def stage_cache "dimgstage-#{name}" end |
#stage_dapp_label ⇒ Object
145 146 147 |
# File 'lib/dapp/dapp.rb', line 145 def stage_dapp_label name end |
#terminate ⇒ Object
149 150 151 152 |
# File 'lib/dapp/dapp.rb', line 149 def terminate @_call_before_terminate.each {|on_terminate| on_terminate.call(self)} FileUtils.rmtree(host_docker_tmp_config_dir) end |
#tmp_base_dir ⇒ Object
113 114 115 |
# File 'lib/dapp/dapp.rb', line 113 def tmp_base_dir self.class.tmp_base_dir end |
#try_host_docker_login ⇒ Object
162 163 164 165 166 |
# File 'lib/dapp/dapp.rb', line 162 def try_host_docker_login return unless option_repo validate_repo_name!(option_repo) host_docker_login(option_repo) end |
#work_dir ⇒ Object
104 105 106 |
# File 'lib/dapp/dapp.rb', line 104 def work_dir File.([:dir] || Dir.pwd) end |