Class: Kuby::Tasks
- Inherits:
-
Object
- Object
- Kuby::Tasks
- Defined in:
- lib/kuby/tasks.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(definition) ⇒ Tasks
constructor
A new instance of Tasks.
- #print_dockerfile ⇒ Object
- #print_kubeconfig ⇒ Object
- #print_resources ⇒ Object
- #push ⇒ Object
- #remote_console ⇒ Object
- #remote_dbconsole ⇒ Object
- #remote_logs ⇒ Object
- #remote_shell ⇒ Object
- #remote_status ⇒ Object
- #run ⇒ Object
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
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
5 6 7 |
# File 'lib/kuby/tasks.rb', line 5 def definition @definition end |
Instance Method Details
#build ⇒ Object
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.. ) end |
#print_dockerfile ⇒ Object
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 |
#print_kubeconfig ⇒ Object
60 61 62 63 64 |
# File 'lib/kuby/tasks.rb', line 60 def print_kubeconfig path = kubernetes.provider.kubeconfig_path Kuby.logger.info("Printing contents of #{path}") puts File.read(path) end |
#print_resources ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/kuby/tasks.rb', line 52 def print_resources kubernetes.before_deploy kubernetes.resources.each do |res| puts res.to_resource.serialize.to_yaml end end |
#push ⇒ Object
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..local..each do |tag| docker.cli.push(image_url, tag) end rescue Kuby::Docker::MissingTagError => e msg = "#{e.} Run rake kuby:build to build the"\ 'Docker image before running this task.' Kuby.logger.fatal(msg) end end |
#remote_console ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/kuby/tasks.rb', line 80 def remote_console first_pod = get_first_pod kubernetes_cli.exec_cmd( 'bundle exec rails console', namespace, first_pod.dig('metadata', 'name') ) end |
#remote_dbconsole ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/kuby/tasks.rb', line 88 def remote_dbconsole first_pod = get_first_pod kubernetes_cli.exec_cmd( 'bundle exec rails dbconsole', namespace, first_pod.dig('metadata', 'name') ) end |
#remote_logs ⇒ Object
66 67 68 |
# File 'lib/kuby/tasks.rb', line 66 def remote_logs kubernetes_cli.logtail(namespace, match_labels.serialize) end |
#remote_shell ⇒ Object
74 75 76 77 78 |
# File 'lib/kuby/tasks.rb', line 74 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_status ⇒ Object
70 71 72 |
# File 'lib/kuby/tasks.rb', line 70 def remote_status kubernetes_cli.run_cmd(['-n', namespace, 'get', 'pods']) end |
#run ⇒ Object
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 |