Module: Docker::Template::Cache

Defined in:
lib/docker/template/cache.rb

Class Method Summary collapse

Class Method Details

.cleanup(repo) ⇒ Object


Cleanup the context caches, removing the caches we no longer need.




42
43
44
45
46
47
48
49
50
51
52
# File 'lib/docker/template/cache.rb', line 42

def cleanup(repo)
  repo.cache_dir.parent.children.each do |file|
    unless repo..tags.include?(file.basename)
      $stdout.puts Simple::Ansi.yellow("Removing %s." % [
        file.relative_path_from(Template.root)
      ])

      file.rm_rf
    end
  end
end

.context(builder, context) ⇒ Object


Cache the context into the cache directory.




16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/docker/template/cache.rb', line 16

def context(builder, context)
  if builder.alias? && builder.aliased_repo.cache_dir.exist?
    parent_cache_dir = builder.aliased_repo.cache_dir
    $stderr.puts Simple::Ansi.yellow("Copying #{builder.aliased_repo} context to #{builder.repo}")
    cache_dir = builder.repo.cache_dir

    parent_cache_dir.cp_r(cache_dir.tap(
      &:rm_rf
    ))
  elsif context
    builder.repo.cache_dir.rm_rf
    $stderr.puts Simple::Ansi.yellow("Copying context for #{builder.repo}")
    cache_dir = builder.repo.cache_dir
    cache_dir.parent.mkdir_p

    readme(builder)
    context.cp_r(cache_dir.tap(
      &:rm_rf
    ))
  end
end

.readme(builder) ⇒ Object


Note: We normally expect but do not require you to have a README. Search for and copy the readme if available.




59
60
61
62
63
64
65
66
67
68
# File 'lib/docker/template/cache.rb', line 59

def readme(builder)
  file = builder.repo.root.children.find do |val|
    val =~ /readme/i
  end

  return unless file
  file.safe_copy(builder.repo.cache_dir, {
    :root => file.parent
  })
end