Class: Lucian::Engine
- Inherits:
-
Object
- Object
- Lucian::Engine
- Defined in:
- lib/lucian/engine.rb
Overview
Core module for Lucian framework is HERE !
Instance Attribute Summary collapse
-
#compose_data ⇒ Object
readonly
lucian_files.
-
#compose_directory ⇒ Object
readonly
lucian_files.
-
#compose_file ⇒ Object
readonly
lucian_files.
-
#docker_compose ⇒ Object
readonly
Returns the value of attribute docker_compose.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#network_name ⇒ Object
readonly
lucian_files.
-
#running_services ⇒ Object
readonly
Returns the value of attribute running_services.
Instance Method Summary collapse
-
#initialize(compose_file = nil, examples = []) ⇒ Engine
constructor
Initialize and fetch for compose file.
-
#run ⇒ Object
Run.
-
#run_docker_service(services_names = []) ⇒ Object
Run and validate services status.
-
#run_lucian_test(example) ⇒ Object
Run lucian test.
-
#shutdown ⇒ Object
Shutdown.
-
#start_lucian_docker ⇒ Object
Start lucian docker connect to compose.
-
#stop_docker_service(services_names) ⇒ Object
Stop docker service.
Constructor Details
#initialize(compose_file = nil, examples = []) ⇒ Engine
Initialize and fetch for compose file. if unable to find a docker-compose file then givving an error
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lucian/engine.rb', line 16 def initialize(compose_file = nil, examples = []) @compose_file = compose_file || fetch_docker_compose_file raise Error.new('Unable to find docker-compose.yml or docker-compose.yaml.') if (!@compose_file || !File.file?(@compose_file)) && ENV["LUCIAN_DOCKER"] == nil @compose_directory = File.(@compose_file+'/..') @compose_data = YAML.load_file(@compose_file) if ENV["LUCIAN_DOCKER"] == nil @lucian_directory = @compose_directory+'/'+DIRECTORY @lucian_helper = @lucian_directory+'/'+HELPER #@lucian_files = fetch_lucian_files(@lucian_directory) @network_name = File.basename(@compose_directory).gsub!(/[^0-9A-Za-z]?/, '')+"_default" if ENV["LUCIAN_DOCKER"] == nil $LOAD_PATH.unshift(@lucian_directory) unless $LOAD_PATH.include?(@lucian_directory) @docker_compose = Docker::Compose.new @examples = examples config_compose require 'lucian_helper' if File.exist?(@lucian_helper) @running_services ||= [] Lucian.engine = self end |
Instance Attribute Details
#compose_data ⇒ Object (readonly)
lucian_files
8 9 10 |
# File 'lib/lucian/engine.rb', line 8 def compose_data @compose_data end |
#compose_directory ⇒ Object (readonly)
lucian_files
8 9 10 |
# File 'lib/lucian/engine.rb', line 8 def compose_directory @compose_directory end |
#compose_file ⇒ Object (readonly)
lucian_files
8 9 10 |
# File 'lib/lucian/engine.rb', line 8 def compose_file @compose_file end |
#docker_compose ⇒ Object (readonly)
Returns the value of attribute docker_compose.
11 12 13 |
# File 'lib/lucian/engine.rb', line 11 def docker_compose @docker_compose end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
11 12 13 |
# File 'lib/lucian/engine.rb', line 11 def examples @examples end |
#network_name ⇒ Object (readonly)
lucian_files
8 9 10 |
# File 'lib/lucian/engine.rb', line 8 def network_name @network_name end |
#running_services ⇒ Object (readonly)
Returns the value of attribute running_services.
10 11 12 |
# File 'lib/lucian/engine.rb', line 10 def running_services @running_services end |
Instance Method Details
#run ⇒ Object
Run
36 37 38 39 40 |
# File 'lib/lucian/engine.rb', line 36 def run BoardCaster.print("Start running Lucian ..", "yellow") RSpec.lucian_engine = self Lucian::Runner.invoke(self) end |
#run_docker_service(services_names = []) ⇒ Object
Run and validate services status
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/lucian/engine.rb', line 56 def run_docker_service(services_names=[]) services_names.collect!(&:to_s) services_names = services_names - @running_services if services_names.count > 0 @docker_compose.up(*services_names, {:detached => true}) @running_services += services_names @running_services.uniq! exited = @docker_compose.ps.where { |c| !c.nil? && !c.up? && services_names.include?(c.image) } raise "We have some exited containers: " + exited.join(', ') if exited.count > 0 end end |
#run_lucian_test(example) ⇒ Object
Run lucian test
89 90 91 92 |
# File 'lib/lucian/engine.rb', line 89 def run_lucian_test(example) # BoardCaster.print("Running lucian test ..", "yellow") Lucian.container.exec(['lucian', '--example', example]) end |
#shutdown ⇒ Object
Shutdown
44 45 46 47 48 49 50 51 52 |
# File 'lib/lucian/engine.rb', line 44 def shutdown # NOTE Check if running in docker or not if ENV["LUCIAN_DOCKER"] == nil stop_lucian_container remove_lucian_container @docker_compose.down end # remove_lucian_image # NOTE Not sure we need to remove this or not end |
#start_lucian_docker ⇒ Object
Start lucian docker connect to compose
81 82 83 84 85 |
# File 'lib/lucian/engine.rb', line 81 def start_lucian_docker image = build_lucian_image container = run_lucian_image(image) connect_container_to_network(container) end |
#stop_docker_service(services_names) ⇒ Object
Stop docker service
70 71 72 73 74 75 76 77 |
# File 'lib/lucian/engine.rb', line 70 def stop_docker_service(services_names) if services_names.count > 0 puts "\n" @docker_compose.stop(*services_names) @running_services -= services_names @running_services.uniq! end end |