Module: Dapp::Dimg::Dapp::Command::BuildContext::Import

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

Instance Method Summary collapse

Instance Method Details

#build_context_importObject



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

def build_context_import
  raise ::Dapp::Error::Command, code: :context_directory_not_found,
                                data: { path: build_context_path } unless build_context_path.exist?

  log_process(:'import context') do
    import_build_context_build_tar
    import_build_context_image_tar
  end
end

#build_path_empty?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/dapp/dimg/dapp/command/build_context/import.rb', line 68

def build_path_empty?
  (build_path.entries.map(&:to_s) - %w(. .. locks)).empty?
end

#import_build_context_build_tarObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dapp/dimg/dapp/command/build_context/import.rb', line 29

def import_build_context_build_tar
  if build_context_build_tar.exist?
    log_secondary_process(:build_dir, short: true) do
      unless dry_run?
        store_current_build_dir

        if !!options[:use_system_tar]
          FileUtils.mkpath build_path
          shellout!("tar -xf #{build_context_build_tar} -C #{build_path}")
        else
          tar_read(build_context_build_tar) do |tar|
            tar.each_entry do |entry|
              header = entry.header
              path = File.join(build_path, entry.full_name)

              if entry.directory?
                FileUtils.mkpath path, :mode => entry.header.mode
              else
                FileUtils.mkpath File.dirname(path)
                File.write(path, entry.read)
                File.chmod(header.mode, path)
              end
            end
          end
        end
      end
    end
  else
    log_warning(desc: { code: :context_archive_not_found, data: { path: build_context_build_tar } })
  end
end

#import_build_context_image_tarObject



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

def import_build_context_image_tar
  if build_context_images_tar.exist?
    log_secondary_process(:images) do
      lock("#{name}.images") do
        Image::Stage.load!(self, build_context_images_tar, verbose: true, quiet: log_quiet?)
      end unless dry_run?
    end
  else
    log_warning(desc: { code: :context_archive_not_found, data: { path: build_context_images_tar } })
  end
end

#store_current_build_dirObject



61
62
63
64
65
66
# File 'lib/dapp/dimg/dapp/command/build_context/import.rb', line 61

def store_current_build_dir
  return if build_path_empty?
  raise ::Dapp::Error::Command, code: :stored_build_dir_already_exist,
                                data: { path: "#{build_path}.old" } if File.exist?("#{build_path}.old")
  FileUtils.mv(build_path, "#{build_path}.old")
end