Class: Dockerun::Template::TemplateWriter

Inherits:
Object
  • Object
show all
Includes:
UserInfo
Defined in:
lib/dockerun/template/template_writer.rb

Direct Known Subclasses

GeneratlTemplateWriter, JrubyTemplateWriter

Defined Under Namespace

Classes: TemplateNotFound

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserInfo

#group_info, #user_info

Constructor Details

#initialize(template = :general) ⇒ TemplateWriter

Returns a new instance of TemplateWriter.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dockerun/template/template_writer.rb', line 28

def initialize(template = :general)
  @template = template
  @image = "<Replace me>"
  user = 
  group = group_info
  @maintainer = user[:login]
  @user_group_id = group[:group_id]
  @user_group_name = group[:group_name]
  @user_id = user[:user_id]
  @user_login = user[:login]
  @image_base = :ubuntu
  @match_user = TR::RTUtils.on_linux?
  @working_dir = "/opt"
end

Instance Attribute Details

#docker_init_file_pathObject

Returns the value of attribute docker_init_file_path.



16
17
18
# File 'lib/dockerun/template/template_writer.rb', line 16

def docker_init_file_path
  @docker_init_file_path
end

#imageObject

Returns the value of attribute image.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def image
  @image
end

#image_baseObject

Returns the value of attribute image_base.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def image_base
  @image_base
end

#maintainerObject

Returns the value of attribute maintainer.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def maintainer
  @maintainer
end

#match_userObject

Returns the value of attribute match_user.



17
18
19
# File 'lib/dockerun/template/template_writer.rb', line 17

def match_user
  @match_user
end

#user_configurablesObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dockerun/template/template_writer.rb', line 43

def user_configurables
  fields = {
    image: { desc: " Docker image name : ", required: true, type: :ask },
    image_base: { desc: " Docker image OS : ", default: :debian, type: :select, options: { debian: "Ubuntu/Debian based", not_sure: "Not sure which distro" }.invert },
    working_dir:  { desc: " Default directory after login : ", type: :ask, default: @working_dir }
  }

  if TR::RTUtils.on_linux?
    f2 = {
      match_user: { desc: " Match host user with docker user? ", type: :yes? },
      #maintainer: { desc: "Maintainer of the Dockerfile", default: @maintainer }

      #user_group_id: { desc: "User group ID that shall be created in docker. Default to current running user's ID", default: @user_group_id.to_s },
      #user_group_name: { desc: "User group name that shall be created in docker. Default to current running user's group", default: @user_group_name },
      #user_id: { desc: "User ID that shall be created in docker. Default to current running user ID", default: @user_id.to_s },
      #user_login: { desc: "User login name that shall be created in docker. Default to current running user's login", default: @user_login }
    }
    fields.merge!(f2)
  end
  fields
end

#user_group_idObject

Returns the value of attribute user_group_id.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def user_group_id
  @user_group_id
end

#user_group_nameObject

Returns the value of attribute user_group_name.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def user_group_name
  @user_group_name
end

#user_idObject

Returns the value of attribute user_id.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def user_id
  @user_id
end

#user_loginObject

Returns the value of attribute user_login.



14
15
16
# File 'lib/dockerun/template/template_writer.rb', line 14

def 
  @user_login
end

#working_dirObject

Returns the value of attribute working_dir.



17
18
19
# File 'lib/dockerun/template/template_writer.rb', line 17

def working_dir
  @working_dir
end

Class Method Details

.instance(template) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/dockerun/template/template_writer.rb', line 19

def self.instance(template)
  tmp = template.to_s.downcase
  if tmp =~ /jruby/
    JrubyTemplateWriter.new
  else
    TemplateWriter.new
  end
end

Instance Method Details

#compile(&block) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/dockerun/template/template_writer.rb', line 65

def compile(&block)

  if not_empty?(@user_configurables)
    @user_configurables.each do |k,v|
      begin
        self.send("#{k}=", v)
      rescue Exception => ex
        STDERR.puts "Setting value exception : #{ex}"
      end
    end
  end

  tmp = find_template
  cont = nil
  File.open(tmp,"r") do |f|
    cont = f.read
  end

  b = binding

  res = ERB.new(cont)
  res.result(b)
end