Allow percentage-based rolling deployments
This commit is contained in:
@@ -841,7 +841,7 @@ MRSK's default is to boot new containers on all hosts in parallel. But you can c
|
|||||||
service: myservice
|
service: myservice
|
||||||
|
|
||||||
boot:
|
boot:
|
||||||
group_limit: 10
|
group_limit: 10 # Can also specify as a percentage of total hosts, such as "25%"
|
||||||
group_wait: 2
|
group_wait: 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class Mrsk::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
Mrsk::Configuration::Boot.new(section: raw_config.boot)
|
Mrsk::Configuration::Boot.new(config: self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,19 @@
|
|||||||
class Mrsk::Configuration::Boot
|
class Mrsk::Configuration::Boot
|
||||||
attr_reader :group_wait, :group_limit
|
def initialize(config:)
|
||||||
|
@options = config.raw_config.boot || {}
|
||||||
|
@host_count = config.all_hosts.count
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(section:)
|
def group_limit
|
||||||
section = section || {}
|
limit = @options["group_limit"]
|
||||||
@group_limit = section["group_limit"]
|
if limit.to_s.end_with?("%")
|
||||||
@group_wait = section["group_wait"]
|
@host_count * limit.to_i / 100
|
||||||
|
else
|
||||||
|
limit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def group_wait
|
||||||
|
@options["group_wait"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class CliAppTest < CliTestCase
|
|||||||
Mrsk::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
Mrsk::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
||||||
|
|
||||||
# Strategy is used when booting the containers
|
# Strategy is used when booting the containers
|
||||||
Mrsk::Cli::App.any_instance.expects(:on).with([ "1.1.1.1" ], in: :groups, limit: 3, wait: 30).with_block_given
|
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_group_strategy)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ require "test_helper"
|
|||||||
|
|
||||||
class CommanderTest < ActiveSupport::TestCase
|
class CommanderTest < ActiveSupport::TestCase
|
||||||
setup do
|
setup do
|
||||||
@mrsk = Mrsk::Commander.new.tap do |mrsk|
|
configure_with(:deploy_with_roles)
|
||||||
mrsk.configure config_file: Pathname.new(File.expand_path("fixtures/deploy_with_roles.yml", __dir__))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "lazy configuration" do
|
test "lazy configuration" do
|
||||||
@@ -55,4 +53,27 @@ class CommanderTest < ActiveSupport::TestCase
|
|||||||
assert_equal [ "web" ], @mrsk.roles_on("1.1.1.1")
|
assert_equal [ "web" ], @mrsk.roles_on("1.1.1.1")
|
||||||
assert_equal [ "workers" ], @mrsk.roles_on("1.1.1.3")
|
assert_equal [ "workers" ], @mrsk.roles_on("1.1.1.3")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "default group strategy" do
|
||||||
|
assert_empty @mrsk.group_strategy
|
||||||
|
end
|
||||||
|
|
||||||
|
test "specific limit group strategy" do
|
||||||
|
configure_with(:deploy_with_group_strategy)
|
||||||
|
|
||||||
|
assert_equal({ in: :groups, limit: 3, wait: 2 }, @mrsk.group_strategy)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "percentage-based group strategy" do
|
||||||
|
configure_with(:deploy_with_precentage_group_strategy)
|
||||||
|
|
||||||
|
assert_equal({ in: :groups, limit: 1, wait: 2 }, @mrsk.group_strategy)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def configure_with(variant)
|
||||||
|
@mrsk = Mrsk::Commander.new.tap do |mrsk|
|
||||||
|
mrsk.configure config_file: Pathname.new(File.expand_path("fixtures/#{variant}.yml", __dir__))
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
2
test/fixtures/deploy_with_group_strategy.yml
vendored
2
test/fixtures/deploy_with_group_strategy.yml
vendored
@@ -14,4 +14,4 @@ registry:
|
|||||||
|
|
||||||
boot:
|
boot:
|
||||||
group_limit: 3
|
group_limit: 3
|
||||||
group_wait: 30
|
group_wait: 2
|
||||||
|
|||||||
17
test/fixtures/deploy_with_precentage_group_strategy.yml
vendored
Normal file
17
test/fixtures/deploy_with_precentage_group_strategy.yml
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
service: app
|
||||||
|
image: dhh/app
|
||||||
|
servers:
|
||||||
|
web:
|
||||||
|
- "1.1.1.1"
|
||||||
|
- "1.1.1.2"
|
||||||
|
workers:
|
||||||
|
- "1.1.1.3"
|
||||||
|
- "1.1.1.4"
|
||||||
|
|
||||||
|
registry:
|
||||||
|
username: user
|
||||||
|
password: pw
|
||||||
|
|
||||||
|
boot:
|
||||||
|
group_limit: 25%
|
||||||
|
group_wait: 2
|
||||||
Reference in New Issue
Block a user