Class: KTools::Tools::Deliver

Inherits:
Object
  • Object
show all
Defined in:
lib/ktools/tools/deliver.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Deliver

Returns a new instance of Deliver.



8
9
10
11
12
13
# File 'lib/ktools/tools/deliver.rb', line 8

def initialize(args)
  @action = "#{args[0]} #{args[1]}"
  @subject = args[2]
  @argument = args[3]
  @opt = args[4]
end

Class Method Details

.start(args) ⇒ Object



4
5
6
# File 'lib/ktools/tools/deliver.rb', line 4

def self.start(args)
  self.new(args).start
end

Instance Method Details

#startObject



15
16
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ktools/tools/deliver.rb', line 15

def start
  case @action
  when 'force deploy'
    dockerfile = "./Dockerfile"
    do_fail("Dockerfile?") unless File.exist?(dockerfile)

    registry = "registry.gitlab.com/"
    origin = Sh.elld!("git config --get remote.origin.url")
    do_fail("It is a Git repo?") unless origin

    project = origin[/(?<=:)([^.]*)/]
    do_fail("Can't find your project name.") if project.empty?

    image_tag = "forcedAt#{Time.now.to_i}"
    image = "#{registry}#{project}:#{image_tag}"

    puts "Forcing deployment..."
    puts "Project: #{project}"
    puts "Docker Image: #{image}"

    puts ""
    puts "Ctrl-C to cancel in 5 seconds..."
    sleep 5
    puts "Starting..."

    Sh.ell_in!("docker build -t #{image} .")
    Sh.ell_in!("docker push #{image}")

    Sh.ell_in!("./kdeliver force deploy #{image}")
  when 'get bash'
    puts "Opening live Bash..."
    puts ""

    pod = get_pod
    container = (@argument ? @argument : "#{@subject}-container")

    pod_cmd = "kubectl exec -ti -n foxbox #{pod}"
    bash_cmd = "-c #{container} /bin/bash"

    Sh.ell_meta("#{pod_cmd} #{bash_cmd}")
  when 'get logs'
    puts "Opening live logs..."
    puts ""

    pod = get_pod
    container = get_container(pod)

    if @argument == "--tail"
      Sh.ell_in!("kubectl logs -f #{pod} #{@opt} -n foxbox -c #{container}")
    else
      Sh.ell_in!("kubectl logs #{pod} #{@argument} -n foxbox -c #{container}")
    end
  else
    Help.display
  end
end