Class: Kaiser::Kaiserfile

Inherits:
Object
  • Object
show all
Defined in:
lib/kaiser/kaiserfile.rb

Overview

This class is responsible for parsing the Kaiserfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Kaiserfile

Returns a new instance of Kaiserfile.



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

def initialize(filename)
  Optimist.die 'No Kaiserfile in current directory' unless File.exist? filename

  @database = {
    image: 'alpine',
    port: 1234,
    data_dir: '/tmp/data',
    params: '',
    commands: 'echo "no db"',
    waitscript: 'echo "no dbwait"',
    waitscript_params: ''
  }
  @attach_mounts = []
  @params_array = []
  @server_type = :unknown
  @database_reset_command = 'echo "no db to reset"'
  @port = 1234
  @services = {}

  instance_eval File.read(filename), filename
end

Instance Attribute Details

#attach_mountsObject

Returns the value of attribute attach_mounts.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def attach_mounts
  @attach_mounts
end

#databaseObject

Returns the value of attribute database.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def database
  @database
end

#database_reset_commandObject

Returns the value of attribute database_reset_command.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def database_reset_command
  @database_reset_command
end

#docker_build_argsObject

Returns the value of attribute docker_build_args.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def docker_build_args
  @docker_build_args
end

#docker_file_contentsObject

Returns the value of attribute docker_file_contents.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def docker_file_contents
  @docker_file_contents
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def port
  @port
end

#server_typeObject

Returns the value of attribute server_type.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def server_type
  @server_type
end

#servicesObject

Returns the value of attribute services.



6
7
8
# File 'lib/kaiser/kaiserfile.rb', line 6

def services
  @services
end

Instance Method Details

#app_params(value) ⇒ Object



79
80
81
# File 'lib/kaiser/kaiserfile.rb', line 79

def app_params(value)
  @params_array << value
end

#attach_mount(from, to) ⇒ Object



53
54
55
# File 'lib/kaiser/kaiserfile.rb', line 53

def attach_mount(from, to)
  attach_mounts << [from, to]
end

#db(image, data_dir:, port:, params: '', commands: '', waitscript: nil, waitscript_params: '') ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/kaiser/kaiserfile.rb', line 57

def db(image,
       data_dir:,
       port:,
       params: '',
       commands: '',
       waitscript: nil,
       waitscript_params: '')
  @database = {
    image: image,
    port: port,
    data_dir: data_dir,
    params: params,
    commands: commands,
    waitscript: waitscript,
    waitscript_params: waitscript_params
  }
end

#db_reset_command(value) ⇒ Object



87
88
89
# File 'lib/kaiser/kaiserfile.rb', line 87

def db_reset_command(value)
  @database_reset_command = value
end

#dockerfile(name, options = {}) ⇒ Object



48
49
50
51
# File 'lib/kaiser/kaiserfile.rb', line 48

def dockerfile(name, options = {})
  @docker_file_contents = File.read(name)
  @docker_build_args = options[:args] || {}
end

#expose(port) ⇒ Object



75
76
77
# File 'lib/kaiser/kaiserfile.rb', line 75

def expose(port)
  @port = port
end

#paramsObject



83
84
85
# File 'lib/kaiser/kaiserfile.rb', line 83

def params
  @params_array.join(' ')
end

#plugin(name) ⇒ Object



41
42
43
44
45
46
# File 'lib/kaiser/kaiserfile.rb', line 41

def plugin(name)
  require "kaiser/plugins/#{name}"
  raise "Plugin #{name} is not loaded." unless Plugin.loaded?(name)

  Plugin.all_plugins[name].new(self).on_init
end

#service(name, image: name) ⇒ Object



97
98
99
100
101
# File 'lib/kaiser/kaiserfile.rb', line 97

def service(name, image: name)
  raise "duplicate service #{name.inspect}" if @services.key?(name)

  @services[name] = { image: image }
end

#type(value) ⇒ Object



91
92
93
94
95
# File 'lib/kaiser/kaiserfile.rb', line 91

def type(value)
  raise 'Valid server types are: [:http]' if value != :http

  @server_type = value
end

#validate!Object



37
38
39
# File 'lib/kaiser/kaiserfile.rb', line 37

def validate!
  raise 'No dockerfile specified.' if @docker_file_contents.nil?
end