Class: Dkc::Main

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/dkc/main.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



9
10
11
# File 'lib/dkc/main.rb', line 9

def self.source_root
  File.dirname(__FILE__)
end

Instance Method Details

#bashObject



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dkc/main.rb', line 101

def bash
  puts "Starting Bash..."
  unless Dkc::Config.instance.load
    raise StandardError.new("ERROR: Could not load/parse #{CONFIG_FILE_NAME}")
  end

  main_container = Dkc::Config.instance.getValue("mainContainer")

  if main_container.class != String || main_container.length <= 0
    raise StandardError.new("ERROR: No mainContainer value in #{CONFIG_FILE_NAME}")
  end

  run("docker-compose exec #{main_container} bash")

rescue StandardError => e
  puts e.message
  exit false
end

#downObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/dkc/main.rb', line 41

def down
  puts "Stopping and Removing Containers..."
  unless Dkc::Config.instance.load
    raise StandardError.new("ERROR: Could not load/parse #{CONFIG_FILE_NAME}")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customDown") == nil
    run("docker-compose down")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customDown") != nil
    run(Dkc::Config.instance.getValue("customDown"))
  end

rescue StandardError => e
  puts e.message
  exit false
end

#initObject



14
15
16
17
18
# File 'lib/dkc/main.rb', line 14

def init
  config_file = File.new(CONFIG_FILE_NAME, "w+")
  config_file.write(CONFIG_FILE_EXAMPLE)
  config_file.close
end

#logsObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/dkc/main.rb', line 121

def logs
  puts "Tailing logs..."
  unless Dkc::Config.instance.load
    raise StandardError.new("ERROR: Could not load/parse #{CONFIG_FILE_NAME}")
  end

  log_containers = Dkc::Config.instance.getValue("logContainers")

  if log_containers.class != Array || log_containers.length <= 0
    raise StandardError.new("ERROR: No logContainers value in #{CONFIG_FILE_NAME}")
  end

  run("docker-compose logs -f #{log_containers.join(" ")}")

rescue StandardError => e
  puts e.message
  exit false
end

#startObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dkc/main.rb', line 61

def start
  puts "Starting Containers..."
  unless Dkc::Config.instance.load
    raise StandardError.new("ERROR: Could not load/parse #{CONFIG_FILE_NAME}")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customStart") == nil
    run("docker-compose start")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customStart") != nil
    run(Dkc::Config.instance.getValue("customStart"))
  end

rescue StandardError => e
  puts e.message
  exit false
end

#stopObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dkc/main.rb', line 81

def stop
  puts "Stopping Containers..."
  unless Dkc::Config.instance.load
    raise StandardError.new("ERROR: Could not load/parse #{CONFIG_FILE_NAME}")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customStop") == nil
    run("docker-compose stop")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customStop") != nil
    run(Dkc::Config.instance.getValue("customStop"))
  end

rescue StandardError => e
  puts e.message
  exit false
end

#upObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dkc/main.rb', line 21

def up
  puts "Bringing Containers Up..."
  unless Dkc::Config.instance.load
    raise StandardError.new("ERROR: Could not load/parse #{CONFIG_FILE_NAME}")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customUp") == nil
    run("docker-compose up -d")
  end

  if Dkc::Config.instance.getValue("usesCompose") == true && Dkc::Config.instance.getValue("customUp") != nil
    run(Dkc::Config.instance.getValue("customUp"))
  end

rescue StandardError => e
  puts e.message
  exit false
end