Sha256: 71d7f5468fbeba636f74483f6924c21551fb99c9d382ba019fcd0869554a0715

Contents?: true

Size: 1.62 KB

Versions: 12

Compression:

Stored size: 1.62 KB

Contents

class Kamal::Cli::Server < Kamal::Cli::Base
  desc "exec", "Run a custom command on the server (use --help to show options)"
  option :interactive, type: :boolean, aliases: "-i", default: false, desc: "Run the command interactively (use for console/bash)"
  def exec(cmd)
    hosts = KAMAL.hosts | KAMAL.accessory_hosts

    case
    when options[:interactive]
      host = KAMAL.primary_host

      say "Running '#{cmd}' on #{host} interactively...", :magenta

      run_locally { exec KAMAL.server.run_over_ssh(cmd, host: host) }
    else
      say "Running '#{cmd}' on #{hosts.join(', ')}...", :magenta

      on(hosts) do |host|
        execute *KAMAL.auditor.record("Executed cmd '#{cmd}' on #{host}"), verbosity: :debug
        puts_by_host host, capture_with_info(cmd)
      end
    end
  end

  desc "bootstrap", "Set up Docker to run Kamal apps"
  def bootstrap
    with_lock do
      missing = []

      on(KAMAL.hosts | KAMAL.accessory_hosts) do |host|
        unless execute(*KAMAL.docker.installed?, raise_on_non_zero_exit: false)
          if execute(*KAMAL.docker.superuser?, raise_on_non_zero_exit: false)
            info "Missing Docker on #{host}. Installing…"
            execute *KAMAL.docker.install
          else
            missing << host
          end
        end

        execute(*KAMAL.server.ensure_run_directory)
      end

      if missing.any?
        raise "Docker is not installed on #{missing.join(", ")} and can't be automatically installed without having root access and either `wget` or `curl`. Install Docker manually: https://docs.docker.com/engine/install/"
      end

      run_hook "docker-setup"
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
kamal-1.9.2 lib/kamal/cli/server.rb
kamal-1.9.1 lib/kamal/cli/server.rb
kamal-1.9.0 lib/kamal/cli/server.rb
kamal-1.8.3 lib/kamal/cli/server.rb
kamal-1.8.2 lib/kamal/cli/server.rb
kamal-1.8.1 lib/kamal/cli/server.rb
kamal-1.8.0 lib/kamal/cli/server.rb
kamal-1.7.3 lib/kamal/cli/server.rb
kamal-1.7.2 lib/kamal/cli/server.rb
kamal-1.7.1 lib/kamal/cli/server.rb
kamal-1.7.0 lib/kamal/cli/server.rb
kamal-1.6.0 lib/kamal/cli/server.rb