Class: Neptuno::Services::Add

Inherits:
CLI::Base
  • Object
show all
Includes:
TTY::Config, TTY::File, TTY::Prompt
Defined in:
lib/neptuno/services/add.rb

Overview

Add project to neptuno

Constant Summary

Constants included from TTY::File

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

Constants included from TTY::Config

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

Constants included from TTY::Prompt

TTY::Prompt::TTY

Constants inherited from CLI::Base

CLI::Base::ABORT_MESSAGE

Constants included from TTY::Command

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

Instance Method Summary collapse

Methods included from TTY::File

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

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::Prompt

#prompt

Methods inherited from CLI::Base

#command_service_to, #command_services_to, #initialize

Methods included from TTY::Command

#command, #command_p, #neptuno_command

Constructor Details

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

Instance Method Details

#add_dockerfile(name) ⇒ Object



31
32
33
34
# File 'lib/neptuno/services/add.rb', line 31

def add_dockerfile(name)
  file.create_file("#{neptuno_path}/dockerfiles/#{name}/Dockerfile")
  file.create_file("#{neptuno_path}/dockerfiles/#{name}/entrypoint.sh")
end

#add_environment(name) ⇒ Object



40
41
42
# File 'lib/neptuno/services/add.rb', line 40

def add_environment(name)
  file.create_file("#{neptuno_path}/environments/#{name}/default")
end

#add_procfile(name) ⇒ Object



36
37
38
# File 'lib/neptuno/services/add.rb', line 36

def add_procfile(name)
  file.create_file("#{neptuno_path}/procfiles/#{name}/Procfile")
end

#add_service_to_dc(name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/neptuno/services/add.rb', line 44

def add_service_to_dc(name)
  puts(<<~EOT)
    #---------------------------------------------------------------
    # Registered #{name} as a service. You can now add it to the docker-compose.yml:
    #---------------------------------------------------------------

    version: '3'
    services:
      ##########################
      # #{name}
      ##########################
      #{name}:
        stdin_open: true
        tty: true
        command: ash
        build:#{" "}
          context: .
          dockerfile: ./dockerfiles/#{name}/Dockerfile
        env_file:#{" "}
          - ./environments/#{name}/default
        # volumes:#{" "}
        #   -
        # ports:#{" "}
        #   -
        # depends_on:#{" "}
        #   -

    #---------------------------------------------------------------
    # Next steps
    #---------------------------------------------------------------

    Add the service's Dockerfile at ./dockerfiles/#{name}/Dockerfile
    Add the service's Environments at ./environments/#{name}/default
    Add the service's Procfile at ./procfiles/#{name}/Procfile
  EOT
end

#callObject



13
14
15
16
17
18
19
20
21
# File 'lib/neptuno/services/add.rb', line 13

def call(**)
  name = prompt.ask("? Service name:")
  repo = prompt.ask("? Git repo:")
  clone_into_folder(repo, name)
  # add_dockerfile(name)
  add_procfile(name)
  add_environment(name)
  add_service_to_dc(name)
end

#clone_into_folder(repo, name) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/neptuno/services/add.rb', line 23

def clone_into_folder(repo, name)
  if repo.nil?
    command.run("mkdir #{neptuno_path}/services/#{name}")
  else
    command.run("cd #{neptuno_path} && git submodule add #{repo} ./services/#{name}")
  end
end