Class: Egg::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/egg/configuration.rb

Overview

Reads and Processes the egg_config.rb file.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&configuration_block) ⇒ Configuration

Returns a new instance of Configuration.



33
34
35
36
37
38
39
40
# File 'lib/egg/configuration.rb', line 33

def initialize(&configuration_block)
  self.docker_compose = DockerCompose.new
  self.ssh_support = false
  self.ruby_version = "2.4"
  self.dotenv = DotenvUtil.new(File.read(".env.template"))
  instance_eval(&configuration_block)
  self
end

Instance Attribute Details

#docker_composeObject

Returns the value of attribute docker_compose.



26
27
28
# File 'lib/egg/configuration.rb', line 26

def docker_compose
  @docker_compose
end

#dockerfileObject

Returns the value of attribute dockerfile.



26
27
28
# File 'lib/egg/configuration.rb', line 26

def dockerfile
  @dockerfile
end

#dotenvObject

Returns the value of attribute dotenv.



26
27
28
# File 'lib/egg/configuration.rb', line 26

def dotenv
  @dotenv
end

#ruby_versionObject

Returns the value of attribute ruby_version.



26
27
28
# File 'lib/egg/configuration.rb', line 26

def ruby_version
  @ruby_version
end

#ssh_supportObject

Returns the value of attribute ssh_support.



26
27
28
# File 'lib/egg/configuration.rb', line 26

def ssh_support
  @ssh_support
end

#supervisorObject

Returns the value of attribute supervisor.



26
27
28
# File 'lib/egg/configuration.rb', line 26

def supervisor
  @supervisor
end

Class Method Details

.load(file) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/egg/configuration.rb', line 14

def self.load(file)
  code = File.read file
  config = eval code, binding, file # rubocop:disable Security/Eval

  return config if config.is_a? Egg::Configuration
rescue SignalException, SystemExit
  raise
rescue SyntaxError, StandardError => e
  warn "Invalid configuration in [#{file}]: #{e}"
  warn e.backtrace.join("\n")
end

Instance Method Details

#after_startup(&block) ⇒ Object



42
43
44
# File 'lib/egg/configuration.rb', line 42

def after_startup(&block)
  @after_startup = block
end

#docker_exec(app, command) ⇒ Object

You may pass a block to docker_exec to read the output in a controlled manner.



47
48
49
50
51
52
53
54
55
# File 'lib/egg/configuration.rb', line 47

def docker_exec(app, command)
  print "docker-compose exec #{app} #{command}\n"
  Open3.popen2(%(docker-compose exec #{app} #{command})) do |_input, output, wait_thread|
    output_read = output.read
    print output_read + "\n"
    yield output_read if block_given?
    wait_thread.value.success? || raise(StandardError, "docker_exec exited with #{wait_thread.value.to_i}")
  end
end

#run_setupObject



57
58
59
60
61
62
63
64
65
# File 'lib/egg/configuration.rb', line 57

def run_setup
  write_docker_files

  docker_pull_build
  File.write(".env", dotenv.generate_env)
  system("docker-compose up -d")

  run_after_startup
end