internal static string BuildDockerKillCommand(WaitForDockerConfig config, IEnumerable <ServicePort> servicePorts)
        {
            var cmd = new StringBuilder();
            var changeDirCommand = GetChangeDirCommand(config.DockerComposeDirPath);

            cmd.Append(changeDirCommand);
            cmd.Append(string.Join(" && ", servicePorts.Select(x => x.Name).Distinct().Select(x => string.Format(DockerKill, $"{config.DockerComposeProjectName}_{x}_1"))));
            return(cmd.ToString());
        }
Exemplo n.º 2
0
        public DockerFixture(IMessageSink messageSink)
        {
            var logger = new DefaultLogger();

            config = new WaitForDockerConfigurationBuilder()
                     .SetCustomLogger(logger)
                     .AddHealthCheck(check => check.WithHttp("rabbitmq", new Uri("http://localhost:15672"), portOfDistinction: 15672))
                     .AddHealthCheck(check => check.WithCmd("rabbitmq", "rabbitmqctl status", portOfDistinction: 5672))
                     .AddHealthCheck(check => check.WithCustom(logger1 => new SomeHealthCheck("123", 1, null, logger1)))
                     .Build();
            WaitFor.DockerCompose(config).GetAwaiter().GetResult();
        }
Exemplo n.º 3
0
        public static Task Wait(WaitForDockerConfig config)
        {
            config = config ?? new WaitForDockerConfig();
            var composeYaml  = DockerFilesReader.ReadComposeContent(config.DockerComposeDirPath, config.ComposeFileName);
            var composeJson  = new JsonComposeConverter().Convert(composeYaml);
            var servicePorts = new JsonComposeServicesPortsExtractor().ExtractServicePorts(composeJson).ToArray();

            var killCommand = DockerCommandBuilder.BuildDockerKillCommand(config, servicePorts);

            ShellExecutorFactory.GetShellExecutor(config.Logger).Execute(killCommand, DockerConsts.DockerComposeKill);
            return(Task.CompletedTask);
        }
        internal static string BuildComposeCommand(WaitForDockerConfig config)
        {
            var cmd = new StringBuilder();
            var changeDirCommand = GetChangeDirCommand(config.DockerComposeDirPath);

            if (config.RenewAnonVolumes)
            {
                config.ComposeParams.Add(RenewAnonVolumes);
            }

            cmd.Append(changeDirCommand);
            cmd.Append(string.Format(ComposeUp, $"{DockerConsts.DockerComposeProjectNameParam} {config.DockerComposeProjectName}", string.Join(" ", config.ComposeParams)));
            return(cmd.ToString());
        }
Exemplo n.º 5
0
        public static async Task Wait(WaitForDockerConfig config)
        {
            config = config ?? new WaitForDockerConfig();
            var logger = config.Logger;

            logger.Log("Wait for docker has been started..");
            var composeYaml  = DockerFilesReader.ReadComposeContent(config.DockerComposeDirPath, config.ComposeFileName);
            var composeJson  = new JsonComposeConverter().Convert(composeYaml);
            var servicePorts = new JsonComposeServicesPortsExtractor().ExtractServicePorts(composeJson).ToArray();

            logger.Log($"Checking is any port is already occupied before {DockerConsts.DockerCompose} execution..");
            await DockerHealthCheckRunner.RunPreComposeHealthChecks(servicePorts, config.Logger);

            config.ExtendWithDefaultHealthChecks(servicePorts);
            var composeCommand = DockerCommandBuilder.BuildComposeCommand(config);

            ShellExecutorFactory.GetShellExecutor(config.Logger).Execute(composeCommand, DockerConsts.DockerCompose);

            await DockerHealthCheckRunner.RunPostComposeHealthChecks(config.HealthCheckers);

            logger.Log("All health checks returns success.");
            logger.Log("Wait for docker has been finished..");
        }
 public DockerHealthCheckFactory(WaitForDockerConfig config)
 => _config = config;
Exemplo n.º 7
0
 public static async Task DockerCompose(WaitForDockerConfig config = null)
 => await WaitForCompose.Wait(config);
Exemplo n.º 8
0
 public static async Task DockerKill(WaitForDockerConfig config = null)
 => await WaitForDockerKill.Wait(config);