Class: ConfigureCommand

Inherits:
Command show all
Defined in:
lib/ukku/configure_command.rb

Instance Method Summary collapse

Methods inherited from Command

#load_app_info

Instance Method Details

#execute(args) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ukku/configure_command.rb', line 2

def execute(args)
  host = args['HOST']
  name = args['NAME'] || "production"
  user = args['--user'] || "root"
  no_pg = args['--no-pg']
  identity_file = args['-i']

  entry = { "host" => host, "user" => user } # the entry to add to UKKU_FILE
  entry["identity_file"] = identity_file if identity_file

  # check if the entry exists in UKKU_FILE (with different info)
  entry_in_file = load_entry_from_file(name)
  if entry_in_file && !entries_match?(entry_in_file, entry)
    raise "Name '#{name}' already exists, choose a different one"
  end

  conn = Connection.new(entry)
  server_ready = is_server_ready?(conn)
  
  if server_ready
    puts "The server is already configured ... skipping"
  else
    configure_server(conn, no_pg)
  end

  repo = fetch_repo
  configure_remote(repo, name, "git@#{host}:#{name}")
  
  append_entry_to_ukku_file(name, entry) if !entry_in_file

  append_ukku_file_to_gitignore

  print_ssh_config(host, identity_file) if identity_file

  puts
  puts "Your server is configured! Deploy your application using 'git push #{name} master'"
end