@@ -52,6 +52,7 @@ class CliServerTest < CliTestCase
52
52
stub_setup
53
53
SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( :docker , "-v" , raise_on_non_zero_exit : false ) . returns ( false ) . at_least_once
54
54
SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' , raise_on_non_zero_exit : false ) . returns ( true ) . at_least_once
55
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( '[ "${EUID:-$(id -u)}" -eq 0 ] || id -nG "${USER:-$(id -un)}" | grep -qw docker || { sudo usermod -aG docker "${USER:-$(id -un)}" && kill -9 -1; }' ) . at_least_once
55
56
SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( :sh , "-c" , "'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \" exit 1\" '" , "|" , :sh ) . at_least_once
56
57
SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( :mkdir , "-p" , ".kamal" ) . returns ( "" ) . at_least_once
57
58
Kamal ::Commands ::Hook . any_instance . stubs ( :hook_exists? ) . returns ( true )
@@ -66,6 +67,26 @@ class CliServerTest < CliTestCase
66
67
end
67
68
end
68
69
70
+ test "bootstrap install as sudo non-root user" do
71
+ stub_setup
72
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( :docker , "-v" , raise_on_non_zero_exit : false ) . returns ( false ) . at_least_once
73
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' , raise_on_non_zero_exit : false ) . returns ( true ) . at_least_once
74
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( '[ "${EUID:-$(id -u)}" -eq 0 ] || id -nG "${USER:-$(id -un)}" | grep -qw docker || { sudo usermod -aG docker "${USER:-$(id -un)}" && kill -9 -1; }' ) . at_least_once . raises ( IOError , "closed stream" )
75
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( :sh , "-c" , "'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \" exit 1\" '" , "|" , :sh ) . at_least_once
76
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( :mkdir , "-p" , ".kamal" ) . returns ( "" ) . at_least_once
77
+ Kamal ::Commands ::Hook . any_instance . stubs ( :hook_exists? ) . returns ( true )
78
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( ".kamal/hooks/pre-connect" , anything ) . at_least_once
79
+ SSHKit ::Backend ::Abstract . any_instance . expects ( :execute ) . with ( ".kamal/hooks/docker-setup" , anything ) . at_least_once
80
+
81
+ run_command ( "bootstrap" ) . tap do |output |
82
+ ( "1.1.1.1" .."1.1.1.4" ) . map do |host |
83
+ assert_match "Missing Docker on #{ host } . Installing…" , output
84
+ assert_match "Session refreshed due to group change." , output
85
+ assert_match "Running the docker-setup hook" , output
86
+ end
87
+ end
88
+ end
89
+
69
90
private
70
91
def run_command ( *command )
71
92
stdouted { Kamal ::Cli ::Server . start ( [ *command , "-c" , "test/fixtures/deploy_with_accessories.yml" ] ) }
0 commit comments