Module: Docker::Template

Defined in:
lib/docker/template.rb,
lib/docker/template/cli.rb,
lib/docker/template/auth.rb,
lib/docker/template/meta.rb,
lib/docker/template/repo.rb,
lib/docker/template/cache.rb,
lib/docker/template/error.rb,
lib/docker/template/logger.rb,
lib/docker/template/notify.rb,
lib/docker/template/parser.rb,
lib/docker/template/builder.rb,
lib/docker/template/version.rb,
lib/docker/template/cli/list.rb,
lib/docker/template/cli/build.rb,
lib/docker/template/builder/normal.rb,
lib/docker/template/builder/rootfs.rb,
lib/docker/template/builder/scratch.rb

Defined Under Namespace

Modules: Auth, Cache, Error, Notify Classes: Builder, CLI, Logger, Meta, Parser, Repo

Constant Summary collapse

VERSION =
"0.14.0"

Class Method Summary collapse

Class Method Details

._require(what) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/docker/template.rb', line 78

def _require(what)
  require what
  if block_given?
    yield
  end

rescue LoadError
  $stderr.puts "The gem '#{what}' wasn't found."
  $stderr.puts "You can install it with `gem install #{what}'"
  abort "Hope you install it so you can report back."
end

.gem_rootObject



44
45
46
47
48
49
50
# File 'lib/docker/template.rb', line 44

def gem_root
  @gem_root ||= begin
    Pathutil.new("../../").expand_path(
      __dir__
    )
  end
end

.get(name, data = {}) ⇒ Object

– Pull a ‘template` from the `template_root` to parse it’s data. TODO: Rename this to get_template! –



65
66
67
68
69
70
71
72
73
74
# File 'lib/docker/template.rb', line 65

def get(name, data = {})
  data = ERB::Context.new(data)
  template = template_root.join("#{name}.erb").read unless name.is_a?(Pathutil)
  template = name.read if name.is_a?(Pathutil)
  template = ERB.new(template)

  return template.result(
    data._binding
  )
end

.project?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
# File 'lib/docker/template.rb', line 26

def project?
  dir = root.join("docker")
  any = Builder.all.dup.keep_if(&:projects_allowed?)
  any = any.map(&:files).reduce(&:|).any? { |file| root.join(file).file? }
  return true if any && root.join(Meta.opts_file(:force => \
    :project)).file?
end

.rootObject



36
37
38
39
40
# File 'lib/docker/template.rb', line 36

def root
  @root ||= begin
    Pathutil.new(Dir.pwd)
  end
end

.template_rootObject



54
55
56
57
58
# File 'lib/docker/template.rb', line 54

def template_root
  @template_root ||= begin
    gem_root.join("templates")
  end
end

.tmpdirObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/docker/template.rb', line 92

def tmpdir
  if ENV["DOCKER_TEMPLATE_TMPDIR"]
    # Don't destroy a user created directory.
    return Pathutil.new(ENV["DOCKER_TEMPLATE_TMPDIR"]).tap(
      &:mkdir_p
    )
  else
    dir = root.join("tmp")

    if !dir.exist?
      # Make the directory and then throw it out at exit.
      dir.mkdir_p; ObjectSpace.define_finalizer(dir, proc do
        dir.rm_rf
      end)
    end

    dir
  end
end