Merge pull request #222 from basecamp/deploy-groups
Allow booting containers in groups for rolling restarts
This commit is contained in:
@@ -40,6 +40,16 @@ class CliAppTest < CliTestCase
|
||||
Thread.report_on_exception = true
|
||||
end
|
||||
|
||||
test "boot uses group strategy when specified" do
|
||||
Mrsk::Cli::App.any_instance.stubs(:on).with("1.1.1.1").twice # acquire & release lock
|
||||
Mrsk::Cli::App.any_instance.stubs(:on).with([ "1.1.1.1" ]) # tag container
|
||||
|
||||
# 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_boot_strategy)
|
||||
end
|
||||
|
||||
test "start" do
|
||||
run_command("start").tap do |output|
|
||||
assert_match "docker start app-web-999", output
|
||||
@@ -158,7 +168,7 @@ class CliAppTest < CliTestCase
|
||||
end
|
||||
|
||||
private
|
||||
def run_command(*command)
|
||||
stdouted { Mrsk::Cli::App.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml", "--hosts", "1.1.1.1"]) }
|
||||
def run_command(*command, config: :with_accessories)
|
||||
stdouted { Mrsk::Cli::App.start([*command, "-c", "test/fixtures/deploy_#{config}.yml", "--hosts", "1.1.1.1"]) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,7 @@ require "test_helper"
|
||||
|
||||
class CommanderTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@mrsk = Mrsk::Commander.new.tap do |mrsk|
|
||||
mrsk.configure config_file: Pathname.new(File.expand_path("fixtures/deploy_with_roles.yml", __dir__))
|
||||
end
|
||||
configure_with(:deploy_with_roles)
|
||||
end
|
||||
|
||||
test "lazy configuration" do
|
||||
@@ -55,4 +53,27 @@ class CommanderTest < ActiveSupport::TestCase
|
||||
assert_equal [ "web" ], @mrsk.roles_on("1.1.1.1")
|
||||
assert_equal [ "workers" ], @mrsk.roles_on("1.1.1.3")
|
||||
end
|
||||
|
||||
test "default group strategy" do
|
||||
assert_empty @mrsk.boot_strategy
|
||||
end
|
||||
|
||||
test "specific limit group strategy" do
|
||||
configure_with(:deploy_with_boot_strategy)
|
||||
|
||||
assert_equal({ in: :groups, limit: 3, wait: 2 }, @mrsk.boot_strategy)
|
||||
end
|
||||
|
||||
test "percentage-based group strategy" do
|
||||
configure_with(:deploy_with_precentage_boot_strategy)
|
||||
|
||||
assert_equal({ in: :groups, limit: 1, wait: 2 }, @mrsk.boot_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
|
||||
|
||||
17
test/fixtures/deploy_with_boot_strategy.yml
vendored
Normal file
17
test/fixtures/deploy_with_boot_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:
|
||||
limit: 3
|
||||
wait: 2
|
||||
17
test/fixtures/deploy_with_precentage_boot_strategy.yml
vendored
Normal file
17
test/fixtures/deploy_with_precentage_boot_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:
|
||||
limit: 25%
|
||||
wait: 2
|
||||
Reference in New Issue
Block a user