Work out the host and port for the container
Avoid docker inspect: 1. Use the container ID as the host 2. Configure the port, default to 3000
This commit is contained in:
@@ -44,7 +44,7 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
||||
|
||||
if role.running_traefik? && KAMAL.proxy_host?(host)
|
||||
version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
||||
endpoint = capture_with_info(*app.container_endpoint(version: version)).strip
|
||||
endpoint = capture_with_info(*app.container_id_for_version(version)).strip
|
||||
raise Kamal::Cli::BootError, "Failed to get endpoint for #{role} on #{host}, did the container boot?" if endpoint.empty?
|
||||
|
||||
execute *KAMAL.proxy.deploy(role.container_prefix, target: endpoint)
|
||||
@@ -66,7 +66,7 @@ class Kamal::Cli::App < Kamal::Cli::Base
|
||||
|
||||
if role.running_traefik? && KAMAL.proxy_host?(host)
|
||||
version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
||||
endpoint = capture_with_info(*app.container_endpoint(version: version)).strip
|
||||
endpoint = capture_with_info(*app.container_id_for_version(version)).strip
|
||||
if endpoint.present?
|
||||
execute *KAMAL.proxy.remove(role.container_prefix, target: endpoint), raise_on_non_zero_exit: false
|
||||
end
|
||||
|
||||
@@ -53,7 +53,7 @@ class Kamal::Cli::App::Boot
|
||||
if proxy_host?
|
||||
execute *app.run_for_proxy(hostname: hostname)
|
||||
if running_traefik?
|
||||
endpoint = capture_with_info(*app.container_endpoint(version: version)).strip
|
||||
endpoint = capture_with_info(*app.container_id_for_version(version)).strip
|
||||
raise Kamal::Cli::BootError, "Failed to get endpoint for #{role} on #{host}, did the container boot?" if endpoint.empty?
|
||||
execute *KAMAL.proxy.deploy(role.container_prefix, target: endpoint)
|
||||
else
|
||||
|
||||
@@ -52,7 +52,7 @@ class Kamal::Cli::Proxy < Kamal::Cli::Base
|
||||
app = KAMAL.app(role: role, host: host)
|
||||
|
||||
version = capture_with_info(*app.current_running_version, raise_on_non_zero_exit: false).strip
|
||||
endpoint = capture_with_info(*app.container_endpoint(version: version)).strip
|
||||
endpoint = capture_with_info(*app.container_id_for_version(version)).strip
|
||||
|
||||
if endpoint.present?
|
||||
info "Deploying #{endpoint} for role `#{role}` on #{host}..."
|
||||
|
||||
@@ -28,11 +28,4 @@ module Kamal::Commands::App::Containers
|
||||
container_id_for(container_name: container_name(version)),
|
||||
xargs(docker(:inspect, "--format", DOCKER_HEALTH_LOG_FORMAT))
|
||||
end
|
||||
|
||||
def container_endpoint(version:)
|
||||
pipe \
|
||||
container_id_for(container_name: container_name(version)),
|
||||
xargs(docker(:inspect, "--format", "'{{index .NetworkSettings.Networks.kamal.Aliases 0}}{{range $k, $v := .NetworkSettings.Ports}}{{printf \":%s\" $k}}{{break}}{{end}}'")),
|
||||
[ :sed, "-e", "'s/\\/tcp$//'" ]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Kamal::Commands::Proxy < Kamal::Commands::Base
|
||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||
delegate :container_name, to: :proxy_config
|
||||
delegate :container_name, :port, to: :proxy_config
|
||||
|
||||
attr_reader :proxy_config
|
||||
|
||||
@@ -35,11 +35,11 @@ class Kamal::Commands::Proxy < Kamal::Commands::Base
|
||||
end
|
||||
|
||||
def deploy(service, target:)
|
||||
docker :exec, container_name, "kamal-proxy", :deploy, service, *optionize({ target: target }), *proxy_config.deploy_command_args
|
||||
docker :exec, container_name, "kamal-proxy", :deploy, service, *optionize({ target: "#{target}:#{port}" }), *proxy_config.deploy_command_args
|
||||
end
|
||||
|
||||
def remove(service, target:)
|
||||
docker :exec, container_name, "kamal-proxy", :remove, service, *optionize({ target: target })
|
||||
docker :exec, container_name, "kamal-proxy", :remove, service, *optionize({ target: "#{target}:#{port}" })
|
||||
end
|
||||
|
||||
def info
|
||||
|
||||
@@ -56,6 +56,12 @@ proxy:
|
||||
# requests for other apps that do have a host set.
|
||||
host: foo.example.com
|
||||
|
||||
# Port
|
||||
#
|
||||
# The port the application is exposed on
|
||||
# Defaults to 80
|
||||
port: 3000
|
||||
|
||||
# SSL
|
||||
#
|
||||
# Kamal Proxy can automatically obtain and renew TLS certificates for your applications.
|
||||
|
||||
@@ -25,6 +25,10 @@ class Kamal::Configuration::Proxy
|
||||
end
|
||||
end
|
||||
|
||||
def port
|
||||
proxy_config.fetch("port", 80)
|
||||
end
|
||||
|
||||
def image
|
||||
proxy_config.fetch("image", DEFAULT_IMAGE)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user