public async Task <RunnerResult> Run() { using var docker = DockerConnectionHelper.GetConnectionConfiguration().CreateClient(); logger.LogTrace($"Created Docker runner for source {task.SubmissionSource} student {task.StudentId}"); try { using var timeout = new CancellationTokenSource(task.EvaluationTimeout); using var tempDirectoryForSolutionCopy = tempPathProvider.GetTempDirectory(); var solutionFolderToMount = await extractSolutionGetEffectiveDirectory(task.SubmissionDirectoryInMachine, tempDirectoryForSolutionCopy.Path); var containerConsoleLog = await runCore(docker, timeout.Token, solutionFolderToMount); logger.LogInformation("Docker runner finished"); return(RunnerResult.Success(containerConsoleLog)); } catch (OperationCanceledException) { logger.LogWarning("Docker runner timeout"); return(RunnerResult.Timeout(string.Empty)); } catch (Exception ex) { logger.LogError(ex, "Docker runner failed"); return(RunnerResult.Failed(string.Empty, ex)); } }
public static async Task Pull(ImageName imageName) { using var docker = DockerConnectionHelper.GetConnectionConfiguration().CreateClient(); await docker.Images.CreateImageAsync(new Docker.DotNet.Models.ImagesCreateParameters() { FromImage = imageName }, null, new Progress <Docker.DotNet.Models.JSONMessage>()); }
public static async Task Cleanup(ILogger logger) { using (var docker = DockerConnectionHelper.GetConnectionConfiguration().CreateClient()) { // containers first, then networks so that no container is connected to a network await cleanupContainers(logger, docker); await cleanupNetworks(logger, docker); } }
public static async Task <bool> CheckImageExists(ImageName imageName) { using var docker = DockerConnectionHelper.GetConnectionConfiguration().CreateClient(); var findImageResult = await docker.Images.ListImagesAsync(new Docker.DotNet.Models.ImagesListParameters() { Filters = new Dictionary <string, IDictionary <string, bool> >() { ["reference"] = new Dictionary <string, bool>() { [imageName] = true } }, All = false }); return(findImageResult.Any()); }