class Mumukit::IsolatedEnvironment
Attributes
container[RW]
Public Instance Methods
configure!(*files) { |*filenames| ... }
click to toggle source
# File lib/mumukit/isolated_environment.rb, line 9 def configure!(*files) filenames = files.map { |it| File.absolute_path(it.path) } dirnames = filenames.map { |it| Pathname.new(it).dirname }.uniq binds = dirnames.map { |it| "#{it}:#{it}" } command = yield(*filenames) command = command.split if command.is_a? String configure_container! command, binds end
configure_container!(command, binds)
click to toggle source
# File lib/mumukit/isolated_environment.rb, line 21 def configure_container!(command, binds) self.container = Docker::Container.create( image: Mumukit.config.docker_image, cmd: command, hostConfig: { binds: binds, pidsLimit: Mumukit.config.pids_limit }, networkDisabled: true) end
destroy!()
click to toggle source
# File lib/mumukit/isolated_environment.rb, line 56 def destroy! if container container.stop container.delete end end
fetch_container_state!()
click to toggle source
# File lib/mumukit/isolated_environment.rb, line 50 def fetch_container_state! exit = container.json['State']['ExitCode'] out = container.streaming_logs(stdout: true, stderr: true) [exit, out] end
run!()
click to toggle source
# File lib/mumukit/isolated_environment.rb, line 32 def run! run_container! exit, out = fetch_container_state! if exit == 0 [out, :passed] else [out, :failed] end rescue Docker::Error::TimeoutError => e [I18n.t('mumukit.time_exceeded', limit: Mumukit.config.command_time_limit), :aborted] end
run_container!()
click to toggle source
# File lib/mumukit/isolated_environment.rb, line 45 def run_container! container.start container.wait(Mumukit.config.command_time_limit) end