Class: Shiplane::Deploy::ContainerConfiguration
- Inherits:
-
Configuration
- Object
- Configuration
- Shiplane::Deploy::ContainerConfiguration
- Defined in:
- lib/shiplane/deploy/container_configuration.rb
Instance Attribute Summary
Attributes inherited from Configuration
Instance Method Summary collapse
- #container_name ⇒ Object
- #environment ⇒ Object
- #exposed_ports ⇒ Object
- #flags ⇒ Object
- #image_name ⇒ Object
- #image_tag ⇒ Object
- #letsencrypt_email ⇒ Object
- #letsencrypt_host ⇒ Object
- #network_alias ⇒ Object
- #network_connect_commands(role) ⇒ Object
- #networks ⇒ Object
- #published_ports ⇒ Object
- #run_command(role) ⇒ Object
- #run_commands(role) ⇒ Object
- #startup_command ⇒ Object
- #unique_container_name ⇒ Object
- #virtual_host ⇒ Object
- #volumes ⇒ Object
Methods inherited from Configuration
Constructor Details
This class inherits a constructor from Shiplane::Deploy::Configuration
Instance Method Details
#container_name ⇒ Object
30 31 32 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 30 def container_name @container_name ||= "#{env.fetch(:application)}_#{name}" end |
#environment ⇒ Object
22 23 24 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 22 def environment @environment ||= .fetch(:environment, {}) end |
#exposed_ports ⇒ Object
18 19 20 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 18 def exposed_ports @exposed_ports ||= [.fetch(:expose, [])].flatten - published_ports end |
#flags ⇒ Object
26 27 28 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 26 def flags @flags ||= .fetch(:flags, {}) end |
#image_name ⇒ Object
38 39 40 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 38 def image_name @image_name ||= "#{.fetch(:repo)}:#{image_tag}" end |
#image_tag ⇒ Object
42 43 44 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 42 def image_tag @image_tag ||= .fetch(:tag, "#{env.fetch(:stage)}-#{env.fetch(:sha)}") end |
#letsencrypt_email ⇒ Object
58 59 60 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 58 def letsencrypt_email @letsencrypt_email ||= [:letsencrypt_email] end |
#letsencrypt_host ⇒ Object
54 55 56 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 54 def letsencrypt_host @letsencrypt_host ||= .fetch(:letsencrypt_host, virtual_host) end |
#network_alias ⇒ Object
6 7 8 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 6 def network_alias @network_alias ||= .fetch(:alias, container_name) end |
#network_connect_commands(role) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 70 def network_connect_commands(role) @network_commands ||= networks[1..-1].map do |network| [ docker_command(role), "network connect", "--alias #{network_alias}", network, unique_container_name, "|| true", ].flatten.compact.join(" ") end end |
#networks ⇒ Object
62 63 64 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 62 def networks @networks ||= .fetch(:networks, []) end |
#published_ports ⇒ Object
14 15 16 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 14 def published_ports @published_ports ||= [.fetch(:publish, [])].flatten end |
#run_command(role) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 83 def run_command(role) @command ||= [ docker_command(role), "run -d", volumes.map{|volume_set| "-v #{volume_set}" }, published_ports.map{|port| "-p #{port}" }, exposed_ports.map{|port| "--expose #{port}" }, "--name #{unique_container_name}", "--network=#{networks.first}", "--network-alias=#{network_alias}", virtual_host ? "-e VIRTUAL_HOST=#{virtual_host}" : nil, letsencrypt_host ? "-e LETSENCRYPT_HOST=#{letsencrypt_host}" : nil, letsencrypt_email ? "-e LETSENCRYPT_EMAIL=#{letsencrypt_email}" : nil, environment.map{ |key, value| "-e #{key}=#{value}" }, flags.map{ |key, value| "--#{key}=#{value}" }, image_name, startup_command ? startup_command : nil, ].flatten.compact.join(" ") end |
#run_commands(role) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 103 def run_commands(role) @run_commands ||= [ run_command(role), network_connect_commands(role), ].flatten end |
#startup_command ⇒ Object
66 67 68 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 66 def startup_command @startup_command ||= [:command] end |
#unique_container_name ⇒ Object
34 35 36 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 34 def unique_container_name @unique_container_name ||= "#{container_name}_#{env.fetch(:sha)}" end |
#virtual_host ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 46 def virtual_host return @virtual_host if defined?(@virtual_host) && @virtual_host if [:virtual_host] @virtual_host = [:virtual_host].is_a?(Proc) ? [:virtual_host].call : [:virtual_host] end end |
#volumes ⇒ Object
10 11 12 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 10 def volumes @volumes ||= .fetch(:volumes, []) end |