class Shiplane::Deploy::ContainerConfiguration

Public Instance Methods

container_name() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 30
def container_name
  @container_name ||= "#{env.fetch(:application)}_#{name}"
end
environment() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 22
def environment
  @environment ||= options.fetch(:environment, {})
end
exposed_ports() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 18
def exposed_ports
  @exposed_ports ||= [options.fetch(:expose, [])].flatten - published_ports
end
flags() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 26
def flags
  @flags ||= options.fetch(:flags, {})
end
image_name() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 38
def image_name
  @image_name ||= "#{options.fetch(:repo)}:#{image_tag}"
end
image_tag() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 42
def image_tag
  @image_tag ||= options.fetch(:tag, "#{env.fetch(:stage)}-#{env.fetch(:sha)}")
end
letsencrypt_email() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 58
def letsencrypt_email
  @letsencrypt_email ||= options[:letsencrypt_email]
end
letsencrypt_host() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 54
def letsencrypt_host
  @letsencrypt_host ||= options.fetch(:letsencrypt_host, virtual_host)
end
network_alias() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 6
def network_alias
  @network_alias ||= options.fetch(:alias, container_name)
end
network_connect_commands(role) click to toggle source
# 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() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 62
def networks
  @networks ||= options.fetch(:networks, [])
end
published_ports() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 14
def published_ports
  @published_ports ||= [options.fetch(:publish, [])].flatten
end
run_command(role) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 66
def startup_command
  @startup_command ||= options[:command]
end
unique_container_name() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 34
def unique_container_name
  @unique_container_name ||= "#{container_name}_#{env.fetch(:sha)}"
end
virtual_host() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 46
def virtual_host
  return @virtual_host if defined?(@virtual_host) && @virtual_host

  if options[:virtual_host]
    @virtual_host = options[:virtual_host].is_a?(Proc) ? options[:virtual_host].call : options[:virtual_host]
  end
end
volumes() click to toggle source
# File lib/shiplane/deploy/container_configuration.rb, line 10
def volumes
  @volumes ||= options.fetch(:volumes, [])
end