From 7cc64299c8f3b3046a8d27471a3d0ebd91985b36 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 2 Feb 2023 15:28:34 +0100 Subject: [PATCH] Add app reboot --- lib/mrsk/cli/app.rb | 9 ++++++++- test/cli/app_test.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/cli/app_test.rb diff --git a/lib/mrsk/cli/app.rb b/lib/mrsk/cli/app.rb index 6b89e0a7..a96196b4 100644 --- a/lib/mrsk/cli/app.rb +++ b/lib/mrsk/cli/app.rb @@ -18,7 +18,14 @@ class Mrsk::Cli::App < Mrsk::Cli::Base end end end - + + desc "reboot", "Reboot app on host (stop container, remove container, start new container)" + def reboot + stop + remove_container + boot + end + desc "start", "Start existing app on servers (use --version= to designate specific version)" option :version, desc: "Defaults to the most recent git-hash in local repository" def start diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb new file mode 100644 index 00000000..72a44481 --- /dev/null +++ b/test/cli/app_test.rb @@ -0,0 +1,32 @@ +require "test_helper" +require "active_support/testing/stream" +require "mrsk/cli" + +class CliAppTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Stream + + setup do + ENV["VERSION"] = "999" + ENV["RAILS_MASTER_KEY"] = "123" + ENV["MYSQL_ROOT_PASSWORD"] = "secret123" + end + + teardown do + ENV.delete("RAILS_MASTER_KEY") + ENV.delete("MYSQL_ROOT_PASSWORD") + ENV.delete("VERSION") + end + + test "boot" do + assert_match /Running docker run -d --restart unless-stopped --name app-999/, run_command("boot") + end + + test "reboot" do + assert_equal "", run_command("reboot") + end + + private + def run_command(*command) + stdouted { Mrsk::Cli::App.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml"]) } + end +end