2017-07-13 01:15:48 +02:00
|
|
|
module DockerCookbook
|
|
|
|
class DockerExec < DockerBase
|
|
|
|
resource_name :docker_exec
|
|
|
|
|
2019-02-17 07:02:05 +01:00
|
|
|
property :host, [String, nil], default: lazy { ENV['DOCKER_HOST'] }, desired_state: false
|
2017-07-13 01:15:48 +02:00
|
|
|
property :command, Array
|
|
|
|
property :container, String
|
2019-02-17 07:02:05 +01:00
|
|
|
property :timeout, Numeric, default: 60, desired_state: false
|
2017-07-13 01:15:48 +02:00
|
|
|
property :container_obj, Docker::Container, desired_state: false
|
|
|
|
|
2019-02-17 07:02:05 +01:00
|
|
|
alias_method :cmd, :command
|
2017-07-13 01:15:48 +02:00
|
|
|
|
|
|
|
action :run do
|
2019-02-17 07:02:05 +01:00
|
|
|
converge_by "executing #{new_resource.command} on #{new_resource.container}" do
|
|
|
|
with_retries { new_resource.container_obj Docker::Container.get(new_resource.container, {}, connection) }
|
|
|
|
new_resource.container_obj.exec(new_resource.command, wait: new_resource.timeout)
|
2017-07-13 01:15:48 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|