class Kaiser::Kaiserfile

This class is responsible for parsing the Kaiserfile

Attributes

attach_mounts[RW]
database[RW]
database_reset_command[RW]
docker_build_args[RW]
docker_file_contents[RW]
port[RW]
server_type[RW]
services[RW]

Public Class Methods

new(filename) click to toggle source
# 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

Public Instance Methods

app_params(value) click to toggle source
# File lib/kaiser/kaiserfile.rb, line 79
def app_params(value)
  @params_array << value
end
attach_mount(from, to) click to toggle source
# 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: '') click to toggle source
# 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) click to toggle source
# File lib/kaiser/kaiserfile.rb, line 87
def db_reset_command(value)
  @database_reset_command = value
end
dockerfile(name, options = {}) click to toggle source
# 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) click to toggle source
# File lib/kaiser/kaiserfile.rb, line 75
def expose(port)
  @port = port
end
params() click to toggle source
# File lib/kaiser/kaiserfile.rb, line 83
def params
  @params_array.join(' ')
end
plugin(name) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/kaiser/kaiserfile.rb, line 91
def type(value)
  raise 'Valid server types are: [:http]' if value != :http

  @server_type = value
end
validate!() click to toggle source
# File lib/kaiser/kaiserfile.rb, line 37
def validate!
  raise 'No dockerfile specified.' if @docker_file_contents.nil?
end