Copy output to file and stdout / stderr

This commit is contained in:
Sebastian Serth
2020-05-12 17:38:42 +02:00
parent daa39336fb
commit d912062abd

View File

@ -450,10 +450,10 @@ class DockerClient
def send_command(command, container) def send_command(command, container)
result = {status: :failed, stdout: '', stderr: ''} result = {status: :failed, stdout: '', stderr: ''}
output = nil output = nil
Timeout.timeout(@execution_environment.permitted_execution_time.to_i - 29) do Timeout.timeout(@execution_environment.permitted_execution_time.to_i) do
# TODO: check phusion doku again if we need -i -t options here # TODO: check phusion doku again if we need -i -t options here
# https://stackoverflow.com/questions/363223/how-do-i-get-both-stdout-and-stderr-to-go-to-the-terminal-and-a-log-file # https://stackoverflow.com/questions/363223/how-do-i-get-both-stdout-and-stderr-to-go-to-the-terminal-and-a-log-file
output = container.exec(['bash', '-c', "#{command} 1> >(tee /proc/1/fd/1) 2> >(tee /proc/1/fd/2 >&2)"], tty: false) output = container.exec(['bash', '-c', "#{command} 1> >(tee -a /tmp/stdout.log) 2> >(tee -a /tmp/stderr.log >&2); rm /tmp/std*.log"], tty: false)
end end
Rails.logger.debug 'output from container.exec' Rails.logger.debug 'output from container.exec'
Rails.logger.debug output Rails.logger.debug output
@ -468,8 +468,8 @@ class DockerClient
result result
rescue Timeout::Error rescue Timeout::Error
Rails.logger.info('got timeout error for container ' + container.to_s) Rails.logger.info('got timeout error for container ' + container.to_s)
stdout = container.logs(stdout: true).force_encoding('utf-8').gsub(/.*\/workspace\$\ /, '') stdout = container.exec(['cat', '/tmp/stdout.log'])[0].join.force_encoding('utf-8')
stderr = container.logs(stderr: true).force_encoding('utf-8').gsub(/.*\/workspace\$\ /, '') stderr = container.exec(['cat', '/tmp/stderr.log'])[0].join.force_encoding('utf-8')
kill_container(container) kill_container(container)
{status: :timeout, stdout: stdout, stderr: stderr} {status: :timeout, stdout: stdout, stderr: stderr}
end end