From a8726be20eda76c68f814c9abfa3854b694b7ecb Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Fri, 14 Apr 2023 11:01:25 +0100 Subject: [PATCH] Move `group_limit` & `group_wait` under `boot` Also make formatting the group strategy the responsibility of the commander. --- README.md | 7 ++++--- lib/mrsk/cli/app.rb | 2 +- lib/mrsk/commander.rb | 8 ++++++++ lib/mrsk/configuration.rb | 21 ++++---------------- lib/mrsk/configuration/boot.rb | 9 +++++++++ test/fixtures/deploy_with_group_strategy.yml | 5 +++-- 6 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 lib/mrsk/configuration/boot.rb diff --git a/README.md b/README.md index e3671f5c..9fcea1ed 100644 --- a/README.md +++ b/README.md @@ -835,13 +835,14 @@ mrsk lock release When deploying to large numbers of hosts, you might prefer not to restart your services on every host at the same time. -MRSK's default is to boot new containers on all hosts in parallel. But you can control this by configuring `group_limit` and `group_wait`. +MRSK's default is to boot new containers on all hosts in parallel. But you can control this by configuring `group_limit` and `group_wait` as boot options: ```yaml service: myservice -group_limit: 10 -group_wait: 30 +boot: + group_limit: 10 + group_wait: 2 ``` When `group_limit` is specified, containers will be booted on, at most, `group_limit` hosts at once. MRSK will pause for `group_wait` seconds between batches. diff --git a/lib/mrsk/cli/app.rb b/lib/mrsk/cli/app.rb index 735fef88..7f6fbf44 100644 --- a/lib/mrsk/cli/app.rb +++ b/lib/mrsk/cli/app.rb @@ -13,7 +13,7 @@ class Mrsk::Cli::App < Mrsk::Cli::Base execute *MRSK.app.tag_current_as_latest end - on(MRSK.hosts, **MRSK.config.group_strategy) do |host| + on(MRSK.hosts, **MRSK.group_strategy) do |host| roles = MRSK.roles_on(host) roles.each do |role| diff --git a/lib/mrsk/commander.rb b/lib/mrsk/commander.rb index 44c96a2a..160b619e 100644 --- a/lib/mrsk/commander.rb +++ b/lib/mrsk/commander.rb @@ -51,6 +51,14 @@ class Mrsk::Commander end end + def group_strategy + if config.boot.group_limit.present? + { in: :groups, limit: config.boot.group_limit, wait: config.boot.group_wait } + else + {} + end + end + def roles_on(host) roles.select { |role| role.hosts.include?(host.to_s) }.map(&:name) end diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index 388bcce4..c3415703 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -87,6 +87,10 @@ class Mrsk::Configuration roles.select(&:running_traefik?).flat_map(&:hosts).uniq end + def boot + Mrsk::Configuration::Boot.new(section: raw_config.boot) + end + def repository [ raw_config.registry["server"], image ].compact.join("/") @@ -153,15 +157,6 @@ class Mrsk::Configuration end - def group_strategy - if group_limit.present? - { in: :groups, limit: group_limit, wait: group_wait } - else - {} - end - end - - def audit_broadcast_cmd raw_config.audit_broadcast_cmd end @@ -246,12 +241,4 @@ class Mrsk::Configuration raise "Can't use commit hash as version, no git repository found in #{Dir.pwd}" end end - - def group_limit - raw_config.group_limit&.to_i - end - - def group_wait - raw_config.group_wait&.to_i - end end diff --git a/lib/mrsk/configuration/boot.rb b/lib/mrsk/configuration/boot.rb new file mode 100644 index 00000000..150f3d5f --- /dev/null +++ b/lib/mrsk/configuration/boot.rb @@ -0,0 +1,9 @@ +class Mrsk::Configuration::Boot + attr_reader :group_wait, :group_limit + + def initialize(section:) + section = section || {} + @group_limit = section["group_limit"] + @group_wait = section["group_wait"] + end +end diff --git a/test/fixtures/deploy_with_group_strategy.yml b/test/fixtures/deploy_with_group_strategy.yml index bc551f8a..a082f539 100644 --- a/test/fixtures/deploy_with_group_strategy.yml +++ b/test/fixtures/deploy_with_group_strategy.yml @@ -12,5 +12,6 @@ registry: username: user password: pw -group_limit: 3 -group_wait: 30 +boot: + group_limit: 3 + group_wait: 30