Class: Kuby::Tasks

Inherits:
Object
  • Object
show all
Defined in:
lib/kuby/tasks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Tasks

Returns a new instance of Tasks.



7
8
9
# File 'lib/kuby/tasks.rb', line 7

def initialize(definition)
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/kuby/tasks.rb', line 5

def definition
  @definition
end

Instance Method Details

#buildObject



19
20
21
22
23
24
25
# File 'lib/kuby/tasks.rb', line 19

def build
  docker.cli.build(
    dockerfile: docker.to_dockerfile,
    image_url:  docker..image_url,
    tags:       docker..tags
  )
end


11
12
13
14
15
16
17
# File 'lib/kuby/tasks.rb', line 11

def print_dockerfile
  theme = Rouge::Themes::Base16::Solarized.new
  formatter = Rouge::Formatters::Terminal256.new(theme)
  lexer = Rouge::Lexers::Docker.new
  tokens = lexer.lex(Kuby.definition.docker.to_dockerfile.to_s)
  puts formatter.format(tokens)
end


58
59
60
61
62
# File 'lib/kuby/tasks.rb', line 58

def print_kubeconfig
  path = kubernetes.provider.kubeconfig_path
  Kuby.logger.info("Printing contents of #{path}")
  puts File.read(path)
end


52
53
54
55
56
# File 'lib/kuby/tasks.rb', line 52

def print_resources
  kubernetes.resources.each do |res|
    puts res.to_resource.serialize.to_yaml
  end
end

#pushObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kuby/tasks.rb', line 37

def push
  image_url = docker..image_url

  begin
    docker.tags.local.latest_tags.each do |tag|
      docker.cli.push(image_url, tag)
    end
  rescue Kuby::Docker::MissingTagError => e
    msg = "#{e.message} Run rake kuby:build to build the"\
      'Docker image before running this task.'

    Kuby.logger.fatal(msg)
  end
end

#remote_consoleObject



78
79
80
81
82
83
84
# File 'lib/kuby/tasks.rb', line 78

def remote_console
  first_pod = get_first_pod

  kubernetes_cli.exec_cmd(
    'bundle exec rails console', namespace, first_pod.dig('metadata', 'name')
  )
end

#remote_dbconsoleObject



86
87
88
89
90
91
92
# File 'lib/kuby/tasks.rb', line 86

def remote_dbconsole
  first_pod = get_first_pod

  kubernetes_cli.exec_cmd(
    'bundle exec rails dbconsole', namespace, first_pod.dig('metadata', 'name')
  )
end

#remote_logsObject



64
65
66
# File 'lib/kuby/tasks.rb', line 64

def remote_logs
  kubernetes_cli.logtail(namespace, match_labels.serialize)
end

#remote_shellObject



72
73
74
75
76
# File 'lib/kuby/tasks.rb', line 72

def remote_shell
  first_pod = get_first_pod
  shell = docker.distro_spec.shell_exe
  kubernetes_cli.exec_cmd(shell, namespace, first_pod.dig('metadata', 'name'))
end

#remote_statusObject



68
69
70
# File 'lib/kuby/tasks.rb', line 68

def remote_status
  kubernetes_cli.run_cmd(['-n', namespace, 'get', 'pods'])
end

#runObject



27
28
29
30
31
32
33
34
35
# File 'lib/kuby/tasks.rb', line 27

def run
  dockerfile = docker.to_dockerfile

  docker.cli.run(
    image_url: docker..image_url,
    tag:       'latest',
    ports:     dockerfile.exposed_ports
  )
end