Пример #1
0
 private async Task CreateNetworkAsync()
 {
     if (dockerEngineOsPlatform == OSPlatform.Linux || dockerEngineOsPlatform == OSPlatform.OSX)
     {
         await dockerProxy.CreateNetworkAsync(dockerNetworkName).ConfigureAwait(false);
     }
 }
        public async Task InitializeAsync()
        {
            dockerEngineOsPlatform = await dockerProxy.GetDockerEngineOsAsync();

            dockerNetworkName = dockerEngineOsPlatform == OSPlatform.Windows ? null : "bridgeWhaleNet";
            var rabbitMQDockerImage = Configuration.RabbitMQDockerImage(dockerEngineOsPlatform);

            await DisposeAsync().ConfigureAwait(false);

            if (dockerEngineOsPlatform == OSPlatform.Linux || dockerEngineOsPlatform == OSPlatform.OSX)
            {
                await dockerProxy.CreateNetworkAsync(dockerNetworkName).ConfigureAwait(false);
            }

            await dockerProxy.PullImageAsync(rabbitMQDockerImage, RabbitImageTag).ConfigureAwait(false);

            var portMappings = new Dictionary <string, ISet <string> >
            {
                { "4369", new HashSet <string>()
                  {
                      "4369"
                  } },
                { "5671", new HashSet <string>()
                  {
                      "5671"
                  } },
                { "5672", new HashSet <string>()
                  {
                      "5672"
                  } },
                { "15671", new HashSet <string>()
                  {
                      "15671"
                  } },
                { "15672", new HashSet <string>()
                  {
                      "15672"
                  } },
                { "25672", new HashSet <string>()
                  {
                      "25672"
                  } }
            };
            var envVars = new List <string> {
                $"RABBITMQ_DEFAULT_VHOST={Configuration.RabbitMqVirtualHostName}"
            };
            var containerId = await dockerProxy
                              .CreateContainerAsync(rabbitMQDockerImage, RabbitContainerAndHostName, portMappings, dockerNetworkName, envVars)
                              .ConfigureAwait(false);

            await dockerProxy.StartContainerAsync(containerId).ConfigureAwait(false);

            RabbitContainerHostForManagement = "localhost";
            if (dockerEngineOsPlatform == OSPlatform.Windows)
            {
                RabbitContainerHostForManagement = await dockerProxy.GetContainerIpAsync(containerId).ConfigureAwait(false);
            }
            var timeoutCts = new CancellationTokenSource(TimeSpan.FromSeconds(DefaultTimeoutSeconds));

            await WaitForRabbitMqReady(timeoutCts.Token).ConfigureAwait(false);
        }