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
- #config_volume_map ⇒ Object
- #config_volumes ⇒ Object
- #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
#config_volume_map ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 16 def config_volume_map { proxy_config: { key: :proxy_conf_volume, default: "/etc/docker/nginx-proxy/proxy.conf", mount_path: "/etc/nginx/proxy.conf", }, conf_d_config: { key: :conf_d_volume, default: "/etc/docker/nginx-proxy/conf.d", mount_path: "/etc/nginx/conf.d", }, vhost_d_config: { key: :vhost_d_volume, default: "/etc/docker/nginx-proxy/vhost.d", mount_path: "/etc/nginx/vhost.d", }, share_config: { key: :share_volume, default: "/etc/docker/nginx-proxy/share", mount_path: "/etc/nginx/share", }, } end |
#config_volumes ⇒ Object
10 11 12 13 14 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 10 def config_volumes @config_volumes ||= config_volume_map.select do |config_volume| env.fetch(:"#{config_volume[:key]}_mount", true) || env.key?(:"#{config_volume[:key]}_location") end.map{|config_volume| "#{env.fetch(:"#{config_volume[:key]}_location", config_volume[:default])}:#{config_volume[:mount_path]}" } end |
#container_name ⇒ Object
61 62 63 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 61 def container_name @container_name ||= "#{env.fetch(:application)}_#{name}" end |
#environment ⇒ Object
53 54 55 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 53 def environment @environment ||= .fetch(:environment, {}) end |
#exposed_ports ⇒ Object
49 50 51 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 49 def exposed_ports @exposed_ports ||= [.fetch(:expose, [])].flatten - published_ports end |
#flags ⇒ Object
57 58 59 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 57 def flags @flags ||= .fetch(:flags, {}) end |
#image_name ⇒ Object
69 70 71 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 69 def image_name @image_name ||= "#{options.fetch(:repo)}:#{image_tag}" end |
#image_tag ⇒ Object
73 74 75 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 73 def image_tag @image_tag ||= .fetch(:tag, "#{env.fetch(:stage)}-#{env.fetch(:sha)}") end |
#letsencrypt_email ⇒ Object
89 90 91 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 89 def letsencrypt_email @letsencrypt_email ||= [:letsencrypt_email] end |
#letsencrypt_host ⇒ Object
85 86 87 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 85 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
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 101 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
93 94 95 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 93 def networks @networks ||= .fetch(:networks, []) end |
#published_ports ⇒ Object
45 46 47 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 45 def published_ports @published_ports ||= [.fetch(:publish, [])].flatten end |
#run_command(role) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 114 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
134 135 136 137 138 139 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 134 def run_commands(role) @run_commands ||= [ run_command(role), network_connect_commands(role), ].flatten end |
#startup_command ⇒ Object
97 98 99 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 97 def startup_command @startup_command ||= [:command] end |
#unique_container_name ⇒ Object
65 66 67 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 65 def unique_container_name @unique_container_name ||= "#{container_name}_#{env.fetch(:sha)}" end |
#virtual_host ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 77 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
41 42 43 |
# File 'lib/shiplane/deploy/container_configuration.rb', line 41 def volumes @volumes ||= .fetch(:volumes, []).concat(config_volumes).uniq end |