Add KAMAL_HOST to app and accessory containers
Adds the host the container is being deployed to as KAMAL_HOST. My use case is to more easily tag the host for metrics tagging, but there might be other uses as well.
This commit is contained in:
@@ -13,11 +13,11 @@ class Kamal::Cli::Accessory < Kamal::Cli::Base
|
|||||||
directories(name)
|
directories(name)
|
||||||
upload(name)
|
upload(name)
|
||||||
|
|
||||||
on(hosts) do
|
on(hosts) do |host|
|
||||||
execute *KAMAL.auditor.record("Booted #{name} accessory"), verbosity: :debug
|
execute *KAMAL.auditor.record("Booted #{name} accessory"), verbosity: :debug
|
||||||
execute *accessory.ensure_env_directory
|
execute *accessory.ensure_env_directory
|
||||||
upload! accessory.secrets_io, accessory.secrets_path, mode: "0600"
|
upload! accessory.secrets_io, accessory.secrets_path, mode: "0600"
|
||||||
execute *accessory.run
|
execute *accessory.run(host: host)
|
||||||
|
|
||||||
if accessory.running_proxy?
|
if accessory.running_proxy?
|
||||||
target = capture_with_info(*accessory.container_id_for(container_name: accessory.service_name, only_running: true)).strip
|
target = capture_with_info(*accessory.container_id_for(container_name: accessory.service_name, only_running: true)).strip
|
||||||
|
|||||||
@@ -13,11 +13,12 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
@accessory_config = config.accessory(name)
|
@accessory_config = config.accessory(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run(host: nil)
|
||||||
docker :run,
|
docker :run,
|
||||||
"--name", service_name,
|
"--name", service_name,
|
||||||
"--detach",
|
"--detach",
|
||||||
"--restart", "unless-stopped",
|
"--restart", "unless-stopped",
|
||||||
|
*([ "-e", "KAMAL_HOST=\"#{host}\"" ] if host),
|
||||||
*network_args,
|
*network_args,
|
||||||
*config.logging_args,
|
*config.logging_args,
|
||||||
*publish_args,
|
*publish_args,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class Kamal::Commands::App < Kamal::Commands::Base
|
|||||||
*([ "--hostname", hostname ] if hostname),
|
*([ "--hostname", hostname ] if hostname),
|
||||||
"-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
|
"-e", "KAMAL_CONTAINER_NAME=\"#{container_name}\"",
|
||||||
"-e", "KAMAL_VERSION=\"#{config.version}\"",
|
"-e", "KAMAL_VERSION=\"#{config.version}\"",
|
||||||
|
"-e", "KAMAL_HOST=\"#{host}\"",
|
||||||
*role.env_args(host),
|
*role.env_args(host),
|
||||||
*role.logging_args,
|
*role.logging_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
|
|||||||
Reference in New Issue
Block a user