Module: Dapp::Dimg::Dapp::Command::BuildContext::Export

Included in:
Dapp
Defined in:
lib/dapp/dimg/dapp/command/build_context/export.rb

Instance Method Summary collapse

Instance Method Details

#build_context_exportObject



7
8
9
10
11
12
13
14
# File 'lib/dapp/dimg/dapp/command/build_context/export.rb', line 7

def build_context_export
  log_process(:'export context') do
    with_log_indent do
      export_build_context_image_tar
      export_build_context_build_tar
    end
  end
end

#export_build_context_build_tarObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dapp/dimg/dapp/command/build_context/export.rb', line 28

def export_build_context_build_tar
  log_secondary_process(:build_dir, short: true) do
    tar_write(build_context_build_tar) do |tar|
      Dir.glob(File.join(build_path, '**/*'), File::FNM_DOTMATCH).each do |path|
        archive_file_path = path
                              .reverse
                              .chomp(build_path.to_s.reverse)
                              .chomp('/')
                              .reverse
        if File.directory?(path)
          tar.mkdir archive_file_path, File.stat(path).mode
        else
          tar.add_file archive_file_path, File.stat(path).mode do |tf|
            tf.write File.read(path)
          end
        end
      end
    end
  end
end

#export_build_context_image_tarObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dapp/dimg/dapp/command/build_context/export.rb', line 16

def export_build_context_image_tar
  lock("#{name}.images", readonly: true) do
    context_images_names = build_configs.map do |config|
      Dimg.new(config: config, dapp: self).tagged_images.map(&:name)
    end.flatten

    log_secondary_process(:images, short: true) do
      Image::Docker.save!(context_images_names, build_context_images_tar, verbose: true, quiet: log_quiet?)
    end unless context_images_names.empty?
  end
end