Module: KnuckleCluster

Extended by:
Forwardable
Defined in:
lib/knuckle_cluster.rb,
lib/knuckle_cluster/task.rb,
lib/knuckle_cluster/agent.rb,
lib/knuckle_cluster/version.rb,
lib/knuckle_cluster/container.rb,
lib/knuckle_cluster/task_registry.rb,
lib/knuckle_cluster/agent_registry.rb

Defined Under Namespace

Classes: Agent, AgentRegistry, Configuration, Container, Task, TaskRegistry

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.connect_to_agents(command: nil, auto: false) ⇒ Object



35
36
37
38
# File 'lib/knuckle_cluster.rb', line 35

def connect_to_agents(command: nil, auto: false)
  agent = select_agent(auto: auto)
  run_command_in_agent(agent: agent, command: command)
end

.connect_to_container(name:, command: 'bash') ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/knuckle_cluster.rb', line 45

def connect_to_container(name:, command: 'bash')
  if shortcut = shortcuts[name.to_sym]
    name = shortcut[:container]
    new_command = shortcut[:command]
    new_command += " #{command}" unless command == 'bash'
    command = new_command
  end

  container = find_container(name: name)
  run_command_in_container(container: container, command: command)
end

.connect_to_containers(command: 'bash', auto: false) ⇒ Object



40
41
42
43
# File 'lib/knuckle_cluster.rb', line 40

def connect_to_containers(command: 'bash', auto: false)
  container = select_container(auto: auto)
  run_command_in_container(container: container, command: command)
end

.container_logs(name:) ⇒ Object



57
58
59
60
61
# File 'lib/knuckle_cluster.rb', line 57

def container_logs(name:)
  container = find_container(name: name)
  subcommand = "#{'sudo ' if sudo}docker logs -f \\`#{get_container_id_command(container.name)}\\`"
  run_command_in_agent(agent: container.task.agent, command: subcommand)
end

.new(cluster_name:, region: 'us-east-1', bastion: nil, rsa_key_location: nil, ssh_username: 'ec2-user', sudo: false, aws_vault_profile: nil, shortcuts: {}, tunnels: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/knuckle_cluster.rb', line 13

def new(
    cluster_name:,
    region: 'us-east-1',
    bastion: nil,
    rsa_key_location: nil,
    ssh_username: 'ec2-user',
    sudo: false,
    aws_vault_profile: nil,
    shortcuts: {},
    tunnels: {})
  @cluster_name      = cluster_name
  @region            = region
  @bastion           = bastion
  @rsa_key_location  = rsa_key_location
  @ssh_username      = ssh_username
  @sudo              = sudo
  @aws_vault_profile = aws_vault_profile
  @shortcuts         = shortcuts
  @tunnels           = tunnels
  self
end

.open_tunnel(name:) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/knuckle_cluster.rb', line 63

def open_tunnel(name:)
  if tunnel = tunnels[name.to_sym]
    agent = select_agent(auto: true)
    open_tunnel_via_agent(tunnel.merge(agent: agent))
  else
    puts "ERROR: A tunnel configuration was not found for '#{name}'"
  end
end