implemented pooling for Docker containers
This commit is contained in:
@ -25,11 +25,11 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
|
||||
def execute_command
|
||||
@docker_client = DockerClient.new(execution_environment: @execution_environment, user: current_user)
|
||||
render(json: @docker_client.execute_command(params[:command]))
|
||||
render(json: @docker_client.execute_arbitrary_command(params[:command]))
|
||||
end
|
||||
|
||||
def execution_environment_params
|
||||
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :help, :indent_size, :name, :permitted_execution_time, :run_command, :test_command, :testing_framework).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :help, :indent_size, :name, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||
end
|
||||
private :execution_environment_params
|
||||
|
||||
@ -44,6 +44,7 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
end
|
||||
|
||||
def set_docker_images
|
||||
DockerClient.check_availability!
|
||||
@docker_images = DockerClient.image_tags.sort
|
||||
rescue DockerClient::Error => error
|
||||
@docker_images = []
|
||||
|
@ -3,6 +3,8 @@ class ExecutionEnvironment < ActiveRecord::Base
|
||||
|
||||
VALIDATION_COMMAND = 'whoami'
|
||||
|
||||
after_initialize :set_default_values
|
||||
|
||||
has_many :exercises
|
||||
has_many :hints
|
||||
|
||||
@ -13,8 +15,15 @@ class ExecutionEnvironment < ActiveRecord::Base
|
||||
validates :docker_image, presence: true
|
||||
validates :name, presence: true
|
||||
validates :permitted_execution_time, numericality: {only_integer: true}, presence: true
|
||||
validates :pool_size, numericality: {only_integer: true}, presence: true
|
||||
validates :run_command, presence: true
|
||||
|
||||
def set_default_values
|
||||
self.permitted_execution_time ||= 60
|
||||
self.pool_size ||= 0
|
||||
end
|
||||
private :set_default_values
|
||||
|
||||
def to_s
|
||||
name
|
||||
end
|
||||
@ -27,13 +36,13 @@ class ExecutionEnvironment < ActiveRecord::Base
|
||||
private :valid_test_setup?
|
||||
|
||||
def validate_docker_image?
|
||||
docker_image.present? && Rails.env != 'test'
|
||||
docker_image.present? && !Rails.env.test?
|
||||
end
|
||||
private :validate_docker_image?
|
||||
|
||||
def working_docker_image?
|
||||
DockerClient.pull(docker_image) unless DockerClient.image_tags.include?(docker_image)
|
||||
output = DockerClient.new(execution_environment: self).execute_command(VALIDATION_COMMAND)
|
||||
output = DockerClient.new(execution_environment: self).execute_arbitrary_command(VALIDATION_COMMAND)
|
||||
errors.add(:docker_image, "error: #{output[:stderr]}") if output[:stderr].present?
|
||||
rescue DockerClient::Error => error
|
||||
errors.add(:docker_image, "error: #{error}")
|
||||
|
@ -17,6 +17,9 @@
|
||||
.form-group
|
||||
= f.label(:permitted_execution_time)
|
||||
= f.number_field(:permitted_execution_time, class: 'form-control', min: 1)
|
||||
.form-group
|
||||
= f.label(:pool_size)
|
||||
= f.number_field(:pool_size, class: 'form-control', min: 0)
|
||||
.form-group
|
||||
= f.label(:run_command)
|
||||
= f.text_field(:run_command, class: 'form-control', placeholder: 'command %{filename}', required: true)
|
||||
|
@ -4,7 +4,7 @@ h1
|
||||
|
||||
= row(label: 'execution_environment.name', value: @execution_environment.name)
|
||||
= row(label: 'execution_environment.user', value: link_to(@execution_environment.author, @execution_environment.author))
|
||||
- [:docker_image, :exposed_ports, :permitted_execution_time, :run_command, :test_command].each do |attribute|
|
||||
- [:docker_image, :exposed_ports, :permitted_execution_time, :pool_size, :run_command, :test_command].each do |attribute|
|
||||
= row(label: "execution_environment.#{attribute}", value: @execution_environment.send(attribute))
|
||||
= row(label: 'execution_environment.testing_framework', value: @testing_framework_adapter.try(:framework_name))
|
||||
= row(label: 'execution_environment.help', value: render_markdown(@execution_environment.help))
|
||||
|
Reference in New Issue
Block a user