@@ -6,7 +6,6 @@ namespace DotNet.Testcontainers.Clients
6
6
using System . Linq ;
7
7
using System . Reflection ;
8
8
using System . Text ;
9
- using System . Text . RegularExpressions ;
10
9
using System . Threading ;
11
10
using System . Threading . Tasks ;
12
11
using Docker . DotNet ;
@@ -33,10 +32,10 @@ internal sealed class TestcontainersClient : ITestcontainersClient
33
32
34
33
private static readonly string OSRootDirectory = Path . GetPathRoot ( Directory . GetCurrentDirectory ( ) ) ;
35
34
36
- private static readonly Regex FromLinePattern = new Regex ( "FROM (?<arg>--[^\\ s]+\\ s)*(?<image>[^\\ s]+).*" , RegexOptions . None , TimeSpan . FromSeconds ( 1 ) ) ;
37
-
38
35
private readonly DockerRegistryAuthenticationProvider _registryAuthenticationProvider ;
39
36
37
+ private readonly ILogger _logger ;
38
+
40
39
/// <summary>
41
40
/// Initializes a new instance of the <see cref="TestcontainersClient" /> class.
42
41
/// </summary>
@@ -50,7 +49,8 @@ public TestcontainersClient(Guid sessionId, IDockerEndpointAuthenticationConfigu
50
49
new DockerNetworkOperations ( sessionId , dockerEndpointAuthConfig , logger ) ,
51
50
new DockerVolumeOperations ( sessionId , dockerEndpointAuthConfig , logger ) ,
52
51
new DockerSystemOperations ( sessionId , dockerEndpointAuthConfig , logger ) ,
53
- new DockerRegistryAuthenticationProvider ( logger ) )
52
+ new DockerRegistryAuthenticationProvider ( logger ) ,
53
+ logger )
54
54
{
55
55
}
56
56
@@ -60,9 +60,11 @@ private TestcontainersClient(
60
60
IDockerNetworkOperations networkOperations ,
61
61
IDockerVolumeOperations volumeOperations ,
62
62
IDockerSystemOperations systemOperations ,
63
- DockerRegistryAuthenticationProvider registryAuthenticationProvider )
63
+ DockerRegistryAuthenticationProvider registryAuthenticationProvider ,
64
+ ILogger logger )
64
65
{
65
66
_registryAuthenticationProvider = registryAuthenticationProvider ;
67
+ _logger = logger ;
66
68
Container = containerOperations ;
67
69
Image = imageOperations ;
68
70
Network = networkOperations ;
@@ -328,25 +330,17 @@ await Task.WhenAll(configuration.ResourceMappings.Values.Select(resourceMapping
328
330
/// <inheritdoc />
329
331
public async Task < string > BuildAsync ( IImageFromDockerfileConfiguration configuration , CancellationToken ct = default )
330
332
{
331
- var dockerfileFilePath = Path . Combine ( configuration . DockerfileDirectory , configuration . Dockerfile ) ;
332
-
333
333
var cachedImage = await Image . ByNameAsync ( configuration . Image . FullName , ct )
334
334
. ConfigureAwait ( false ) ;
335
335
336
- if ( File . Exists ( dockerfileFilePath ) )
337
- {
338
- await Task . WhenAll ( File . ReadAllLines ( dockerfileFilePath )
339
- . Select ( line => FromLinePattern . Match ( line ) )
340
- . Where ( match => match . Success )
341
- . Select ( match => match . Groups [ "image" ] )
342
- . Select ( group => group . Value )
343
- . Select ( image => new DockerImage ( image ) )
344
- . Select ( image => PullImageAsync ( image , ct ) ) ) ;
345
- }
346
-
347
336
if ( configuration . ImageBuildPolicy ( cachedImage ) )
348
337
{
349
- _ = await Image . BuildAsync ( configuration , ct )
338
+ var dockerfileArchive = new DockerfileArchive ( configuration . DockerfileDirectory , configuration . Dockerfile , configuration . Image , _logger ) ;
339
+
340
+ await Task . WhenAll ( dockerfileArchive . GetBaseImages ( ) . Select ( image => PullImageAsync ( image , ct ) ) )
341
+ . ConfigureAwait ( false ) ;
342
+
343
+ _ = await Image . BuildAsync ( configuration , dockerfileArchive , ct )
350
344
. ConfigureAwait ( false ) ;
351
345
}
352
346
0 commit comments