diff --git a/lib/kamal/commands/base.rb b/lib/kamal/commands/base.rb index f51f01c1..7e09fc1c 100644 --- a/lib/kamal/commands/base.rb +++ b/lib/kamal/commands/base.rb @@ -70,6 +70,10 @@ module Kamal::Commands [ :xargs, command ].flatten end + def shell(command) + [ :sh, "-c", "'#{command.flatten.join(" ").gsub("'", "'\\''")}'" ] + end + def docker(*args) args.compact.unshift :docker end diff --git a/lib/kamal/commands/docker.rb b/lib/kamal/commands/docker.rb index 942c58c0..2966e095 100644 --- a/lib/kamal/commands/docker.rb +++ b/lib/kamal/commands/docker.rb @@ -1,7 +1,7 @@ class Kamal::Commands::Docker < Kamal::Commands::Base # Install Docker using the https://github.com/docker/docker-install convenience script. def install - pipe [ :curl, "-fsSL", "https://get.docker.com" ], :sh + pipe get_docker, :sh end # Checks the Docker client version. Fails if Docker is not installed. @@ -18,4 +18,13 @@ class Kamal::Commands::Docker < Kamal::Commands::Base def superuser? [ '[ "${EUID:-$(id -u)}" -eq 0 ] || command -v sudo >/dev/null || command -v su >/dev/null' ] end + + private + def get_docker + shell \ + any \ + [ :curl, "-fsSL", "https://get.docker.com" ], + [ :wget, "-O -", "https://get.docker.com" ], + [ :echo, "\"exit 1\"" ] + end end diff --git a/test/cli/server_test.rb b/test/cli/server_test.rb index 1c8a2607..0098b100 100644 --- a/test/cli/server_test.rb +++ b/test/cli/server_test.rb @@ -21,7 +21,7 @@ class CliServerTest < CliTestCase test "bootstrap install as root user" do SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:docker, "-v", raise_on_non_zero_exit: false).returns(false).at_least_once 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 - SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:curl, "-fsSL", "https://get.docker.com", "|", :sh).at_least_once + 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 SSHKit::Backend::Abstract.any_instance.expects(:execute).with(:mkdir, "-p", ".kamal").returns("").at_least_once run_command("bootstrap").tap do |output| diff --git a/test/commands/docker_test.rb b/test/commands/docker_test.rb index 098d4162..0c0e976b 100644 --- a/test/commands/docker_test.rb +++ b/test/commands/docker_test.rb @@ -9,7 +9,7 @@ class CommandsDockerTest < ActiveSupport::TestCase end test "install" do - assert_equal "curl -fsSL https://get.docker.com | sh", @docker.install.join(" ") + assert_equal "sh -c 'curl -fsSL https://get.docker.com || wget -O - https://get.docker.com || echo \"exit 1\"' | sh", @docker.install.join(" ") end test "installed?" do