Merge branch 'master' of https://github.com/openHPI/codeocean
Conflicts: lib/docker_client.rb
This commit is contained in:
@ -5,6 +5,7 @@ class DockerClient
|
||||
DEFAULT_MEMORY_LIMIT = 256
|
||||
LOCAL_WORKSPACE_ROOT = Rails.root.join('tmp', 'files', Rails.env)
|
||||
MINIMUM_MEMORY_LIMIT = 4
|
||||
RECYCLE_CONTAINERS = true
|
||||
RETRY_COUNT = 2
|
||||
|
||||
attr_reader :container
|
||||
@ -161,19 +162,19 @@ class DockerClient
|
||||
`docker pull #{docker_image}` if docker_image
|
||||
end
|
||||
|
||||
#this sends the command to run whatever is defined in the backend
|
||||
def return_container(container)
|
||||
local_workspace_path = self.class.local_workspace_path(container)
|
||||
FileUtils.rm_rf(local_workspace_path) if local_workspace_path
|
||||
FileUtils.mkdir(local_workspace_path)
|
||||
DockerContainerPool.return_container(container, @execution_environment)
|
||||
end
|
||||
private :return_container
|
||||
|
||||
def send_command(command, container, &block)
|
||||
Timeout.timeout(@execution_environment.permitted_execution_time.to_i) do
|
||||
stderr = []
|
||||
stdout = []
|
||||
# map command in a shell call, maybe add -c
|
||||
command = ['bash', '-c', command]
|
||||
#command.join!(' ')
|
||||
# lets call the command, but we do not want the container to stop afterwards
|
||||
# thats why we use exec. If its ok do stop the container this could be assign instead
|
||||
container.exec(command) do |stream, chunk|
|
||||
#container.attach(stdin: StringIO.new(command)) do |stream, chunk|
|
||||
|
||||
container.exec(['bash', '-c', command]) do |stream, chunk|
|
||||
block.call(stream, chunk) if block_given?
|
||||
if stream == :stderr
|
||||
stderr.push(chunk)
|
||||
@ -186,16 +187,7 @@ class DockerClient
|
||||
rescue Timeout::Error
|
||||
{status: :timeout}
|
||||
ensure
|
||||
Concurrent::Future.execute {
|
||||
# If you do not want to reuse running container you could use:
|
||||
#self.class.destroy_container(container)
|
||||
# This could be moved to an execution environment specific setting
|
||||
|
||||
# we may need to stop the exec call here..!!!
|
||||
FileUtils.rm_rf(local_workspace_path(container)) if local_workspace_path(container)
|
||||
FileUtils.mkdir(local_workspace_path(container))
|
||||
DockerContainerPool.return_container(container, @execution_environment)
|
||||
}
|
||||
RECYCLE_CONTAINERS ? return_container(container) : self.class.destroy_container(container)
|
||||
end
|
||||
private :send_command
|
||||
|
||||
|
Reference in New Issue
Block a user