public LocalStackFixture(IOptions <LocalStackOptions> options, Amazon.Extensions.NETCore.Setup.AWSOptions awsOptions) { var localStackBuilder = new TestcontainersBuilder <TestcontainersContainer>() .WithImage("localstack/localstack") .WithCleanUp(true) .WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole()) .WithEnvironment("DEFAULT_REGION", "eu-central-1") .WithEnvironment("SERVICES", "s3") .WithEnvironment("DOCKER_HOST", "unix:///var/run/docker.sock") .WithEnvironment("DEBUG", "1") .WithPortBinding(4566, 4566); if (awsOptions != null) { if (awsOptions.Credentials != null) { var awsCreds = awsOptions.Credentials.GetCredentials(); localStackBuilder.WithEnvironment("AWS_ACCESS_KEY_ID", awsCreds.AccessKey) .WithEnvironment("AWS_SECRET_ACCESS_KEY", awsCreds.SecretKey); } } _localStackContainer = localStackBuilder.Build(); this.options = options; }
public async Task <Container> StartContainerAsync(int traceAgentPort, int webPort) { // get path to test application that the profiler will attach to string testApplicationName = $"testapplication-{EnvironmentHelper.TestApplicationName.ToLowerInvariant()}"; string agentBaseUrl = $"http://{DockerNetworkHelper.IntegrationTestsGateway}:{traceAgentPort}"; string agentHealthzUrl = $"{agentBaseUrl}/healthz"; string zipkinEndpoint = $"{agentBaseUrl}/api/v2/spans"; string networkName = DockerNetworkHelper.IntegrationTestsNetworkName; string networkId = DockerNetworkHelper.SetupIntegrationTestsNetwork(); Output.WriteLine($"Zipkin Endpoint: {zipkinEndpoint}"); string logPath = EnvironmentHelper.IsRunningOnCI() ? Path.Combine(Environment.GetEnvironmentVariable("GITHUB_WORKSPACE"), "build_data", "profiler-logs") : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"OpenTelemetry .NET AutoInstrumentation", "logs"); Directory.CreateDirectory(logPath); Output.WriteLine("Collecting docker logs to: " + logPath); var builder = new TestcontainersBuilder <TestcontainersContainer>() .WithImage(testApplicationName) .WithCleanUp(cleanUp: true) .WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole()) .WithName($"{testApplicationName}-{traceAgentPort}-{webPort}") .WithNetwork(networkId, networkName) .WithPortBinding(webPort, 80) .WithEnvironment("OTEL_EXPORTER_ZIPKIN_ENDPOINT", zipkinEndpoint) .WithBindMount(logPath, "c:/inetpub/wwwroot/logs") .WithBindMount(EnvironmentHelper.GetNukeBuildOutput(), "c:/opentelemetry"); var container = builder.Build(); var wasStarted = container.StartAsync().Wait(TimeSpan.FromMinutes(5)); wasStarted.Should().BeTrue($"Container based on {testApplicationName} has to be operational for the test."); Output.WriteLine($"Container was started successfully."); PowershellHelper.RunCommand($"docker exec {container.Name} curl -v {agentHealthzUrl}", Output); var webAppHealthzUrl = $"http://localhost:{webPort}/healthz"; var webAppHealthzResult = await HealthzHelper.TestHealtzAsync(webAppHealthzUrl, "IIS WebApp", Output); webAppHealthzResult.Should().BeTrue("IIS WebApp health check never returned OK."); Output.WriteLine($"IIS WebApp was started successfully."); return(new Container(container)); }