lib/bolt/transport/docker/connection.rb
def execute(*command, options)
          command.unshift(options[:interpreter]) if options[:interpreter]
          # Build the `--env` parameters
          envs = []
          if options[:environment]
            options[:environment].each { |env, val| envs.concat(['--env', "#{env}=#{val}"]) }
          end

          command_options = []
          # Need to be interactive if redirecting STDIN
          command_options << '--interactive' unless options[:stdin].nil?
          command_options << '--tty' if options[:tty]
          command_options.concat(envs) unless envs.empty?
          command_options << container_id
          command_options.concat(command)

          @logger.debug { "Executing: exec #{command_options}" }

          stdout_str, stderr_str, status = execute_local_docker_command('exec', command_options, options[:stdin])

          # The actual result is the exitstatus not the process object
          status = status.nil? ? -32768 : status.exitstatus
          if status == 0
            @logger.debug { "Command returned successfully" }
          else
            @logger.info { "Command failed with exit code #{status}" }
          end
          stdout_str.force_encoding(Encoding::UTF_8)
          stderr_str.force_encoding(Encoding::UTF_8)
          # Normalise line endings
          stdout_str.gsub!("\r\n", "\n")
          stderr_str.gsub!("\r\n", "\n")
          [stdout_str, stderr_str, status]
        rescue StandardError
          @logger.debug { "Command aborted" }
          raise
        end
# Executes a command inside the target container
#
# @param command [Array] The command to run, expressed as an array of strings
# @param options [Hash] command specific options
# @option opts [String] :interpreter statements that are prefixed to the command e.g `/bin/bash` or `cmd.exe /c`
# @option opts [Hash] :environment A hash of environment variables that will be injected into the command
# @option opts [IO] :stdin An IO object that will be used to redirect STDIN for the docker command
Executes a command inside the target container
Executes a command inside the target container
def execute(*command, options)
          command.unshift(options[:interpreter]) if options[:interpreter]
          envs = []
          if options[:environment]
            options[:environment].each { |env, val| envs.concat(['--env', "#{env}=#{val}"]) }
          end
          command_options = []
          command_options << '--interactive' unless options[:stdin].nil?
          command_options << '--tty' if options[:tty]
          command_options.concat(envs) unless envs.empty?
          command_options << container_id
          command_options.concat(command)
          @logger.debug { "Executing: exec #{command_options}" }
          stdout_str, stderr_str, status = execute_local_docker_command('exec', command_options, options[:stdin])
          status = status.nil? ? -32768 : status.exitstatus
          if status == 0
            @logger.debug { "Command returned successfully" }
          else
            @logger.info { "Command failed with exit code #{status}" }
          end
          stdout_str.force_encoding(Encoding::UTF_8)
          stderr_str.force_encoding(Encoding::UTF_8)
          stdout_str.gsub!("\r\n", "\n")
          stderr_str.gsub!("\r\n", "\n")
          [stdout_str, stderr_str, status]
        rescue StandardError
          @logger.debug { "Command aborted" }
          raise
        end
def execute ( * command , options ) command . unshift ( options [ :interpreter ] ) if options [ :interpreter ] envs = [ ] if options [ :environment ] options [ :environment ] . each { | env , val | envs . concat ( [ '--env' , "#{env}=#{val}" ] ) } end command_options = [ ] command_options << '--interactive' unless options [ :stdin ] . nil? command_options << '--tty' if options [ :tty ] command_options . concat ( envs ) unless envs . empty? command_options << container_id command_options . concat ( command ) @logger . debug { "Executing: exec #{command_options}" } stdout_str , stderr_str , status = execute_local_docker_command ( 'exec' , command_options , options [ :stdin ] ) status = status . nil? ? - 32768 : status . exitstatus if status == 0 @logger . debug { "Command returned successfully" } else @logger . info { "Command failed with exit code #{status}" } end stdout_str . force_encoding ( Encoding :: UTF_8 ) stderr_str . force_encoding ( Encoding :: UTF_8 ) stdout_str . gsub! ( "\r\n" , "\n" ) stderr_str . gsub! ( "\r\n" , "\n" ) [ stdout_str , stderr_str , status ] rescue StandardError @logger . debug { "Command aborted" } raise end
Executes a command inside the target container
Executes a command inside the target container
# Build the `--env` parameters # Need to be interactive if redirecting STDIN # The actual result is the exitstatus not the process object # Normalise line endings
command
The command to run, expressed as an array of strings
The command to run expressed as an array of strings
options
command specific options
command specific options
opts
:stdin An IO object that will be used to redirect STDIN for the docker command
: stdin An IO object that will be used to redirect STDIN for the docker command