Class: KuberKit::Shell::Commands::DockerCommands
- Defined in:
- lib/kuber_kit/shell/commands/docker_commands.rb
Instance Method Summary collapse
- #build(shell, build_dir, args = []) ⇒ Object
- #container_exists?(shell, container_name) ⇒ Boolean
- #delete_container(shell, container_name) ⇒ Object
- #get_container_id(shell, container_name, only_healthy: false, status: "running") ⇒ Object
- #push(shell, tag_name) ⇒ Object
- #run(shell, image_name, run_args: nil, run_command: nil) ⇒ Object
- #tag(shell, image_name, tag_name) ⇒ Object
Instance Method Details
#build(shell, build_dir, args = []) ⇒ Object
2 3 4 5 6 7 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 2 def build(shell, build_dir, args = []) default_args = ["--rm=true"] args_list = (default_args + args).join(" ") shell.exec!(%Q{docker build #{build_dir} #{args_list}}) end |
#container_exists?(shell, container_name) ⇒ Boolean
27 28 29 30 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 27 def container_exists?(shell, container_name) result = get_container_id(shell, container_name) result && result != "" end |
#delete_container(shell, container_name) ⇒ Object
32 33 34 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 32 def delete_container(shell, container_name) shell.exec!(%Q{docker rm -f #{container_name}}) end |
#get_container_id(shell, container_name, only_healthy: false, status: "running") ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 36 def get_container_id(shell, container_name, only_healthy: false, status: "running") command_parts = [] command_parts << "docker ps -a -q" if only_healthy command_parts << "--filter=\"health=healthy\"" end command_parts << "--filter=\"status=#{status}\"" command_parts << "--filter=\"name=#{container_name}\"" shell.exec!(command_parts.join(" ")) end |
#push(shell, tag_name) ⇒ Object
13 14 15 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 13 def push(shell, tag_name) shell.exec!(%Q{docker push #{tag_name}}) end |
#run(shell, image_name, run_args: nil, run_command: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 17 def run(shell, image_name, run_args: nil, run_command: nil) command_parts = [] command_parts << "docker run" command_parts << run_args if run_args command_parts << image_name command_parts << run_command if run_command shell.exec!(command_parts.join(" ")) end |
#tag(shell, image_name, tag_name) ⇒ Object
9 10 11 |
# File 'lib/kuber_kit/shell/commands/docker_commands.rb', line 9 def tag(shell, image_name, tag_name) shell.exec!(%Q{docker tag #{image_name} #{tag_name}}) end |