Class: Dockdev::Config
- Inherits:
-
Object
- Object
- Dockdev::Config
- Includes:
- TR::CondUtils
- Defined in:
- lib/dockdev/dockdev_config.rb
Overview
Content of the config file
which shall configure the to be run docker instance
Hence mostly the accessors/readers are related to docker configuration items
Instance Attribute Summary collapse
-
#activate_context ⇒ Object
readonly
since context activation is automated: 1.
-
#dockerfile_entries ⇒ Object
readonly
for image.
-
#mounts ⇒ Object
readonly
for container.
-
#network ⇒ Object
Returns the value of attribute network.
-
#ports ⇒ Object
readonly
for container.
-
#skip_context ⇒ Object
readonly
since context activation is automated: 1.
-
#workdir ⇒ Object
for image.
Instance Method Summary collapse
-
#add_mount(on_host, on_docker, opts = { duplicated_entry_policy: :error }) ⇒ Object
Add mount mapping of host => docker follows docker-cli which follows docker cli -v format.
-
#add_port(on_host, on_docker, opts = { duplicated_entry_policy: :error }) ⇒ Object
Add port mapping of host => docker follows docker-cli which follows docker cli -p format.
-
#append_Dockerfile(st) ⇒ Object
Any instruction to be appended into Dockerfile.
-
#initialize(val = {}) ⇒ Config
constructor
A new instance of Config.
- #is_context_should_skip?(name) ⇒ Boolean
- #manual_activated_context ⇒ Object
-
#to_storage ⇒ Object
Convert internal value into hash to be written to file to get rid of the object encoding in the yaml file.
Constructor Details
#initialize(val = {}) ⇒ Config
Returns a new instance of Config.
70 71 72 73 74 75 76 77 78 |
# File 'lib/dockdev/dockdev_config.rb', line 70 def initialize(val = {}) @mounts = val[:mounts] || {} @ports = val[:ports] || {} @network = val[:network] || nil @dockerfile_entries = val[:dockerfile_entries] || [] @workdir = val[:workdir] || "/opt" @skip_context = val[:skip_context] || [] @activate_context = val[:activate_context] || [] end |
Instance Attribute Details
#activate_context ⇒ Object (readonly)
since context activation is automated:
-
skip_context shall skip all found automated activated context
-
activate_context shall add those context which is not found by automated discovery
69 70 71 |
# File 'lib/dockdev/dockdev_config.rb', line 69 def activate_context @activate_context end |
#dockerfile_entries ⇒ Object (readonly)
for image
64 65 66 |
# File 'lib/dockdev/dockdev_config.rb', line 64 def dockerfile_entries @dockerfile_entries end |
#mounts ⇒ Object (readonly)
for container
60 61 62 |
# File 'lib/dockdev/dockdev_config.rb', line 60 def mounts @mounts end |
#network ⇒ Object
Returns the value of attribute network.
61 62 63 |
# File 'lib/dockdev/dockdev_config.rb', line 61 def network @network end |
#ports ⇒ Object (readonly)
for container
60 61 62 |
# File 'lib/dockdev/dockdev_config.rb', line 60 def ports @ports end |
#skip_context ⇒ Object (readonly)
since context activation is automated:
-
skip_context shall skip all found automated activated context
-
activate_context shall add those context which is not found by automated discovery
69 70 71 |
# File 'lib/dockdev/dockdev_config.rb', line 69 def skip_context @skip_context end |
#workdir ⇒ Object
for image
57 58 59 |
# File 'lib/dockdev/dockdev_config.rb', line 57 def workdir @workdir end |
Instance Method Details
#add_mount(on_host, on_docker, opts = { duplicated_entry_policy: :error }) ⇒ Object
Add mount mapping of host => docker follows docker-cli which follows
docker cli -v format
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 |
# File 'lib/dockdev/dockdev_config.rb', line 97 def add_mount(on_host, on_docker, opts = { duplicated_entry_policy: :error }) if not_empty?(on_host) and not_empty?(on_docker) if @mounts.keys.include?(on_host) policy = opts[:duplicated_entry_policy] || :error case policy when :warn_replace logger.warn "on_host '#{on_host}' was mapped to '#{@mounts[on_host]}'. It shall be replaced with '#{on_docker}'" @mounts[on_host] = on_docker when :warn_discard logger.warn "on_host '#{on_host}' already mapped to '#{@mounts[on_host]}'. New value on_docker is ignored." else # default policy always raise error raise Error, "on_host '#{on_host}' already mapped to '#{@mounts[on_host]}'" end else @mounts[on_host] = on_docker end else logger.debug "add_mount unsuccessful = on_host : #{on_host} / on_docker : #{on_docker}" raise Error, "on_host mount entry cannot be empty" if is_empty?(on_host) raise Error, "on_docker mount entry cannot be empty" if is_empty?(on_docker) end end |
#add_port(on_host, on_docker, opts = { duplicated_entry_policy: :error }) ⇒ Object
Add port mapping of host => docker follows docker-cli which follows
docker cli -p format
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/dockdev/dockdev_config.rb', line 133 def add_port(on_host, on_docker, opts = { duplicated_entry_policy: :error }) if not_empty?(on_host) and not_empty?(on_docker) if @ports.keys.include?(on_host) policy = opts[:duplicated_entry_policy] || :error case policy when :warn_replace logger.warn "on_host '#{on_host}' was mapped to '#{@mounts[on_host]}'. It shall be replaced with '#{on_docker}'" @ports[on_host] = on_docker when :warn_discard logger.warn "on_host '#{on_host}' already mapped to '#{@mounts[on_host]}'. New value on_docker is ignored." else # default policy always raise error raise Error, "on_host '#{on_host}' already mapped to '#{@mounts[on_host]}'" end else @ports[on_host] = on_docker end else logger.debug "add_port unsuccessful = on_host : #{on_host} / on_docker : #{on_docker}" raise Error, "on_host port entry cannot be empty" if is_empty?(on_host) raise Error, "on_docker port entry cannot be empty" if is_empty?(on_docker) end end |
#append_Dockerfile(st) ⇒ Object
Any instruction to be appended into Dockerfile.
Note this did not presume the entry is RUN, COPY or anyting.
A full valid Dockerfile entry has to be provided here
165 166 167 168 |
# File 'lib/dockdev/dockdev_config.rb', line 165 def append_Dockerfile(st) logger.debug "Appending : #{st}" @dockerfile_entries << st end |
#is_context_should_skip?(name) ⇒ Boolean
170 171 172 |
# File 'lib/dockdev/dockdev_config.rb', line 170 def is_context_should_skip?(name) @skip_context.include?(name) end |
#manual_activated_context ⇒ Object
175 176 177 |
# File 'lib/dockdev/dockdev_config.rb', line 175 def manual_activated_context @activate_context.freeze end |
#to_storage ⇒ Object
Convert internal value into hash to be written to file to get rid of the object
encoding in the yaml file
83 84 85 |
# File 'lib/dockdev/dockdev_config.rb', line 83 def to_storage { mounts: @mounts, ports: @ports, dockerfile_entries: @dockerfile_entries, workdir: @workdir, skip_context: @skip_context, activate_context: @activate_context } end |