Class: Indocker::Containers::ContainerBuilder
- Inherits:
-
Object
- Object
- Indocker::Containers::ContainerBuilder
- Defined in:
- lib/indocker/containers/container_builder.rb
Instance Attribute Summary collapse
-
#container ⇒ Object
readonly
Returns the value of attribute container.
Instance Method Summary collapse
- #after_deploy(proc) ⇒ Object
- #after_start(proc) ⇒ Object
- #before_start(proc) ⇒ Object
- #build_args(opts) ⇒ Object
- #command(name) ⇒ Object
- #daemonize(flag) ⇒ Object
- #depends_on(*container_list) ⇒ Object
- #image(name) ⇒ Object
-
#initialize(name:, configuration:, container: nil) ⇒ ContainerBuilder
constructor
A new instance of ContainerBuilder.
- #networks(*network_list) ⇒ Object
- #redeploy_schedule(schedule) ⇒ Object
- #scale(number) ⇒ Object
- #servers(*server_list) ⇒ Object
- #soft_depends_on(*container_list) ⇒ Object
- #start(opts) ⇒ Object
- #tags(*tag_list) ⇒ Object
- #volumes(*volume_list) ⇒ Object
Constructor Details
#initialize(name:, configuration:, container: nil) ⇒ ContainerBuilder
Returns a new instance of ContainerBuilder.
4 5 6 7 8 |
# File 'lib/indocker/containers/container_builder.rb', line 4 def initialize(name:, configuration:, container: nil) @container = container || Indocker::Containers::Container.new(name) @configuration = configuration configuration.add_container(@container) end |
Instance Attribute Details
#container ⇒ Object (readonly)
Returns the value of attribute container.
2 3 4 |
# File 'lib/indocker/containers/container_builder.rb', line 2 def container @container end |
Instance Method Details
#after_deploy(proc) ⇒ Object
167 168 169 170 |
# File 'lib/indocker/containers/container_builder.rb', line 167 def after_deploy(proc) container.set_after_deploy_proc(proc) self end |
#after_start(proc) ⇒ Object
162 163 164 165 |
# File 'lib/indocker/containers/container_builder.rb', line 162 def after_start(proc) container.set_after_start_proc(proc) self end |
#before_start(proc) ⇒ Object
157 158 159 160 |
# File 'lib/indocker/containers/container_builder.rb', line 157 def before_start(proc) container.set_before_start_proc(proc) self end |
#build_args(opts) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/indocker/containers/container_builder.rb', line 14 def build_args(opts) raise ArgumentError.new("build args should be a Hash") if !opts.is_a?(Hash) opts = Indocker::HashMerger.deep_merge(@container.build_args, opts) # merge with already defined args @container.set_build_args(opts) self end |
#command(name) ⇒ Object
10 11 12 |
# File 'lib/indocker/containers/container_builder.rb', line 10 def command(name) @container.set_start_command(name) end |
#daemonize(flag) ⇒ Object
102 103 104 105 |
# File 'lib/indocker/containers/container_builder.rb', line 102 def daemonize(flag) @container.daemonize(flag) self end |
#depends_on(*container_list) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/indocker/containers/container_builder.rb', line 107 def depends_on(*container_list) if !container_list.is_a?(Array) container_list = [container_list] end container_list.uniq! container_list.each do |name| path = Indocker.container_files.fetch(name) do Indocker.logger.error("Dependent container :#{name} was not found in bounded contexts dir for container :#{@container.name}") exit 1 end require path end containers = @configuration.containers.select do |container| container_list.include?(container.name) end containers.each do |container| @container.add_dependent_container(container) end self end |
#image(name) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/indocker/containers/container_builder.rb', line 30 def image(name) path = Indocker.image_files[name] if !path raise ArgumentError.new("Image :#{name} was not found in bounded contexts folder") else require path end image = @configuration.images.detect do |image| image.name == name end if !image Indocker.logger.error("image :#{name} was not found in configuration :#{@configuration.name}") exit 1 end @container.set_image(image) self end |
#networks(*network_list) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/indocker/containers/container_builder.rb', line 67 def networks(*network_list) network_list.uniq! networks = Indocker.networks.select do |network| network_list.include?(network.name) end extra_networks = network_list - networks.map(&:name) if !extra_networks.empty? raise ArgumentError.new("unknown networks: #{extra_networks.inspect} for container :#{@container.name}") end @container.set_networks(networks) self end |
#redeploy_schedule(schedule) ⇒ Object
182 183 184 185 |
# File 'lib/indocker/containers/container_builder.rb', line 182 def redeploy_schedule(schedule) container.set_redeploy_schedule(schedule) self end |
#scale(number) ⇒ Object
178 179 180 |
# File 'lib/indocker/containers/container_builder.rb', line 178 def scale(number) container.set_scale(number) end |
#servers(*server_list) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/indocker/containers/container_builder.rb', line 52 def servers(*server_list) server_list.uniq! extra_servers = server_list - Indocker.servers.map(&:name) if !extra_servers.empty? Indocker.logger.error("unrecognized servers #{extra_servers.inspect} for container :#{@container.name} in configuration :#{@configuration.name}") exit 1 end servers = Indocker.servers.select {|s| server_list.include?(s.name)} @container.set_servers(servers) self end |
#soft_depends_on(*container_list) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/indocker/containers/container_builder.rb', line 134 def soft_depends_on(*container_list) container_list = Array(container_list).uniq container_list.each do |name| path = Indocker.container_files.fetch(name) do Indocker.logger.error("Soft dependent container :#{name} was not found in bounded contexts dir for container :#{@container.name}") exit 1 end require path end containers = @configuration.containers.select do |container| container_list.include?(container.name) end containers.each do |container| @container.add_soft_dependent_container(container) end self end |
#start(opts) ⇒ Object
172 173 174 175 176 |
# File 'lib/indocker/containers/container_builder.rb', line 172 def start(opts) opts = Indocker::HashMerger.deep_merge(container., opts) container.(opts) self end |
#tags(*tag_list) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/indocker/containers/container_builder.rb', line 21 def (*tag_list) if !tag_list.is_a?(Array) tag_list = [tag_list] end @container.(tag_list) self end |
#volumes(*volume_list) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/indocker/containers/container_builder.rb', line 84 def volumes(*volume_list) volume_list.uniq! volumes = Indocker.volumes.select do |volume| volume_list.include?(volume.name) end extra_volumes = volume_list - volumes.map(&:name) if !extra_volumes.empty? raise Indocker.logger.error("unknown volumes: #{extra_volumes.inspect} for container :#{@container.name}") exit 1 end @container.set_volumes(volumes) self end |