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.



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

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

  @database = {
    image: 'none',
    platform: '',
    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

#platformObject

Returns the value of attribute platform.



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

def platform
  @platform
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



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

def app_params(value)
  @params_array << value
end

#attach_mount(from, to) ⇒ Object



55
56
57
# File 'lib/kaiser/kaiserfile.rb', line 55

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

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



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

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

#db_reset_command(value) ⇒ Object



95
96
97
# File 'lib/kaiser/kaiserfile.rb', line 95

def db_reset_command(value)
  @database_reset_command = value
end

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



50
51
52
53
# File 'lib/kaiser/kaiserfile.rb', line 50

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

#expose(port) ⇒ Object



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

def expose(port)
  @port = port
end

#force_platform(platform_name) ⇒ Object



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

def force_platform(platform_name)
  @platform = platform_name
end

#paramsObject



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

def params
  @params_array.join(' ')
end

#plugin(name) ⇒ Object



43
44
45
46
47
48
# File 'lib/kaiser/kaiserfile.rb', line 43

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, command: nil, binds: {}, env: {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/kaiser/kaiserfile.rb', line 105

def service(name,
            image: name,
            command: nil,
            binds: {},
            env: {})

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

  @services[name] = {
    image: image,
    command: command,
    binds: binds,
    env: env
  }
end

#type(value) ⇒ Object



99
100
101
102
103
# File 'lib/kaiser/kaiserfile.rb', line 99

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

  @server_type = value
end

#validate!Object



39
40
41
# File 'lib/kaiser/kaiserfile.rb', line 39

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