Пример #1
0
        public static CreateContainerParametersBuilder CreateFromContainer(Container container)
        {
            var imageId = new DockerImageId(container.ImageName, container.ImageVersion);
            var builder = new CreateContainerParametersBuilder(imageId, container.Name);

            foreach (var(name, value) in DockerLabelHelper.CreateForContainer(container))
            {
                builder.AddLabel(name, value);
            }

            foreach (var binding in container.ServerPorts)
            {
                builder.AddPortBinding(binding.ContainerPort, binding.HostPort);
            }

            foreach (var volume in container.Volumes)
            {
                builder.AddVolumeMount(
                    volume.DockerName,
                    volume.ContainerMountPoint,
                    DockerLabelHelper.CreateForVolume(container, volume)
                    );
            }

            foreach (var argument in container.Arguments)
            {
                builder.AddEnvironmentVariable(argument);
            }

            return(builder);
        }
Пример #2
0
        private async Task <bool> BuildImageSourceAsync(
            DockerImageId imageId,
            IDirectoryInfo sourceDirectory,
            DockerClient dockerClient
            )
        {
            using var loggerScope = _logger.BeginScope($"Building docker image from {sourceDirectory.FullName}");

            var response = new LoggedResponse(_logger);

            try
            {
                if (await CheckImageExistsAsync(imageId, dockerClient))
                {
                    return(true);
                }

                _logger.LogInformation("Creating tar stream from directory");

                var builder      = new TarBuilder();
                var sourceStream = await builder.BuildFromDirectory(sourceDirectory);

                _logger.LogInformation("Creating Docker image from tar stream");

                using var dockerResponseStream = await dockerClient.Images.BuildImageFromDockerfileAsync(sourceStream, new ImageBuildParameters
                {
                    Tags = new List <string>
                    {
                        imageId.FullName
                    },
                    Labels = DockerLabelHelper.CreateBaseLabels()
                });

                if (!await DockerBuildHelper.ValidateBuildAsync(dockerResponseStream, _logger))
                {
                    throw new Exception($"Docker build returned an error, lol soz (TODO: maybe log the error, Paul?)");
                }

                return(true);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Unable to build Docker image");
            }

            return(false);
        }
Пример #3
0
        public static CreateContainerParametersBuilder CreateStorageServer(Server server)
        {
            var imageId       = new DockerImageId("triceratops_volumeinspector", "1.0");
            var containerName = NameHelper.SanitiseHostname($"Triceratops.StorageServer.{server.Name}");

            var builder = new CreateContainerParametersBuilder(imageId, containerName)
                          .AddLabels(DockerLabelHelper.CreateForTemporaryContainer());

            foreach (var volume in ServerVolumeIdentifier.CreateForServer(server))
            {
                builder.AddVolumeMount(
                    volume.VolumeName,
                    volume.CreateMountDestination(Constants.VolumeInspectorVolumesPath),
                    new Dictionary <string, string>(0)
                    );
            }
            ;

            return(builder);
        }