Exemplo n.º 1
0
 public DockerRunnerTask(
     string submissionSource, string studentId, TimeSpan evaluationTimeout,
     ContainerConfig container,
     string submissionDirectoryInMachine, string submissionDirectoryInContainer,
     string artifactPathInMachine, string?artifactPathInContainer,
     ContainerConfig?serviceContainer = null)
     : base(submissionSource, studentId, evaluationTimeout)
 {
     this.Container = container;
     this.SubmissionDirectoryInMachine   = submissionDirectoryInMachine;
     this.SubmissionDirectoryInContainer = submissionDirectoryInContainer;
     this.ArtifactPathInMachine          = artifactPathInMachine;
     this.ArtifactPathInContainer        = artifactPathInContainer;
     this.ServiceContainer = serviceContainer;
 }
Exemplo n.º 2
0
        public static async Task <DockerContainer> CreateNewContainer(ContainerConfig config, Docker.DotNet.DockerClient docker, ILogger logger, CancellationToken cancellationToken, Action <Docker.DotNet.Models.CreateContainerParameters>?configure = null)
        {
            try
            {
                var createContainerParams = new Docker.DotNet.Models.CreateContainerParameters()
                {
                    Image      = config.ImageName,
                    Labels     = DockerObjectBase.LabelsForCreation,
                    HostConfig = new Docker.DotNet.Models.HostConfig()
                    {
                        Mounts = new List <Docker.DotNet.Models.Mount>()
                        {
                        }
                    },
                    Env = config.EnvVariables.ToList()
                };

                if (config.CreateParams != null && config.CreateParams.Any())
                {
                    setImageParameters(createContainerParams, config.CreateParams, logger);
                }

                configure?.Invoke(createContainerParams);

                var createContainerResponse = await docker.Containers.CreateContainerAsync(createContainerParams, cancellationToken);

                if (string.IsNullOrEmpty(createContainerResponse.ID))
                {
                    throw new Exception("Container create failed with unknown error");
                }

                logger.LogTrace($"Container created with ID {createContainerResponse.ID}");

                return(new DockerContainer(createContainerResponse.ID, logger, docker));
            }
            catch (Docker.DotNet.DockerImageNotFoundException)
            {
                throw new Exception($"Image {config.ImageName} not found.");
            }
            catch (Docker.DotNet.DockerApiException ex)
            {
                throw new Exception($"Container create failed with error: {ex.Message}", ex);
            }
        }