Module: Dapp::Build::Stage::Mod::Artifact
- Included in:
- Base
- Defined in:
- lib/dapp/build/stage/mod/artifact.rb
Overview
Artifact
Instance Method Summary collapse
- #after_artifacts ⇒ Object
-
#apply_artifact(artifact, image) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength.
- #artifact_app_options(artifact, verbose) ⇒ Object
- #artifacts_signatures ⇒ Object
- #before_artifacts ⇒ Object
- #do_artifacts(artifacts) ⇒ Object
-
#safe_cp(from, to, owner, group, cwd = '', paths = []) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Details
#after_artifacts ⇒ Object
12 13 14 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 12 def after_artifacts @after_artifacts ||= do_artifacts(application.config._artifact.select { |artifact| artifact._after == name }) end |
#apply_artifact(artifact, image) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 46 def apply_artifact(artifact, image) return if application.dry_run? artifact_name = artifact[:name] app = artifact[:app] cwd = artifact[:options][:cwd] paths = artifact[:options][:paths] owner = artifact[:options][:owner] group = artifact[:options][:group] where_to_add = artifact[:options][:where_to_add] = ['--rm', "--volume #{application.tmp_path('artifact', artifact_name)}:#{app.container_tmp_path(artifact_name)}", '--entrypoint /bin/sh'] commands = safe_cp(where_to_add, app.container_tmp_path(artifact_name), Process.uid, Process.gid) application.log_secondary_process(application.t(code: 'process.artifact_copy', data: { name: artifact_name }), short: true) do app.run(, Array(application.shellout_pack(commands))) end commands = safe_cp(application.container_tmp_path('artifact', artifact_name), where_to_add, owner, group, cwd, paths) image.add_commands commands end |
#artifact_app_options(artifact, verbose) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 32 def (artifact, verbose) { config: artifact._config, cli_options: application..merge(log_quiet: !verbose), ignore_git_fetch: application.ignore_git_fetch, is_artifact: true } end |
#artifacts_signatures ⇒ Object
41 42 43 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 41 def artifacts_signatures (before_artifacts + after_artifacts).map { |artifact| hashsum [artifact[:app].signature, artifact[:options]] } end |
#before_artifacts ⇒ Object
8 9 10 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 8 def before_artifacts @before_artifacts ||= do_artifacts(application.config._artifact.select { |artifact| artifact._before == name }) end |
#do_artifacts(artifacts) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 16 def do_artifacts(artifacts) verbose = application.log_verbose? artifacts.map do |artifact| process = application.t(code: 'process.artifact_building', data: { name: artifact._config._name }) application.log_secondary_process(process, short: !verbose) do application.with_log_indent do { name: artifact._config._name, options: artifact., app: Application.new((artifact, verbose)).tap(&:build!) } end end end end |
#safe_cp(from, to, owner, group, cwd = '', paths = []) ⇒ Object
rubocop:disable Metrics/ParameterLists
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dapp/build/stage/mod/artifact.rb', line 71 def safe_cp(from, to, owner, group, cwd = '', paths = []) credentials = '' credentials += "-o #{owner} " if owner credentials += "-g #{group} " if group copy_files = lambda do |from_, cwd_, path_ = ''| "find #{File.join(from_, cwd_, path_)} -type f -exec bash -ec 'install -D #{credentials} {} " \ "#{File.join(to, "$(echo {} | sed -e \"s/#{File.join(from_, cwd_).gsub('/', '\\/')}//g\")")}' \\;" end commands = [] commands << ['install', credentials, '-d', to].join(' ') commands.concat(paths.empty? ? Array(copy_files.call(from, cwd)) : paths.map { |path| copy_files.call(from, cwd, path) }) commands << "find #{to} -type d -exec bash -ec 'install -d #{credentials} {}' \\;" commands.join(' && ') end |