Merge pull request #146 from basecamp/tell-me-more
Deploys mention the service and version
This commit is contained in:
@@ -40,7 +40,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
invoke "mrsk:cli:prune:all", [], invoke_options
|
invoke "mrsk:cli:prune:all", [], invoke_options
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Deployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
|
audit_broadcast "Deployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
desc "redeploy", "Deploy app to servers without bootstrapping servers, starting Traefik, pruning, and registry login"
|
||||||
@@ -63,7 +63,7 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
invoke "mrsk:cli:app:boot", [], invoke_options
|
invoke "mrsk:cli:app:boot", [], invoke_options
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Redeployed app in #{runtime.to_i} seconds" unless options[:skip_broadcast]
|
audit_broadcast "Redeployed #{service_version} in #{runtime.round} seconds" unless options[:skip_broadcast]
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "rollback [VERSION]", "Rollback app to VERSION"
|
desc "rollback [VERSION]", "Rollback app to VERSION"
|
||||||
@@ -74,18 +74,21 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
say "Start version #{version}, then wait #{MRSK.config.readiness_delay}s for app to boot before stopping the old version...", :magenta
|
say "Start version #{version}, then wait #{MRSK.config.readiness_delay}s for app to boot before stopping the old version...", :magenta
|
||||||
|
|
||||||
cli = self
|
cli = self
|
||||||
|
old_version = nil
|
||||||
|
|
||||||
on(MRSK.hosts) do |host|
|
on(MRSK.hosts) do |host|
|
||||||
old_version = capture_with_info(*MRSK.app.current_running_version).strip.presence
|
old_version = capture_with_info(*MRSK.app.current_running_version).strip.presence
|
||||||
|
|
||||||
execute *MRSK.app.start
|
execute *MRSK.app.start
|
||||||
|
|
||||||
sleep MRSK.config.readiness_delay
|
if old_version
|
||||||
|
sleep MRSK.config.readiness_delay
|
||||||
|
|
||||||
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false
|
execute *MRSK.app.stop(version: old_version), raise_on_non_zero_exit: false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
audit_broadcast "Rolled back app to version #{version}" unless options[:skip_broadcast]
|
audit_broadcast "Rolled back #{service_version(Mrsk::Utils.abbreviate_version(old_version))} to #{service_version}" unless options[:skip_broadcast]
|
||||||
else
|
else
|
||||||
say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red
|
say "The app version '#{version}' is not available as a container (use 'mrsk app containers' for available versions)", :red
|
||||||
end
|
end
|
||||||
@@ -203,4 +206,8 @@ class Mrsk::Cli::Main < Mrsk::Cli::Base
|
|||||||
on(host) { container_names = capture_with_info(*MRSK.app.list_container_names).split("\n") }
|
on(host) { container_names = capture_with_info(*MRSK.app.list_container_names).split("\n") }
|
||||||
Array(container_names).include?(container_name)
|
Array(container_names).include?(container_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def service_version(version = MRSK.config.abbreviated_version)
|
||||||
|
[ MRSK.config.service, version ].compact.join("@")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,6 +46,11 @@ class Mrsk::Configuration
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def abbreviated_version
|
||||||
|
Mrsk::Utils.abbreviate_version(version)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def roles
|
def roles
|
||||||
@roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) }
|
@roles ||= role_names.collect { |role_name| Role.new(role_name, config: self) }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -48,4 +48,9 @@ module Mrsk::Utils
|
|||||||
def escape_shell_value(value)
|
def escape_shell_value(value)
|
||||||
value.to_s.dump.gsub(/`/, '\\\\`')
|
value.to_s.dump.gsub(/`/, '\\\\`')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Abbreviate a git revhash for concise display
|
||||||
|
def abbreviate_version(version)
|
||||||
|
version[0...7] if version
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -88,11 +88,23 @@ class CliMainTest < CliTestCase
|
|||||||
|
|
||||||
test "rollback good version" do
|
test "rollback good version" do
|
||||||
Mrsk::Cli::Main.any_instance.stubs(:container_name_available?).returns(true)
|
Mrsk::Cli::Main.any_instance.stubs(:container_name_available?).returns(true)
|
||||||
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info).with(:docker, :ps, "--filter", "label=service=app", "--format", "\"{{.Names}}\"", "|", "sed 's/-/\\n/g'", "|", "tail -n 1").returns("version-to-rollback\n").times(2)
|
||||||
|
|
||||||
run_command("rollback", "123").tap do |output|
|
run_command("rollback", "123").tap do |output|
|
||||||
assert_match /Start version 123/, output
|
assert_match "Start version 123", output
|
||||||
assert_match /docker ps -q --filter label=service=app | xargs docker stop/, output
|
assert_match "docker start app-123", output
|
||||||
assert_match /docker start app-123/, output
|
assert_match "docker container ls --all --filter name=app-version-to-rollback --quiet | xargs docker stop", output, "Should stop the container that was previously running"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "rollback without old version" do
|
||||||
|
Mrsk::Cli::Main.any_instance.stubs(:container_name_available?).returns(true)
|
||||||
|
SSHKit::Backend::Abstract.any_instance.expects(:capture_with_info).with(:docker, :ps, "--filter", "label=service=app", "--format", "\"{{.Names}}\"", "|", "sed 's/-/\\n/g'", "|", "tail -n 1").returns("").times(2)
|
||||||
|
|
||||||
|
run_command("rollback", "123").tap do |output|
|
||||||
|
assert_match "Start version 123", output
|
||||||
|
assert_match "docker start app-123", output
|
||||||
|
assert_no_match "docker stop", output
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user