Skip to content

Commit

Permalink
Mitigate DiskFull failures in subsequent tasks after docker image fai…
Browse files Browse the repository at this point in the history
…lures (#711)
  • Loading branch information
BMurri authored May 19, 2024
1 parent 4244ae7 commit dc47555
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Tes.Runner.Test/Docker/DockerExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task RunOnContainerAsync_DockerClientReturnsAuthNeeded_CallsContain
Assert.Fail(ex.Message);
}

Assert.AreEqual(1, dockerImageMock.Invocations.Count);
Assert.AreEqual(2, dockerImageMock.Invocations.Count);
}

[DataTestMethod]
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task RunOnContainerAsync_DockerClientReturnsOtherError_DoesNotCallC
Assert.AreSame(exception, ex);
}

Assert.AreEqual(1 + DockerExecutor.dockerPullRetryPolicyOptions.MaxRetryCount, dockerImageMock.Invocations.Count);
Assert.AreEqual(2 + DockerExecutor.dockerPullRetryPolicyOptions.MaxRetryCount, dockerImageMock.Invocations.Count);
}

//[DataTestMethod]
Expand Down
28 changes: 18 additions & 10 deletions src/Tes.Runner/Docker/DockerExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,29 @@ public virtual async Task<ContainerExecutionResult> RunOnContainerAsync(Executio

try
{
await PullImageWithRetriesAsync(executionOptions.ImageName, executionOptions.Tag);
}
catch (DockerApiException e) when (IsAuthFailure(e))
{
var authConfig = await containerRegistryAuthorizationManager.TryGetAuthConfigForAzureContainerRegistryAsync(executionOptions.ImageName, executionOptions.Tag, executionOptions.RuntimeOptions);

if (authConfig is not null)
try
{
await PullImageWithRetriesAsync(executionOptions.ImageName, executionOptions.Tag, authConfig);
await PullImageWithRetriesAsync(executionOptions.ImageName, executionOptions.Tag);
}
else
catch (DockerApiException e) when (IsAuthFailure(e))
{
throw;
var authConfig = await containerRegistryAuthorizationManager.TryGetAuthConfigForAzureContainerRegistryAsync(executionOptions.ImageName, executionOptions.Tag, executionOptions.RuntimeOptions);

if (authConfig is not null)
{
await PullImageWithRetriesAsync(executionOptions.ImageName, executionOptions.Tag, authConfig);
}
else
{
throw;
}
}
}
catch
{
await dockerClient.Images.PruneImagesAsync();
throw;
}

await ConfigureNetworkAsync();

Expand Down

0 comments on commit dc47555

Please sign in to comment.