Class: KuberKit::ImageCompiler::ImageBuildDirCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/kuber_kit/image_compiler/image_build_dir_creator.rb

Instance Method Summary collapse

Instance Method Details

#cleanup(shell, build_dir) ⇒ Object



40
41
42
# File 'lib/kuber_kit/image_compiler/image_build_dir_creator.rb', line 40

def cleanup(shell, build_dir)
  bash_commands.rm_rf(shell, build_dir)
end

#create(shell, image, build_dir, context_helper: nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kuber_kit/image_compiler/image_build_dir_creator.rb', line 12

def create(shell, image, build_dir, context_helper: nil)
  bash_commands.rm_rf(shell, build_dir)
  bash_commands.mkdir_p(shell, build_dir)

  if image.build_context_dir
    # Sync build context and then preprocess
    shell.sync(image.build_context_dir, build_dir)

    shell.recursive_list_files(build_dir).each do |file_path|
      file_preprocessor.compile(
        shell, file_path, 
        context_helper: context_helper
      )
    end
  end

  # Sync dockerfile and then preprocess
  target_dockerfile = File.join(build_dir, configs.image_dockerfile_name)
  shell.sync(image.dockerfile_path, target_dockerfile)
  file_preprocessor.compile(
    shell, target_dockerfile,
    context_helper: context_helper
  )

  docker_ignore_content = configs.docker_ignore_list.join("\r\n")
  shell.write(File.join(build_dir, '.dockerignore'), docker_ignore_content)
end