Merge pull request #1020 from igor-alexandrov/network-args
Allow to override network
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
class Kamal::Commands::Accessory < Kamal::Commands::Base
|
class Kamal::Commands::Accessory < Kamal::Commands::Base
|
||||||
attr_reader :accessory_config
|
attr_reader :accessory_config
|
||||||
delegate :service_name, :image, :hosts, :port, :files, :directories, :cmd,
|
delegate :service_name, :image, :hosts, :port, :files, :directories, :cmd,
|
||||||
:publish_args, :env_args, :volume_args, :label_args, :option_args,
|
:network_args, :publish_args, :env_args, :volume_args, :label_args, :option_args,
|
||||||
:secrets_io, :secrets_path, :env_directory,
|
:secrets_io, :secrets_path, :env_directory,
|
||||||
to: :accessory_config
|
to: :accessory_config
|
||||||
|
|
||||||
@@ -15,7 +15,7 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
"--name", service_name,
|
"--name", service_name,
|
||||||
"--detach",
|
"--detach",
|
||||||
"--restart", "unless-stopped",
|
"--restart", "unless-stopped",
|
||||||
"--network", "kamal",
|
*network_args,
|
||||||
*config.logging_args,
|
*config.logging_args,
|
||||||
*publish_args,
|
*publish_args,
|
||||||
*env_args,
|
*env_args,
|
||||||
@@ -64,7 +64,7 @@ class Kamal::Commands::Accessory < Kamal::Commands::Base
|
|||||||
docker :run,
|
docker :run,
|
||||||
("-it" if interactive),
|
("-it" if interactive),
|
||||||
"--rm",
|
"--rm",
|
||||||
"--network", "kamal",
|
*network_args,
|
||||||
*env_args,
|
*env_args,
|
||||||
*volume_args,
|
*volume_args,
|
||||||
image,
|
image,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
class Kamal::Configuration::Accessory
|
class Kamal::Configuration::Accessory
|
||||||
include Kamal::Configuration::Validation
|
include Kamal::Configuration::Validation
|
||||||
|
|
||||||
|
DEFAULT_NETWORK = "kamal"
|
||||||
|
|
||||||
delegate :argumentize, :optionize, to: Kamal::Utils
|
delegate :argumentize, :optionize, to: Kamal::Utils
|
||||||
|
|
||||||
attr_reader :name, :accessory_config, :env
|
attr_reader :name, :accessory_config, :env
|
||||||
@@ -38,6 +40,10 @@ class Kamal::Configuration::Accessory
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def network_args
|
||||||
|
argumentize "--network", network
|
||||||
|
end
|
||||||
|
|
||||||
def publish_args
|
def publish_args
|
||||||
argumentize "--publish", port if port
|
argumentize "--publish", port if port
|
||||||
end
|
end
|
||||||
@@ -173,4 +179,8 @@ class Kamal::Configuration::Accessory
|
|||||||
accessory_config["roles"].flat_map { |role| config.role(role).hosts }
|
accessory_config["roles"].flat_map { |role| config.role(role).hosts }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def network
|
||||||
|
accessory_config["network"] || DEFAULT_NETWORK
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -90,3 +90,11 @@ accessories:
|
|||||||
# They are not created or copied before mounting:
|
# They are not created or copied before mounting:
|
||||||
volumes:
|
volumes:
|
||||||
- /path/to/mysql-logs:/var/log/mysql
|
- /path/to/mysql-logs:/var/log/mysql
|
||||||
|
|
||||||
|
# Network
|
||||||
|
#
|
||||||
|
# The network the accessory will be attached to.
|
||||||
|
#
|
||||||
|
# Defaults to kamal:
|
||||||
|
network: custom
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,14 @@ class CommandsAccessoryTest < ActiveSupport::TestCase
|
|||||||
new_command(:busybox).run.join(" ")
|
new_command(:busybox).run.join(" ")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "run in custom network" do
|
||||||
|
@config[:accessories]["mysql"]["network"] = "custom"
|
||||||
|
|
||||||
|
assert_equal \
|
||||||
|
"docker run --name app-mysql --detach --restart unless-stopped --network custom --log-opt max-size=\"10m\" --publish 3306:3306 --env MYSQL_ROOT_HOST=\"%\" --env-file .kamal/apps/app/env/accessories/mysql.env --label service=\"app-mysql\" private.registry/mysql:8.0",
|
||||||
|
new_command(:mysql).run.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
test "start" do
|
test "start" do
|
||||||
assert_equal \
|
assert_equal \
|
||||||
"docker container start app-mysql",
|
"docker container start app-mysql",
|
||||||
|
|||||||
@@ -152,4 +152,13 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
test "options" do
|
test "options" do
|
||||||
assert_equal [ "--cpus", "\"4\"", "--memory", "\"2GB\"" ], @config.accessory(:redis).option_args
|
assert_equal [ "--cpus", "\"4\"", "--memory", "\"2GB\"" ], @config.accessory(:redis).option_args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "network_args default" do
|
||||||
|
assert_equal [ "--network", "kamal" ], @config.accessory(:mysql).network_args
|
||||||
|
end
|
||||||
|
|
||||||
|
test "network_args with configured options" do
|
||||||
|
@deploy[:accessories]["mysql"]["network"] = "database"
|
||||||
|
assert_equal [ "--network", "database" ], @config.accessory(:mysql).network_args
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user