Example #1
0
        public void SetUp()
        {
            var config = TestHelper.InitConfiguration().Get <TestConfiguration>();

            _setting = new DockerSettings(config);
            this._setting.DockerComposePull();
            this._setting.DockerComposeUp();
        }
Example #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);
        }
Example #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);
     }
 }
Example #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}'");
            }
        }
Example #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;
 }