Class: Shippy::Docker::Client
- Inherits:
-
Object
- Object
- Shippy::Docker::Client
- Includes:
- SSHKit::DSL
- Defined in:
- lib/shippy/docker/client.rb
Instance Method Summary collapse
- #compose_down(path) ⇒ Object
- #compose_pull(path, stream: false) ⇒ Object
- #compose_restart(path, services = []) ⇒ Object
- #compose_up(path, flags: "") ⇒ Object
- #ensure_network(name) ⇒ Object
-
#initialize(host) ⇒ Client
constructor
A new instance of Client.
- #logs(path, follow: false) ⇒ Object
- #pin_image_digests(path) ⇒ Object
- #run_hook(path, service, options, command) ⇒ Object
- #status(path) ⇒ Object
Constructor Details
#initialize(host) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/shippy/docker/client.rb', line 9 def initialize(host) @host = host end |
Instance Method Details
#compose_down(path) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/shippy/docker/client.rb', line 31 def compose_down(path) on(@host) do if test("[ -f #{path.join("docker-compose.yml")} ]") within(path) do execute :docker, :compose, :down, "--remove-orphans" end end end end |
#compose_pull(path, stream: false) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/shippy/docker/client.rb', line 41 def compose_pull(path, stream: false) handler = stream ? Shippy::SshStreamHandler.new : nil on(@host) do within(path) do execute :docker, :compose, :pull, interaction_handler: handler end end end |
#compose_restart(path, services = []) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/shippy/docker/client.rb', line 59 def compose_restart(path, services = []) on(@host) do within(path) do execute :docker, :compose, :restart, *services end end end |
#compose_up(path, flags: "") ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/shippy/docker/client.rb', line 21 def compose_up(path, flags: "") on(@host) do within(path) do args = [:docker, :compose, :up, "-d"] args.concat(Array(flags)) unless flags.nil? || flags.empty? execute(*args) end end end |
#ensure_network(name) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/shippy/docker/client.rb', line 13 def ensure_network(name) on(@host) do if test("[ -z \"$(docker network ls -q -f name=#{name})\" ]") execute :docker, :network, :create, name end end end |
#logs(path, follow: false) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/shippy/docker/client.rb', line 79 def logs(path, follow: false) cmd_args = [:docker, "compose", "logs"] cmd_args << "--follow" if follow on(@host) do within(path) do if follow execute(*cmd_args, interaction_handler: Shippy::SshStreamHandler.new) else puts capture(*cmd_args) end end end end |
#pin_image_digests(path) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/shippy/docker/client.rb', line 50 def pin_image_digests(path) on(@host) do within(path) do execute :docker, :compose, :config, "--resolve-image-digests > docker-compose.pinned.yml" execute :mv, "docker-compose.pinned.yml", "docker-compose.yml" end end end |
#run_hook(path, service, options, command) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shippy/docker/client.rb', line 67 def run_hook(path, service, , command) on(@host) do within(path) do args = [:docker, :compose, :run, "--rm"] args << if && !.empty? args << service args << command execute(*args) end end end |
#status(path) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/shippy/docker/client.rb', line 94 def status(path) on(@host) do within(path) do puts capture(:docker, :compose, :ps, "-a") end end end |