From c83b74dcb74d4388555b0a8f6c426e68216c223a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 2 May 2023 13:11:31 +0200 Subject: [PATCH] Simplify domain language to just "boot" and unscoped config keys --- README.md | 8 ++++---- lib/mrsk/cli/app.rb | 2 +- lib/mrsk/commander.rb | 6 +++--- lib/mrsk/configuration/boot.rb | 9 +++++---- test/cli/app_test.rb | 2 +- test/commander_test.rb | 10 +++++----- ...roup_strategy.yml => deploy_with_boot_strategy.yml} | 4 ++-- ...gy.yml => deploy_with_precentage_boot_strategy.yml} | 4 ++-- 8 files changed, 23 insertions(+), 22 deletions(-) rename test/fixtures/{deploy_with_group_strategy.yml => deploy_with_boot_strategy.yml} (83%) rename test/fixtures/{deploy_with_precentage_group_strategy.yml => deploy_with_precentage_boot_strategy.yml} (82%) diff --git a/README.md b/README.md index 093d43bf..4cb298fa 100644 --- a/README.md +++ b/README.md @@ -835,17 +835,17 @@ 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` as boot options: +MRSK's default is to boot new containers on all hosts in parallel. But you can control this by configuring `boot/limit` and `boot/wait` as options: ```yaml service: myservice boot: - group_limit: 10 # Can also specify as a percentage of total hosts, such as "25%" - group_wait: 2 + limit: 10 # Can also specify as a percentage of total hosts, such as "25%" + 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. +When `limit` is specified, containers will be booted on, at most, `limit` hosts at once. MRSK will pause for `wait` seconds between batches. These settings only apply when booting containers (using `mrsk deploy`, or `mrsk app boot`). For other commands, MRSK continues to run commands in parallel across all hosts. diff --git a/lib/mrsk/cli/app.rb b/lib/mrsk/cli/app.rb index 7f6fbf44..3722ce6e 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.group_strategy) do |host| + on(MRSK.hosts, **MRSK.boot_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 160b619e..217918e6 100644 --- a/lib/mrsk/commander.rb +++ b/lib/mrsk/commander.rb @@ -51,9 +51,9 @@ 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 } + def boot_strategy + if config.boot.limit.present? + { in: :groups, limit: config.boot.limit, wait: config.boot.wait } else {} end diff --git a/lib/mrsk/configuration/boot.rb b/lib/mrsk/configuration/boot.rb index dd86b689..1332398a 100644 --- a/lib/mrsk/configuration/boot.rb +++ b/lib/mrsk/configuration/boot.rb @@ -4,8 +4,9 @@ class Mrsk::Configuration::Boot @host_count = config.all_hosts.count end - def group_limit - limit = @options["group_limit"] + def limit + limit = @options["limit"] + if limit.to_s.end_with?("%") @host_count * limit.to_i / 100 else @@ -13,7 +14,7 @@ class Mrsk::Configuration::Boot end end - def group_wait - @options["group_wait"] + def wait + @options["wait"] end end diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index dc2594b9..3dddb078 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -40,7 +40,7 @@ class CliAppTest < CliTestCase # Strategy is used when booting the containers Mrsk::Cli::App.any_instance.expects(:on).with([ "1.1.1.1" ], in: :groups, limit: 3, wait: 2).with_block_given - run_command("boot", config: :with_group_strategy) + run_command("boot", config: :with_boot_strategy) end test "start" do diff --git a/test/commander_test.rb b/test/commander_test.rb index e5fd2961..25dfabdd 100644 --- a/test/commander_test.rb +++ b/test/commander_test.rb @@ -55,19 +55,19 @@ class CommanderTest < ActiveSupport::TestCase end test "default group strategy" do - assert_empty @mrsk.group_strategy + assert_empty @mrsk.boot_strategy end test "specific limit group strategy" do - configure_with(:deploy_with_group_strategy) + configure_with(:deploy_with_boot_strategy) - assert_equal({ in: :groups, limit: 3, wait: 2 }, @mrsk.group_strategy) + assert_equal({ in: :groups, limit: 3, wait: 2 }, @mrsk.boot_strategy) end test "percentage-based group strategy" do - configure_with(:deploy_with_precentage_group_strategy) + configure_with(:deploy_with_precentage_boot_strategy) - assert_equal({ in: :groups, limit: 1, wait: 2 }, @mrsk.group_strategy) + assert_equal({ in: :groups, limit: 1, wait: 2 }, @mrsk.boot_strategy) end private diff --git a/test/fixtures/deploy_with_group_strategy.yml b/test/fixtures/deploy_with_boot_strategy.yml similarity index 83% rename from test/fixtures/deploy_with_group_strategy.yml rename to test/fixtures/deploy_with_boot_strategy.yml index 91ae3cc0..7691eb2e 100644 --- a/test/fixtures/deploy_with_group_strategy.yml +++ b/test/fixtures/deploy_with_boot_strategy.yml @@ -13,5 +13,5 @@ registry: password: pw boot: - group_limit: 3 - group_wait: 2 + limit: 3 + wait: 2 diff --git a/test/fixtures/deploy_with_precentage_group_strategy.yml b/test/fixtures/deploy_with_precentage_boot_strategy.yml similarity index 82% rename from test/fixtures/deploy_with_precentage_group_strategy.yml rename to test/fixtures/deploy_with_precentage_boot_strategy.yml index e738d07d..eb68a52f 100644 --- a/test/fixtures/deploy_with_precentage_group_strategy.yml +++ b/test/fixtures/deploy_with_precentage_boot_strategy.yml @@ -13,5 +13,5 @@ registry: password: pw boot: - group_limit: 25% - group_wait: 2 + limit: 25% + wait: 2