Skip to content

Commit

Permalink
fix: Do not pre-pull scratch image (#1304)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Nov 20, 2024
1 parent f2397a7 commit 37e5351
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/Testcontainers/Clients/TestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,12 @@ private async Task PullImageAsync(IImage image, CancellationToken ct = default)

if (dockerRegistryServerAddress == null)
{
// https://hub.docker.com/_/scratch.
if ("scratch".Equals(image.Repository, StringComparison.OrdinalIgnoreCase))
{
return;
}

var info = await System.GetInfoAsync(ct)
.ConfigureAwait(false);

Expand Down
1 change: 1 addition & 0 deletions tests/Testcontainers.Tests/Assets/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ credHelpers
credsStore
healthWaitStrategy
pullBaseImages
scratch
**/*.md
2 changes: 2 additions & 0 deletions tests/Testcontainers.Tests/Assets/scratch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM scratch
LABEL "maintainer"="[email protected]"
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,31 @@ public async Task ThrowsDockerfileDirectoryDoesNotExist()
Assert.Equal($"Directory '{Path.GetFullPath(dockerfileDirectory)}' does not exist.", exception.Message);
}

[Fact]
public async Task BuildsDockerScratchImage()
{
// Given
var imageFromDockerfileBuilder = new ImageFromDockerfileBuilder()
.WithDockerfileDirectory("Assets/scratch")
.Build();

// When
var exception = await Record.ExceptionAsync(() => imageFromDockerfileBuilder.CreateAsync())
.ConfigureAwait(true);

// Then
Assert.Null(exception);
Assert.NotNull(imageFromDockerfileBuilder.Repository);
Assert.NotNull(imageFromDockerfileBuilder.Tag);
Assert.NotNull(imageFromDockerfileBuilder.FullName);
Assert.Null(imageFromDockerfileBuilder.GetHostname());
}

[Theory]
[InlineData("Dockerfile")]
[InlineData("./Dockerfile")]
[InlineData(".\\Dockerfile")]
public async Task BuildsDockerImage(string dockerfile)
public async Task BuildsDockerAlpineImage(string dockerfile)
{
// Given
IImage tag1 = new DockerImage(new DockerImage(string.Join("/", "localhost", "testcontainers", Guid.NewGuid().ToString("D"))));
Expand Down

0 comments on commit 37e5351

Please sign in to comment.