Exemplo n.º 1
0
        public void SetUp()
        {
            var config = TestHelper.InitConfiguration().Get <TestConfiguration>();

            _setting = new DockerSettings(config);
            this._setting.DockerComposePull();
            this._setting.DockerComposeUp();
        }
Exemplo n.º 2
0
        public static void DockerComposeDown(this DockerSettings settings)
        {
            var processInfo = new ProcessStartInfo()
            {
                FileName  = "docker-compose",
                Arguments = $"-f {settings.DockerComposePath} down --rmi local"
            };

            AddEnvironmentVariables(processInfo, settings);

            var process = Process.Start(processInfo);

            process.WaitForExit();
            process.ExitCode.Should().Be(0);
        }
Exemplo n.º 3
0
 private static async Task <bool> WaitForDockerUp(DockerSettings settings)
 {
     using (var client = new WebClient())
     {
         var result = Policy.Handle <Exception>().
                      WaitAndRetryAsync(settings.RetryAttemps, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
                      .ExecuteAsync(async() =>
         {
             string HTMLSource = await client.DownloadStringTaskAsync(new Uri(settings.Url));
             return(true);
         })
                      .GetAwaiter()
                      .GetResult();
         return(result);
     }
 }
Exemplo n.º 4
0
        public static void DockerComposeUp(this DockerSettings settings)
        {
            var processInfo = new ProcessStartInfo()
            {
                FileName  = "docker-compose",
                Arguments = $"-f {settings.DockerComposePath} up -d"
            };

            AddEnvironmentVariables(processInfo, settings);
            var process = Process.Start(processInfo);

            process.WaitForExit();
            process.ExitCode.Should().Be(0);
            var up = WaitForDockerUp(settings).Result;

            if (!up)
            {
                throw new Exception($"Startup failed, could not get '{settings.Ip}:{settings.ExternalPort}'");
            }
        }
Exemplo n.º 5
0
 private static void AddEnvironmentVariables(ProcessStartInfo processStartInfo, DockerSettings variables)
 {
     processStartInfo.Environment["TAG"]          = variables.Tag;
     processStartInfo.Environment["COMPUTERNAME"] = variables.MachineName;
     processStartInfo.Environment["ExternalPort"] = variables.ExternalPort;
 }