Remove usage of DockerClient from execution_environments_controller.rb

This commit is contained in:
Sebastian Serth
2021-10-24 11:21:24 +02:00
parent 541afa92f3
commit 2b98905acb
5 changed files with 25 additions and 5 deletions

View File

@ -133,12 +133,12 @@ class ExecutionEnvironmentsController < ApplicationController
end
def set_docker_images
DockerClient.check_availability!
@docker_images = DockerClient.image_tags.sort
rescue DockerClient::Error => e
@docker_images = []
@docker_images ||= ExecutionEnvironment.pluck(:docker_image)
@docker_images += Runner.strategy_class.available_images
rescue Runner::Error::InternalServerError => e
flash[:warning] = e.message
Sentry.capture_exception(e)
ensure
@docker_images = @docker_images.sort.uniq
end
private :set_docker_images

View File

@ -9,6 +9,10 @@ class Runner::Strategy
raise NotImplementedError
end
def self.available_images
raise NotImplementedError
end
def self.sync_environment(_environment)
raise NotImplementedError
end

View File

@ -8,6 +8,13 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
@config ||= CodeOcean::Config.new(:docker).read(erb: true)
end
def self.available_images
DockerClient.check_availability!
DockerClient.image_tags
rescue DockerClient::Error => e
raise Runner::Error::InternalServerError.new(e.message)
end
def self.sync_environment(_environment)
# There is no dedicated sync mechanism yet
true

View File

@ -13,6 +13,13 @@ class Runner::Strategy::Poseidon < Runner::Strategy
@config ||= CodeOcean::Config.new(:code_ocean).read[:runner_management] || {}
end
def self.available_images
# Images are pulled when needed for a new execution environment
# and cleaned up automatically if no longer in use.
# Hence, there is no additional image that we need to return
[]
end
def self.headers
@headers ||= {'Content-Type' => 'application/json', 'Poseidon-Token' => config[:token]}
end

View File

@ -114,6 +114,7 @@ describe ExecutionEnvironmentsController do
let(:docker_images) { [1, 2, 3] }
before do
allow(Runner).to receive(:strategy_class).and_return Runner::Strategy::DockerContainerPool
allow(DockerClient).to receive(:check_availability!).at_least(:once)
allow(DockerClient).to receive(:image_tags).and_return(docker_images)
controller.send(:set_docker_images)
@ -126,6 +127,7 @@ describe ExecutionEnvironmentsController do
let(:error_message) { 'Docker is unavailable' }
before do
allow(Runner).to receive(:strategy_class).and_return Runner::Strategy::DockerContainerPool
allow(DockerClient).to receive(:check_availability!).at_least(:once).and_raise(DockerClient::Error.new(error_message))
controller.send(:set_docker_images)
end