Пример #1
0
        public async Task InitializeAsync()
        {
            var webHostUrl = FixtureUtils.IsRunningInContainer
                ? FixtureUtils.GetLocalIPAddress()
                : "127.0.0.1";

            var settings = new LambdaTestHostSettings(() => new TestLambdaContext())
            {
                WebHostUrl       = $"http://{webHostUrl}:0",
                ConfigureLogging = logging =>
                {
                    logging.AddXUnit(_outputHelper);
                    logging.SetMinimumLevel(LogLevel.Debug);
                }
            };

            settings.AddFunction(new LambdaFunctionInfo(
                                     nameof(SimpleLambdaFunction),
                                     typeof(SimpleLambdaFunction),
                                     nameof(SimpleLambdaFunction.FunctionHandler)));
            _lambdaTestHost = await LambdaTestHost.Start(settings);

            var lambdaInvokeEndpoint = FixtureUtils.GetLambdaInvokeEndpoint(_outputHelper, _lambdaTestHost);

            _stepFunctionsLocal = new Builder()
                                  .UseContainer()
                                  .WithName("lambda-testhost-stepfunctions")
                                  .UseImage("amazon/aws-stepfunctions-local:latest")
                                  .WithEnvironment($"LAMBDA_ENDPOINT={lambdaInvokeEndpoint}")
                                  .ReuseIfExists()
                                  .ExposePort(0, ContainerPort)
                                  .Build()
                                  .Start();

            var exposedPort = _stepFunctionsLocal
                              .GetConfiguration()
                              .NetworkSettings
                              .Ports.First()
                              .Value.First()
                              .HostPort;

            var stepFunctionsServiceUrl = new UriBuilder($"http://localhost:{exposedPort}");

            if (FixtureUtils.IsRunningInContainer)
            {
                var host = _stepFunctionsLocal
                           .GetConfiguration()
                           .NetworkSettings
                           .IPAddress;

                stepFunctionsServiceUrl.Host = host;
                stepFunctionsServiceUrl.Port = ContainerPort;
            }

            _stepFunctionsServiceUrl = stepFunctionsServiceUrl.Uri;
        }
Пример #2
0
        public ContainerModel(IContainerService container)
        {
            var config = container.GetConfiguration();

            this.Id        = container.Id;
            this.Name      = config.Name;
            this.Image     = container.Image.Name;
            this.IsWindows = container.IsWindowsContainer;
            this.State     = container.State.ToString();
        }
Пример #3
0
 public void UpdateStatusOnRunning(IContainerService container)
 {
     if (container.State == ServiceRunningState.Running)
     {
         var config = container.GetConfiguration();
         this.Id    = this.Id = container.Id;
         this.Name  = config.Name;
         this.Image = container.Image.Name;
         if (container.IsWindowsContainer)
         {
             Platform = "Windows";
         }
         else
         {
             Platform = "Linux";
         }
         this.State = container.State.ToString();
     }
 }
Пример #4
0
        /// <summary>
        ///   Waits for the container to be in a healthy state
        /// </summary>
        /// <param name="service">The service to check processes within.</param>
        /// <param name="millisTimeout">Timeout giving up the wait.</param>
        /// <returns>The in param service.</returns>
        public static IContainerService WaitForHealthy(this IContainerService service, long millisTimeout = -1)
        {
            if (service == null)
            {
                return(null);
            }

            Exception exception = null;
            var       stopwatch = Stopwatch.StartNew();

            using (var mre = new ManualResetEventSlim())
            {
                Timer timer;
                using (timer = new Timer(_ =>
                {
                    var config = service.GetConfiguration(true);
                    if (config?.State?.Health?.Status == HealthState.Healthy)
                    {
                        mre.Set();
                    }
                    if (stopwatch.ElapsedMilliseconds > millisTimeout)
                    {
                        exception = new FluentDockerException($"Wait for healthy expired for container {service.Id}");
                        mre.Set();
                    }
                }, null, 0, 500))

                    mre.Wait();
                timer.Dispose();
            }

            if (exception != null)
            {
                throw exception;
            }

            return(service);
        }
Пример #5
0
        public static void WaitForRunning(this IContainerService container)
        {
            Exception exception = null;

            using (var mre = new ManualResetEventSlim())
                using (new Timer(_ =>
                {
                    var state = container.GetConfiguration(true).State;
                    if (!string.IsNullOrWhiteSpace(state.Error))
                    {
                        exception = new FluentDockerException($"Unable to start container: {state.Error}");
                        mre.Set();
                    }
                    if (state.ToServiceState() == ServiceRunningState.Running)
                    {
                        mre.Set();
                    }
                }, null, 0, 500))
                    mre.Wait();
            if (exception != null)
            {
                throw exception;
            }
        }
Пример #6
0
 /// <summary>
 ///   Translates a docker exposed port and protocol (on format 'port/proto' e.g. '534/tcp') to a
 ///   host endpoint that can be contacted outside the container.
 /// </summary>
 /// <param name="service">The container to query.</param>
 /// <param name="portAndProto">The port slash protocol to translate to a host based <see cref="IPEndPoint" />.</param>
 /// <returns>A host based endpoint from a exposed port or null if none.</returns>
 public static IPEndPoint ToHostExposedEndpoint(this IContainerService service, string portAndProto)
 {
     return(service.GetConfiguration()?.NetworkSettings.Ports.ToHostPort(portAndProto, service.DockerHost));
 }