Class: Brick::Models::Project
- Inherits:
-
Object
- Object
- Brick::Models::Project
- Includes:
- Brick::Mixin::YamlHelper
- Defined in:
- lib/brick/models/project.rb
Instance Attribute Summary collapse
-
#docker_client ⇒ Object
Returns the value of attribute docker_client.
-
#insecure_registry ⇒ Object
Returns the value of attribute insecure_registry.
-
#name ⇒ Object
Returns the value of attribute name.
-
#recreate ⇒ Object
Returns the value of attribute recreate.
-
#services ⇒ Object
Returns the value of attribute services.
Instance Method Summary collapse
- #build_services(no_cache = false, project_dir = nil) ⇒ Object
- #get_service(name) ⇒ Object
- #get_services(service_name, inlcude_links = false) ⇒ Object
-
#init_services_from_config(config_file = nil) ⇒ Object
initialize the configuration of each service, and put it into services.
-
#initialize(project_name, options = {}, client = nil) ⇒ Project
constructor
A new instance of Project.
-
#run_services(service_name, enable_link = true) ⇒ Object
create the service according to the service name.
- #up(detach_mode = true, enable_link = true, recreate = false) ⇒ Object
Methods included from Brick::Mixin::YamlHelper
Constructor Details
#initialize(project_name, options = {}, client = nil) ⇒ Project
Returns a new instance of Project.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/brick/models/project.rb', line 13 def initialize(project_name ,={},client=nil) @name = project_name unless [:config_file].nil? @config_file = [:config_file] end @docker_client = client ? client : Brick::Docker::DockerClient::default init_services_from_config(@config_file) end |
Instance Attribute Details
#docker_client ⇒ Object
Returns the value of attribute docker_client.
11 12 13 |
# File 'lib/brick/models/project.rb', line 11 def docker_client @docker_client end |
#insecure_registry ⇒ Object
Returns the value of attribute insecure_registry.
11 12 13 |
# File 'lib/brick/models/project.rb', line 11 def insecure_registry @insecure_registry end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/brick/models/project.rb', line 11 def name @name end |
#recreate ⇒ Object
Returns the value of attribute recreate.
11 12 13 |
# File 'lib/brick/models/project.rb', line 11 def recreate @recreate end |
#services ⇒ Object
Returns the value of attribute services.
11 12 13 |
# File 'lib/brick/models/project.rb', line 11 def services @services end |
Instance Method Details
#build_services(no_cache = false, project_dir = nil) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/brick/models/project.rb', line 124 def build_services no_cache=false, project_dir=nil self.services.each_key{|key| service= services[key] if service.can_be_built? service.build("#{self.name}_#{key}",no_cache,project_dir) else ::Brick::CLI::logger.info("uses an image, skipping #{key}") end } end |
#get_service(name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/brick/models/project.rb', line 32 def get_service(name) service = nil unless @services.nil? service = @services[name] end service end |
#get_services(service_name, inlcude_links = false) ⇒ Object
28 29 30 |
# File 'lib/brick/models/project.rb', line 28 def get_services(service_name, inlcude_links=false) end |
#init_services_from_config(config_file = nil) ⇒ Object
initialize the configuration of each service, and put it into services
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/brick/models/project.rb', line 46 def init_services_from_config(config_file=nil) config_hash = load_yaml_file config_file # config = config_hash.to_ostruct @services = {} config_hash.each_key{|key| # @services << Service.new(key,eval("config.#{key}")) @services[key] =Service.new("#{@name}_#{key}_1",config_hash[key],@docker_client) } @services.each_key{|key| service = @services[key] service.update_links @services service.update_volumes_from @services service.update_image_for_building_tag("#{self.name}_#{key}") } end |
#run_services(service_name, enable_link = true) ⇒ Object
create the service according to the service name
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/brick/models/project.rb', line 95 def run_services(service_name, enable_link=true) service = @services[service_name] to_build = false if service.can_be_built? if service.image_exist? if ::Brick::Config[:rebuild] to_build=true else puts "The image #{service.image_name} already exists!" end else to_build = true end end if to_build service.build nil, true, ::Brick::Config[:project_dir] end raise ServicesNotFoundException.new("service #{service_name} is not found in #{@config_file}") if service.nil? service.run enable_link end |
#up(detach_mode = true, enable_link = true, recreate = false) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/brick/models/project.rb', line 68 def up(detach_mode = true, enable_link=true, recreate=false) self.services.each_key{|key| service= services[key] if service.container_exist? puts "Recreating #{service.name} ..." else puts "Creating #{service.name} ..." end if service.can_be_built? unless service.image_exist? # by default, not set cache service.build nil, true, ::Brick::Config[:project_dir] end end service.run enable_link, recreate, detach_mode } Service.wait_for_deamon end |