From 0db6f2093324b1811231e07d7a10a4daf8087575 Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Sun, 24 Oct 2021 09:55:12 +0200 Subject: [PATCH] Move MemoryLimit to Execution Environment --- app/models/execution_environment.rb | 4 +++- app/views/execution_environments/_form.html.slim | 2 +- ...150317083739_add_memory_limit_to_execution_environments.rb | 2 +- lib/docker_client.rb | 2 -- spec/factories/execution_environment.rb | 2 +- spec/models/execution_environment_spec.rb | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/execution_environment.rb b/app/models/execution_environment.rb index 863138ad..3bb86331 100644 --- a/app/models/execution_environment.rb +++ b/app/models/execution_environment.rb @@ -8,6 +8,8 @@ class ExecutionEnvironment < ApplicationRecord VALIDATION_COMMAND = 'whoami' DEFAULT_CPU_LIMIT = 20 + DEFAULT_MEMORY_LIMIT = 256 + MINIMUM_MEMORY_LIMIT = 4 after_initialize :set_default_values @@ -21,7 +23,7 @@ class ExecutionEnvironment < ApplicationRecord validate :working_docker_image?, if: :validate_docker_image? validates :docker_image, presence: true validates :memory_limit, - numericality: {greater_than_or_equal_to: DockerClient::MINIMUM_MEMORY_LIMIT, only_integer: true}, presence: true + numericality: {greater_than_or_equal_to: MINIMUM_MEMORY_LIMIT, only_integer: true}, presence: true validates :network_enabled, boolean_presence: true validates :name, presence: true validates :permitted_execution_time, numericality: {only_integer: true}, presence: true diff --git a/app/views/execution_environments/_form.html.slim b/app/views/execution_environments/_form.html.slim index 6b74eeae..2a1122e8 100644 --- a/app/views/execution_environments/_form.html.slim +++ b/app/views/execution_environments/_form.html.slim @@ -19,7 +19,7 @@ .help-block.form-text = t('.hints.exposed_ports_list') .form-group = f.label(:memory_limit) - = f.number_field(:memory_limit, class: 'form-control', min: DockerClient::MINIMUM_MEMORY_LIMIT, value: f.object.memory_limit || DockerClient::DEFAULT_MEMORY_LIMIT) + = f.number_field(:memory_limit, class: 'form-control', min: ExecutionEnvironment::MINIMUM_MEMORY_LIMIT, value: f.object.memory_limit || ExecutionEnvironment::DEFAULT_MEMORY_LIMIT) .form-group = f.label(:cpu_limit) = f.number_field(:cpu_limit, class: 'form-control', min: 1, step: 1, value: f.object.cpu_limit || ExecutionEnvironment::DEFAULT_CPU_LIMIT) diff --git a/db/migrate/20150317083739_add_memory_limit_to_execution_environments.rb b/db/migrate/20150317083739_add_memory_limit_to_execution_environments.rb index 290f6c1b..05d4a7b7 100644 --- a/db/migrate/20150317083739_add_memory_limit_to_execution_environments.rb +++ b/db/migrate/20150317083739_add_memory_limit_to_execution_environments.rb @@ -6,7 +6,7 @@ class AddMemoryLimitToExecutionEnvironments < ActiveRecord::Migration[4.2] reversible do |direction| direction.up do - ExecutionEnvironment.update(memory_limit: DockerClient::DEFAULT_MEMORY_LIMIT) + ExecutionEnvironment.update(memory_limit: ExecutionEnvironment::DEFAULT_MEMORY_LIMIT) end end end diff --git a/lib/docker_client.rb b/lib/docker_client.rb index ff9a9f45..0517ff69 100644 --- a/lib/docker_client.rb +++ b/lib/docker_client.rb @@ -8,10 +8,8 @@ class DockerClient end CONTAINER_WORKSPACE_PATH = '/workspace' # '/home/python/workspace' #'/tmp/workspace' - DEFAULT_MEMORY_LIMIT = 256 # Ralf: I suggest to replace this with the environment variable. Ask Hauke why this is not the case! LOCAL_WORKSPACE_ROOT = File.expand_path(config[:workspace_root]) - MINIMUM_MEMORY_LIMIT = 4 RECYCLE_CONTAINERS = false RETRY_COUNT = 2 MINIMUM_CONTAINER_LIFETIME = 10.minutes diff --git a/spec/factories/execution_environment.rb b/spec/factories/execution_environment.rb index 94ecfdd4..c13c2292 100644 --- a/spec/factories/execution_environment.rb +++ b/spec/factories/execution_environment.rb @@ -152,7 +152,7 @@ FactoryBot.define do end trait :default_memory_limit do - memory_limit { DockerClient::DEFAULT_MEMORY_LIMIT } + memory_limit { ExecutionEnvironment::DEFAULT_MEMORY_LIMIT } end trait :default_cpu_limit do diff --git a/spec/models/execution_environment_spec.rb b/spec/models/execution_environment_spec.rb index e4dba06c..09fd1c0a 100644 --- a/spec/models/execution_environment_spec.rb +++ b/spec/models/execution_environment_spec.rb @@ -16,7 +16,7 @@ describe ExecutionEnvironment do end it 'validates the minimum value of the memory limit' do - execution_environment.update(memory_limit: DockerClient::MINIMUM_MEMORY_LIMIT / 2) + execution_environment.update(memory_limit: ExecutionEnvironment::MINIMUM_MEMORY_LIMIT / 2) expect(execution_environment.errors[:memory_limit]).to be_present end