Class: K8sflow::Command::Run
- Inherits:
-
Clitopic::Command::Base
- Object
- Clitopic::Command::Base
- K8sflow::Command::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.
34 35 36 |
# File 'lib/k8sflow/command/docker/run.rb', line 34 def aliases @aliases end |
Class Method Details
.call ⇒ Object
101 102 103 104 105 106 |
# File 'lib/k8sflow/command/docker/run.rb', line 101 def call pp cmd = get_cmd(arguments) envs = env_vars() docker_run(cmd, envs, ) end |
.docker_run(cmd, envs, options) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/k8sflow/command/docker/run.rb', line 71 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/k8sflow/command/docker/run.rb', line 54 def env_vars() envs = {} if .has_key?(:envs) [:envs].each do |e| sp = e.split("=") key = sp[0..-2].join("=") value = sp[-1] envs[key] = value end end if .has_key?(:heroku) envs.merge!( K8sflow::Utils::HerokuClient.envs([:heroku], [:heroku_db])) end pp envs return envs end |
.get_cmd(args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/k8sflow/command/docker/run.rb', line 40 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 |