Skip to content

Commit 7446a9a

Browse files
committed
fix: Prevent Docker-in-Docker container startup in GitHub Actions CI
- Fail fast in CI if LocalStack service container is not detected - Only start Testcontainers in local development environments - Avoids Docker networking errors in GitHub Actions runners - Tests now exclusively use the service container in CI This resolves the 'failed to set up container networking' error by ensuring tests never attempt to start their own containers when running in GitHub Actions, where LocalStack is provided as a service.
1 parent ba70bba commit 7446a9a

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

tests/SourceFlow.Cloud.AWS.Tests/TestHelpers/LocalStackTestFixture.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,20 @@ public async Task InitializeAsync()
110110

111111
if (!isAlreadyRunning)
112112
{
113-
Console.WriteLine("Starting new LocalStack container...");
113+
// In GitHub Actions, we expect LocalStack to be provided as a service container
114+
// If it's not detected, fail fast rather than trying to start a new container
115+
if (isGitHubActions)
116+
{
117+
string errorMessage = "LocalStack service container not detected in GitHub Actions CI. " +
118+
"Ensure the workflow has a 'services.localstack' configuration. " +
119+
"Tests cannot start their own containers in CI due to Docker-in-Docker limitations.";
120+
Console.WriteLine($"ERROR: {errorMessage}");
121+
throw new InvalidOperationException(errorMessage);
122+
}
123+
124+
Console.WriteLine("Starting new LocalStack container for local development...");
114125

115-
// Create LocalStack container
126+
// Create LocalStack container (local development only)
116127
_localStackContainer = new ContainerBuilder()
117128
.WithImage("localstack/localstack:latest")
118129
.WithPortBinding(4566, 4566)
@@ -126,10 +137,9 @@ public async Task InitializeAsync()
126137
await _localStackContainer.StartAsync();
127138
Console.WriteLine("LocalStack container started successfully");
128139

129-
// Wait for services to be ready - longer delay in CI environments
130-
int postStartDelay = isGitHubActions ? 5000 : 2000;
131-
Console.WriteLine($"Waiting {postStartDelay}ms for LocalStack services to initialize...");
132-
await Task.Delay(postStartDelay);
140+
// Wait for services to be ready
141+
Console.WriteLine("Waiting 2000ms for LocalStack services to initialize...");
142+
await Task.Delay(2000);
133143
}
134144

135145
// Create AWS clients configured for LocalStack

0 commit comments

Comments
 (0)