Merge branch 'main' into pr/154
* main: (32 commits) Inline default as with other options Symbols! Fix tests test stop with custom stop wait time No need to replicate Docker default Describe purpose rather than elements Style and ordering Customizable stop wait time Fix tests Ensure it also works when configuring just log options without setting a driver Add accessory test Undo change Improve test Update README Ensure default log option `max-size=10m` #142 Allow to customize container options in accessories Fix flaky test Fix tests More resilient tests Fix other tests ...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
class Mrsk::Commands::Accessory < Mrsk::Commands::Base
|
||||
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:)
|
||||
super(config)
|
||||
@@ -12,11 +13,12 @@ class Mrsk::Commands::Accessory < Mrsk::Commands::Base
|
||||
"--name", service_name,
|
||||
"--detach",
|
||||
"--restart", "unless-stopped",
|
||||
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
||||
*config.logging_args,
|
||||
*publish_args,
|
||||
*env_args,
|
||||
*volume_args,
|
||||
*label_args,
|
||||
*option_args,
|
||||
image
|
||||
end
|
||||
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
def run(role: :web)
|
||||
role = config.role(role)
|
||||
attr_reader :role
|
||||
|
||||
def initialize(config, role: nil)
|
||||
super(config)
|
||||
@role = role
|
||||
end
|
||||
|
||||
def run
|
||||
role = config.role(self.role)
|
||||
|
||||
docker :run,
|
||||
"--detach",
|
||||
"--restart unless-stopped",
|
||||
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
||||
"--name", service_with_version_and_destination,
|
||||
"-e", "MRSK_CONTAINER_NAME=\"#{service_with_version_and_destination}\"",
|
||||
"--name", container_name,
|
||||
"-e", "MRSK_CONTAINER_NAME=\"#{container_name}\"",
|
||||
*role.env_args,
|
||||
*config.logging_args,
|
||||
*config.volume_args,
|
||||
*role.label_args,
|
||||
*role.option_args,
|
||||
@@ -17,13 +24,13 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
end
|
||||
|
||||
def start
|
||||
docker :start, service_with_version_and_destination
|
||||
docker :start, container_name
|
||||
end
|
||||
|
||||
def stop(version: nil)
|
||||
pipe \
|
||||
version ? container_id_for_version(version) : current_container_id,
|
||||
xargs(docker(:stop))
|
||||
xargs(config.stop_wait_time ? docker(:stop, "-t", config.stop_wait_time) : docker(:stop))
|
||||
end
|
||||
|
||||
def info
|
||||
@@ -52,7 +59,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
def execute_in_existing_container(*command, interactive: false)
|
||||
docker :exec,
|
||||
("-it" if interactive),
|
||||
service_with_version_and_destination,
|
||||
container_name,
|
||||
*command
|
||||
end
|
||||
|
||||
@@ -97,7 +104,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
|
||||
def remove_container(version:)
|
||||
pipe \
|
||||
container_id_for(container_name: service_with_version_and_destination(version)),
|
||||
container_id_for(container_name: container_name(version)),
|
||||
xargs(docker(:container, :rm))
|
||||
end
|
||||
|
||||
@@ -115,12 +122,12 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
|
||||
|
||||
private
|
||||
def service_with_version_and_destination(version = nil)
|
||||
[ config.service, config.destination, version || config.version ].compact.join("-")
|
||||
def container_name(version = nil)
|
||||
[ config.service, role, config.destination, version || config.version ].compact.join("-")
|
||||
end
|
||||
|
||||
def container_id_for_version(version)
|
||||
container_id_for(container_name: service_with_version_and_destination(version))
|
||||
container_id_for(container_name: container_name(version))
|
||||
end
|
||||
|
||||
def filter_args
|
||||
@@ -130,6 +137,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base
|
||||
def filters
|
||||
[ "label=service=#{config.service}" ].tap do |filters|
|
||||
filters << "label=destination=#{config.destination}" if config.destination
|
||||
filters << "label=role=#{role}" if role
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
require "active_support/core_ext/time/conversions"
|
||||
|
||||
class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
attr_reader :role
|
||||
|
||||
def initialize(config, role: nil)
|
||||
super(config)
|
||||
@role = role
|
||||
end
|
||||
|
||||
# Runs remotely
|
||||
def record(line)
|
||||
append \
|
||||
@@ -25,18 +32,26 @@ class Mrsk::Commands::Auditor < Mrsk::Commands::Base
|
||||
end
|
||||
|
||||
def tagged_record_line(line)
|
||||
"'#{recorded_at_tag} #{performer_tag} #{line}'"
|
||||
tagged_line recorded_at_tag, performer_tag, role_tag, line
|
||||
end
|
||||
|
||||
def tagged_broadcast_line(line)
|
||||
"'#{performer_tag} #{line}'"
|
||||
tagged_line performer_tag, role_tag, line
|
||||
end
|
||||
|
||||
def tagged_line(*tags_and_line)
|
||||
"'#{tags_and_line.compact.join(" ")}'"
|
||||
end
|
||||
|
||||
def recorded_at_tag
|
||||
"[#{Time.now.to_fs(:db)}]"
|
||||
end
|
||||
|
||||
def performer_tag
|
||||
"[#{`whoami`.strip}]"
|
||||
end
|
||||
|
||||
def recorded_at_tag
|
||||
"[#{Time.now.to_fs(:db)}]"
|
||||
def role_tag
|
||||
"[#{role}]" if role
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,8 +2,6 @@ module Mrsk::Commands
|
||||
class Base
|
||||
delegate :redact, :argumentize, to: Mrsk::Utils
|
||||
|
||||
MAX_LOG_SIZE = "10m"
|
||||
|
||||
attr_accessor :config
|
||||
|
||||
def initialize(config)
|
||||
|
||||
@@ -7,9 +7,9 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
||||
docker :run, "--name traefik",
|
||||
"--detach",
|
||||
"--restart", "unless-stopped",
|
||||
"--log-opt", "max-size=#{MAX_LOG_SIZE}",
|
||||
"--publish", port,
|
||||
"--volume", "/var/run/docker.sock:/var/run/docker.sock",
|
||||
*config.logging_args,
|
||||
*docker_options_args,
|
||||
"traefik",
|
||||
"--providers.docker",
|
||||
@@ -50,7 +50,7 @@ class Mrsk::Commands::Traefik < Mrsk::Commands::Base
|
||||
docker :image, :prune, "--all", "--force", "--filter", "label=org.opencontainers.image.title=Traefik"
|
||||
end
|
||||
|
||||
def port
|
||||
def port
|
||||
"#{host_port}:#{CONTAINER_PORT}"
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user