Module: Dapp::Build::Stage::Mod::Artifact

Included in:
Artifact
Defined in:
lib/dapp/build/stage/mod/artifact.rb

Overview

Artifact

Instance Method Summary collapse

Instance Method Details

#apply_artifact(artifact, image) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dapp/build/stage/mod/artifact.rb', line 40

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]

  docker_options = ['--rm',
                    "--volume #{application.tmp_path('artifact', artifact_name)}:#{app.container_tmp_path(artifact_name)}",
                    '--entrypoint /bin/bash']
  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(docker_options, [%(-ec '#{application.shellout_pack(commands)}')])
  end

  commands = safe_cp(application.container_tmp_path('artifact', artifact_name), where_to_add, owner, group, cwd, paths)
  image.add_command commands
  image.add_volume "#{application.tmp_path('artifact', artifact_name)}:#{application.container_tmp_path('artifact', artifact_name)}:ro"
end

#artifact_app_options(artifact, verbose) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/dapp/build/stage/mod/artifact.rb', line 26

def artifact_app_options(artifact, verbose)
  {
    config: artifact._config,
    cli_options: application.cli_options.merge(log_quiet: !verbose),
    ignore_git_fetch: application.ignore_git_fetch,
    is_artifact: true
  }
end

#artifacts ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dapp/build/stage/mod/artifact.rb', line 8

def artifacts
  @artifacts ||= begin
    verbose = application.log_verbose?
    application.config._artifact.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._artifact_options,
            app: Application.new(artifact_app_options(artifact, verbose)).tap(&:build!)
          }
        end
      end
    end
  end
end

#artifacts_signatures ⇒ Object



35
36
37
# File 'lib/dapp/build/stage/mod/artifact.rb', line 35

def artifacts_signatures
  artifacts.map { |artifact| hashsum [artifact[:app].signature, artifact[:options]] }
end

#safe_cp(from, to, owner, group, cwd = '', paths = []) ⇒ Object

rubocop:disable Metrics/ParameterLists



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/dapp/build/stage/mod/artifact.rb', line 66

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