diff --git a/Gemfile b/Gemfile index 5269fe34..e77ae876 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gem 'carrierwave' gem 'coffee-rails', '~> 4.0.0' gem 'concurrent-ruby', '~> 1.0.0' gem 'concurrent-ruby-ext', '~> 1.0.0', platform: :ruby -gem 'docker-api','~> 1.21.1', require: 'docker' +gem 'docker-api','~> 1.25.0', require: 'docker' gem 'factory_girl_rails', '~> 4.0' gem 'forgery' gem 'highline' diff --git a/Gemfile.lock b/Gemfile.lock index 5972ea79..268f8596 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,13 +103,13 @@ GEM debug_inspector (0.0.2) diff-lcs (1.2.5) docile (1.1.5) - docker-api (1.21.1) + docker-api (1.25.0) excon (>= 0.38.0) json erubis (2.7.0) eventmachine (1.0.8) eventmachine (1.0.8-java) - excon (0.45.2) + excon (0.45.4) execjs (2.5.2) factory_girl (4.5.0) activesupport (>= 3.0.0) @@ -350,7 +350,7 @@ DEPENDENCIES concurrent-ruby (~> 1.0.0) concurrent-ruby-ext (~> 1.0.0) database_cleaner - docker-api (~> 1.21.1) + docker-api (~> 1.25.0) factory_girl_rails (~> 4.0) faye-websocket forgery diff --git a/lib/docker_client.rb b/lib/docker_client.rb index 4ac5836d..67f77bfc 100644 --- a/lib/docker_client.rb +++ b/lib/docker_client.rb @@ -128,6 +128,23 @@ class DockerClient end private :create_workspace_file + def create_workspace_files_transmit(container, submission) + # create a temporary dir, put all files in it, and put it into the container. the dir is automatically removed when leaving the block. + Dir.mktmpdir {|dir| + submission.collect_files.each do |file| + disk_file = File.new(dir + '/' + (file.path || '') + file.name_with_extension, 'w') + disk_file.write(file.content) + disk_file.close + end + + # tar the files in dir and put the tar to CONTAINER_WORKSPACE_PATH in the container + container.archive_in(dir, CONTAINER_WORKSPACE_PATH, overwrite: false) + + # untar the tar file placed in the CONTAINER_WORKSPACE_PATH + container.exec(['bash', '-c', 'tar -xf ' + CONTAINER_WORKSPACE_PATH + '/' + dir.split('/tmp/')[1] + ' -C ' + CONTAINER_WORKSPACE_PATH]) + } + end + def self.destroy_container(container) Rails.logger.info('destroying container ' + container.to_s) container.stop.kill @@ -242,7 +259,7 @@ class DockerClient Run commands by attaching a websocket to Docker. """ command = submission.execution_environment.run_command % command_substitutions(filename) - create_workspace_files = proc { create_workspace_files(container, submission) } + create_workspace_files = proc { create_workspace_files_transmit(container, submission) } execute_websocket_command(command, create_workspace_files, block) end @@ -251,7 +268,7 @@ class DockerClient Stick to existing Docker API with exec command. """ command = submission.execution_environment.test_command % command_substitutions(filename) - create_workspace_files = proc { create_workspace_files(container, submission) } + create_workspace_files = proc { create_workspace_files_transmit(container, submission) } execute_command(command, create_workspace_files, block) end