Class: Neptuno::Overmind::Connect

Inherits:
CLI::Base
  • Object
show all
Includes:
TTY::Config
Defined in:
lib/neptuno/overmind/connect.rb

Overview

Build docker container for Neptuno project

Constant Summary

Constants included from TTY::Config

TTY::Config::ABORT_MESSAGE, TTY::Config::TTY

Constants included from TTY::File

TTY::File::ABORT_MESSAGE, TTY::File::TTY

Constants inherited from CLI::Base

CLI::Base::ABORT_MESSAGE

Constants included from TTY::Command

TTY::Command::TTY, TTY::Command::TTYP

Constants included from TTY::Prompt

TTY::Prompt::TTY

Instance Method Summary collapse

Methods included from TTY::Config

#auto_restart_procs, #config, #configured_services, #docker_compose_hash, #docker_compose_services, #get_dependants, #healthy_services, #json_services_status, #running_services, #services, #services_with_procs, #starting_services

Methods included from TTY::File

#file, #in_service?, #make_service_files, #neptuno_path, #project, #service

Methods inherited from CLI::Base

#command_service_to, #command_services_to, #initialize

Methods included from TTY::Command

#command, #command_p, #neptuno_command

Methods included from TTY::Prompt

#prompt

Constructor Details

This class inherits a constructor from Neptuno::CLI::Base

Instance Method Details

#call(services: [], **options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/neptuno/overmind/connect.rb', line 17

def call(services: [], **options)
  command_services_to("connect to procs", all: options.fetch(:all), services_as_args: services) do |services|
    original_services = services
    services = services_with_procs.intersection(get_dependants(services).concat(services).uniq).sort
    `neptuno up #{services.join(" ")}` if options.fetch(:up)

    outside_tmux = `echo $TMUX`.strip.empty?

    if config.fetch("procfile_manager") == "tmux"
      services.each do |service|
        if /#{service}/.match?(`tmux ls`)
          puts "Neptuno will use the existing Tmux session for: #{service}"
          next
        end

        pid = spawn("cd #{neptuno_path} && tmuxinator start neptuno_#{service} #{service}",
          3 => "/dev/null")
        Process.detach(pid)
        puts "Neptuno started Tmux session for: #{service}" if `echo $TMUX`.strip.empty?
      end
    else
      puts `neptuno start --no-up #{services.join(" ")}` if options.fetch(:start)
      if outside_tmux
        system("cd #{neptuno_path} && sleep 1 && tmuxinator start neptuno #{services.join(" ")}")
      else
        puts "Connecting to #{original_services.first}"
        system("cd #{neptuno_path}/procfiles/#{original_services.first} && sleep 2 && overmind connect shell")
      end
    end
  end
end