lib/bolt/transport/docker/connection.rb in bolt-3.5.0 vs lib/bolt/transport/docker/connection.rb in bolt-3.6.0
- old
+ new
@@ -32,10 +32,14 @@
# @return [String] The full ID of the target container
def container_id
@container_info["Id"]
end
+ def run_cmd(cmd, env_vars)
+ Bolt::Util.exec_docker(cmd, env_vars)
+ end
+
private def env_hash
# Set the DOCKER_HOST if we are using a non-default service-url
@docker_host.nil? ? {} : { 'DOCKER_HOST' => @docker_host }
end
@@ -88,11 +92,11 @@
raise
end
def upload_file(source, destination)
@logger.trace { "Uploading #{source} to #{destination}" }
- _out, err, stat = Bolt::Util.exec_docker(['cp', source, "#{container_id}:#{destination}"], env_hash)
+ _out, err, stat = run_cmd(['cp', source, "#{container_id}:#{destination}"], env_hash)
unless stat.exitstatus.zero?
raise "Error writing to container #{container_id}: #{err}"
end
rescue StandardError => e
raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
@@ -102,11 +106,11 @@
@logger.trace { "Downloading #{source} to #{destination}" }
# Create the destination directory, otherwise copying a source directory with Docker will
# copy the *contents* of the directory.
# https://docs.docker.com/engine/reference/commandline/cp/
FileUtils.mkdir_p(destination)
- _out, err, stat = Bolt::Util.exec_docker(['cp', "#{container_id}:#{source}", destination], env_hash)
+ _out, err, stat = run_cmd(['cp', "#{container_id}:#{source}", destination], env_hash)
unless stat.exitstatus.zero?
raise "Error downloading content from container #{container_id}: #{err}"
end
rescue StandardError => e
raise Bolt::Node::FileError.new(e.message, 'WRITE_ERROR')
@@ -117,12 +121,12 @@
# @param subcommand [String] The docker subcommand to run
# e.g. 'inspect' for `docker inspect`
# @param arguments [Array] Arguments to pass to the docker command
# e.g. 'src' and 'dest' for `docker cp <src> <dest>
# @return [Object] Ruby object representation of the JSON string
- private def execute_local_json_command(subcommand, arguments = [])
+ def execute_local_json_command(subcommand, arguments = [])
cmd = [subcommand, '--format', '{{json .}}'].concat(arguments)
- out, _err, _stat = Bolt::Util.exec_docker(cmd, env_hash)
+ out, _err, _stat = run_cmd(cmd, env_hash)
extract_json(out)
end
# Converts the JSON encoded STDOUT string from the docker cli into ruby objects
#