Merge branch 'main' into pr/155
* main: Describe purpose rather than elements Style and ordering #142 Allow to customize container options in accessories
This commit is contained in:
@@ -521,6 +521,9 @@ accessories:
|
|||||||
- MYSQL_ROOT_PASSWORD
|
- MYSQL_ROOT_PASSWORD
|
||||||
volumes:
|
volumes:
|
||||||
- /var/lib/mysql:/var/lib/mysql
|
- /var/lib/mysql:/var/lib/mysql
|
||||||
|
options:
|
||||||
|
cpus: 4
|
||||||
|
memory: "2GB"
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
host: 1.1.1.4
|
host: 1.1.1.4
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class Mrsk::Commands::Accessory < Mrsk::Commands::Base
|
class Mrsk::Commands::Accessory < Mrsk::Commands::Base
|
||||||
attr_reader :accessory_config
|
attr_reader :accessory_config
|
||||||
delegate :service_name, :image, :host, :port, :files, :directories, :publish_args, :env_args, :volume_args, :label_args, to: :accessory_config
|
delegate :service_name, :image, :host, :port, :files, :directories, :publish_args, :env_args, :volume_args,
|
||||||
|
:label_args, :option_args, to: :accessory_config
|
||||||
|
|
||||||
def initialize(config, name:)
|
def initialize(config, name:)
|
||||||
super(config)
|
super(config)
|
||||||
@@ -17,6 +18,7 @@ class Mrsk::Commands::Accessory < Mrsk::Commands::Base
|
|||||||
*env_args,
|
*env_args,
|
||||||
*volume_args,
|
*volume_args,
|
||||||
*label_args,
|
*label_args,
|
||||||
|
*option_args,
|
||||||
image
|
image
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
"--detach",
|
"--detach",
|
||||||
"--restart unless-stopped",
|
"--restart unless-stopped",
|
||||||
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
||||||
"--name", service_with_version_and_destination_and_role,
|
"--name", container_name,
|
||||||
"-e", "MRSK_CONTAINER_NAME=\"#{service_with_version_and_destination_and_role}\"",
|
"-e", "MRSK_CONTAINER_NAME=\"#{container_name}\"",
|
||||||
*role.env_args,
|
*role.env_args,
|
||||||
*config.volume_args,
|
*config.volume_args,
|
||||||
*role.label_args,
|
*role.label_args,
|
||||||
@@ -24,7 +24,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
docker :start, service_with_version_and_destination_and_role
|
docker :start, container_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def stop(version: nil)
|
def stop(version: nil)
|
||||||
@@ -59,7 +59,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
def execute_in_existing_container(*command, interactive: false)
|
def execute_in_existing_container(*command, interactive: false)
|
||||||
docker :exec,
|
docker :exec,
|
||||||
("-it" if interactive),
|
("-it" if interactive),
|
||||||
service_with_version_and_destination_and_role,
|
container_name,
|
||||||
*command
|
*command
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
|
|
||||||
def remove_container(version:)
|
def remove_container(version:)
|
||||||
pipe \
|
pipe \
|
||||||
container_id_for(container_name: service_with_version_and_destination_and_role(version)),
|
container_id_for(container_name: container_name(version)),
|
||||||
xargs(docker(:container, :rm))
|
xargs(docker(:container, :rm))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -122,12 +122,12 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
|||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
def service_with_version_and_destination_and_role(version = nil)
|
def container_name(version = nil)
|
||||||
[ config.service, role, config.destination, version || config.version ].compact.join("-")
|
[ config.service, role, config.destination, version || config.version ].compact.join("-")
|
||||||
end
|
end
|
||||||
|
|
||||||
def container_id_for_version(version)
|
def container_id_for_version(version)
|
||||||
container_id_for(container_name: service_with_version_and_destination_and_role(version))
|
container_id_for(container_name: container_name(version))
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_args
|
def filter_args
|
||||||
|
|||||||
@@ -32,26 +32,26 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tagged_record_line(line)
|
def tagged_record_line(line)
|
||||||
quote [recorded_at_tag, performer_tag, role_tag, line].compact.join(" ")
|
tagged_line recorded_at_tag, performer_tag, role_tag, line
|
||||||
end
|
end
|
||||||
|
|
||||||
def tagged_broadcast_line(line)
|
def tagged_broadcast_line(line)
|
||||||
quote [performer_tag, role_tag, line].compact.join(" ")
|
tagged_line performer_tag, role_tag, line
|
||||||
end
|
end
|
||||||
|
|
||||||
def role_tag
|
def tagged_line(*tags_and_line)
|
||||||
"[#{role}]" if role
|
"'#{tags_and_line.compact.join(" ")}'"
|
||||||
end
|
|
||||||
|
|
||||||
def performer_tag
|
|
||||||
"[#{`whoami`.strip}]"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def recorded_at_tag
|
def recorded_at_tag
|
||||||
"[#{Time.now.to_fs(:db)}]"
|
"[#{Time.now.to_fs(:db)}]"
|
||||||
end
|
end
|
||||||
|
|
||||||
def quote(tagged_line)
|
def performer_tag
|
||||||
"'#{tagged_line}'"
|
"[#{`whoami`.strip}]"
|
||||||
|
end
|
||||||
|
|
||||||
|
def role_tag
|
||||||
|
"[#{role}]" if role
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class Mrsk::Configuration::Accessory
|
class Mrsk::Configuration::Accessory
|
||||||
delegate :argumentize, :argumentize_env_with_secrets, to: Mrsk::Utils
|
delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils
|
||||||
|
|
||||||
attr_accessor :name, :specifics
|
attr_accessor :name, :specifics
|
||||||
|
|
||||||
@@ -67,6 +67,14 @@ class Mrsk::Configuration::Accessory
|
|||||||
argumentize "--volume", volumes
|
argumentize "--volume", volumes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def option_args
|
||||||
|
if args = specifics["options"]
|
||||||
|
optionize args
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
attr_accessor :config
|
attr_accessor :config
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,11 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
},
|
},
|
||||||
"volumes" => [
|
"volumes" => [
|
||||||
"/var/lib/redis:/data"
|
"/var/lib/redis:/data"
|
||||||
]
|
],
|
||||||
|
"options" => {
|
||||||
|
"cpus" => 4,
|
||||||
|
"memory" => "2GB"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,4 +108,8 @@ class ConfigurationAccessoryTest < ActiveSupport::TestCase
|
|||||||
test "directories" do
|
test "directories" do
|
||||||
assert_equal({"$PWD/app-mysql/data"=>"/var/lib/mysql"}, @config.accessory(:mysql).directories)
|
assert_equal({"$PWD/app-mysql/data"=>"/var/lib/mysql"}, @config.accessory(:mysql).directories)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "options" do
|
||||||
|
assert_equal ["--cpus", "\"4\"", "--memory", "\"2GB\""], @config.accessory(:redis).option_args
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user