Class: Indocker::ImageDirectivesRunner

Inherits:
Object
  • Object
show all
Includes:
SmartIoC::Iocify
Defined in:
lib/indocker/directives/image_directives_runner.rb

Instance Method Summary collapse

Instance Method Details

#run(directive) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/indocker/directives/image_directives_runner.rb', line 14

def run(directive)
  case directive
  when Indocker::PrepareDirectives::DockerCp
    run_docker_cp(directive)
  when Indocker::DockerDirectives::Copy
    run_copy(directive)
  else
    # do nothing
  end
end

#run_all(directives) ⇒ Object



10
11
12
# File 'lib/indocker/directives/image_directives_runner.rb', line 10

def run_all(directives)
  directives.each {|c| run(c)}
end

#run_copy(directive) ⇒ Object



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/indocker/directives/image_directives_runner.rb', line 35

def run_copy(directive)
  directive.copy_actions.each do |from, to|
    build_dir_file = File.join(directive.context.build_dir, from)

    source_dir = File.join(config.root, from)
    
    if File.directory?(from)
      dest_dir = File.join(directive.context.build_dir, from)
    else
      dest_dir = File.join(directive.context.build_dir, File.dirname(from))
    end

    if File.exists?(build_dir_file) && File.file?(build_dir_file)
      copy_compile_file(
        from:    build_dir_file, 
        to:      build_dir_file, 
        locals:  directive.context.storage, 
        compile: directive.compile
      )

      return
    end
    
    if File.exist?(build_dir_file) && File.directory?(build_dir_file)
      files_list = Dir.glob(File.join(build_dir_file, '**', '*'), File::FNM_DOTMATCH)

      files_list.each do |from|
        copy_compile_file(
          from:    from, 
          to:      from, 
          locals:  directive.context.storage, 
          compile: directive.compile
        )
      end

      return
    end

    if File.exists?(source_dir) && File.file?(source_dir)
      copy_compile_file(
        from:    source_dir, 
        to:      File.join(dest_dir, File.basename(source_dir)), 
        locals:  directive.context.storage, 
        compile: directive.compile
      )

      return
    end

    if Dir.exist?(source_dir) && File.directory?(source_dir)
      files_list = Dir.glob(File.join(source_dir, '**', '*'), File::FNM_DOTMATCH)

      files_list.each do |from|
        relative_to = Pathname.new(from).relative_path_from( Pathname.new(source_dir) ).to_s
        absolute_to = File.join(dest_dir, relative_to)

        copy_compile_file(
          from:    from, 
          to:      absolute_to, 
          locals:  directive.context.storage, 
          compile: directive.compile
        )
      end

      return
    end

    raise Indocker::Errors::FileDoesNotExists
  end
end

#run_docker_cp(directive) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/indocker/directives/image_directives_runner.rb', line 25

def run_docker_cp(directive)
  directive.copy_actions.each do |from, to|
    container_manager.copy(
      name:      directive.container_name,
      copy_from: from,
      copy_to:   to
    )
  end
end