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

Raises:



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 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)


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

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
# 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
      store_current_build_dir

      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
  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, short: true) do
      lock("#{name}.images") do
        Image::Docker.load!(build_context_images_tar, verbose: true, quiet: log_quiet?)
      end
    end
  else
    log_warning(desc: { code: :context_archive_not_found, data: { path: build_context_images_tar } })
  end
end

#store_current_build_dirObject

Raises:



54
55
56
57
58
59
# File 'lib/dapp/dimg/dapp/command/build_context/import.rb', line 54

def store_current_build_dir
  return if build_path_empty?
  raise 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