Module: Odysseus::CLI::InteractiveCommands

Included in:
CLI
Defined in:
lib/odysseus/cli/interactive_commands.rb

Instance Method Summary collapse

Instance Method Details

#app_console(server, options = {}) ⇒ Object

App console



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/odysseus/cli/interactive_commands.rb', line 41

def app_console(server, options = {})
  config_file = options[:config] || 'deploy.yml'
  role = (options[:role] || 'web').to_sym
  console_cmd = options[:cmd] || '/bin/sh'
  config = load_config(config_file)
  image = running_image(server, config, role)
  # Read before the env file is written: a --cmd that cannot be parsed is
  # not worth putting a file of secrets on the host for.
  words = console_words(console_cmd)
  session_header('App Console', server: server, role: role, image: image, command: console_cmd)

  with_container_env(server, config, config_file) do |env_file|
    remote = remote_command(['docker', 'run', '-it', '--rm', '--network', 'odysseus',
                             *env_file_args(env_file), image, *words])
    run_interactive!(ssh_command(config, server, remote))
  end
rescue Odysseus::Error => e
  @ui.error e.message
  exit 1
end

#app_shell(server, options = {}) ⇒ Object

App shell



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/odysseus/cli/interactive_commands.rb', line 23

def app_shell(server, options = {})
  config_file = options[:config] || 'deploy.yml'
  role = (options[:role] || 'web').to_sym
  config = load_config(config_file)
  image = running_image(server, config, role)
  session_header('App Shell', server: server, role: role, image: image, command: '/bin/sh')

  with_container_env(server, config, config_file) do |env_file|
    remote = remote_command(['docker', 'run', '-it', '--rm', '--network', 'odysseus',
                             *env_file_args(env_file), image, '/bin/sh'])
    run_interactive!(ssh_command(config, server, remote))
  end
rescue Odysseus::Error => e
  @ui.error e.message
  exit 1
end

#dependency_shell(server, options = {}) ⇒ Object

Dependency shell



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/odysseus/cli/interactive_commands.rb', line 63

def dependency_shell(server, options = {})
  config_file = options[:config] || 'deploy.yml'
  name = require_name!(options)

  config = load_config(config_file)
  service_name = "#{config[:service]}-#{name}"

  ssh = connect_to_server(server, config)
  begin
    docker = Odysseus::Docker::Client.new(ssh)
    containers = docker.list(service: service_name)

    if containers.empty?
      @ui.error "No running containers found for #{service_name}"
      exit 1
    end

    container_id = containers.first['ID']
  ensure
    ssh.close
  end

  remote = remote_command(['docker', 'exec', '-it', container_id, '/bin/sh'])
  run_interactive!(ssh_command(config, server, remote))
rescue Odysseus::Error => e
  @ui.error e.message
  exit 1
end