Class: K8sflow::Docker::Run
- Inherits:
-
Clitopic::Command::Base
- Object
- Clitopic::Command::Base
- K8sflow::Docker::Run
- Defined in:
- lib/k8sflow/command/docker/run.rb
Class Attribute Summary collapse
-
.aliases ⇒ Object
Returns the value of attribute aliases.
Class Method Summary collapse
- .call ⇒ Object
- .docker_run(cmd, envs, options) ⇒ Object
- .env_vars(options) ⇒ Object
- .get_cmd(args) ⇒ Object
Class Attribute Details
.aliases ⇒ Object
Returns the value of attribute aliases.
37 38 39 |
# File 'lib/k8sflow/command/docker/run.rb', line 37 def aliases @aliases end |
Class Method Details
.call ⇒ Object
110 111 112 113 114 115 |
# File 'lib/k8sflow/command/docker/run.rb', line 110 def call pp cmd = get_cmd(arguments) envs = env_vars() docker_run(cmd, envs, ) end |
.docker_run(cmd, envs, options) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/k8sflow/command/docker/run.rb', line 80 def docker_run(cmd, envs, ) ::Docker.url = [:docker_api] container_info = { 'Cmd' => cmd.split(" "), 'Image' => "#{[:registry]}:#{[:tag]}", 'Env' => envs.map{|k| "#{k[0]}=#{k[1]}"}, 'OpenStdin' => true } if ![:detach] container_info["Tty"] = true end if [:port] ctn_port, host_port = [:port].split(":") container_info["HostConfig"] = { "PortBindings" => { "#{ctn_port}/tcp" => [{ "HostPort" => host_port.to_s}] } } end if [:port_all] == true container_info["PublishAllPorts"] = true end pp container_info container = ::Docker::Container.create(container_info) container.start puts "container created with id: #{container.id}" if ![:detach] puts "docker -H #{::Docker.url} attach #{container.id}" exec("docker -H #{::Docker.url} attach #{container.id}") end end |
.env_vars(options) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/k8sflow/command/docker/run.rb', line 57 def env_vars() envs = {} if .key?(:envs) [:envs].each do |e| sp = e.split("=") key = sp[0..-2].join("=") value = sp[-1] envs[key] = value end end if .key?(:varager_api) && ![:varager_api].empty? uri = [:varager_api] token = [:varager_token] if uri && token client = K8sflow::Utils::Varager.new(token, uri) envs.merge!(client.envs([:app], false)) end end pp envs return envs end |
.get_cmd(args) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/k8sflow/command/docker/run.rb', line 43 def get_cmd(args) if args.size == 0 raise ArgumentError.new('no CMD') else cmd = args.join(" ").strip puts cmd if !@options[:aliases].nil? && @options[:aliases].is_a?(Hash) @aliases.merge!(@options[:aliases]) end cmd = aliases[cmd] if aliases.has_key?(cmd) return cmd end end |