Skip to content

Commit d2318d1

Browse files
feat: Require explicit container image when creating container builder (#1584)
Co-authored-by: Andre Hofmeister <[email protected]>
1 parent 698193e commit d2318d1

File tree

325 files changed

+2781
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

325 files changed

+2781
-391
lines changed

src/Templates/CSharp/Testcontainers.ModuleName/ModuleNameBuilder.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,40 @@ public sealed class ModuleNameBuilder : ContainerBuilder<ModuleNameBuilder, Modu
77
/// <summary>
88
/// Initializes a new instance of the <see cref="ModuleNameBuilder" /> class.
99
/// </summary>
10-
public ModuleNameBuilder()
10+
/// <param name="image">
11+
/// The full Docker image name, including the image repository and tag
12+
/// (e.g., <c>repository:tag</c>).
13+
/// </param>
14+
/// <remarks>
15+
/// Docker image tags available at <see href="https://hub.docker.com/..." />.
16+
/// </remarks>
17+
public ModuleNameBuilder(string image)
1118
: this(new ModuleNameConfiguration())
1219
{
1320
// 1) To change the ContainerBuilder default configuration override the DockerResourceConfiguration property and the "ModuleNameBuilder Init()" method.
14-
// Append the module configuration to base.Init() e.g. base.Init().WithImage("alpine:3.17") to set the modules' default image.
21+
// Append the module configuration to base.Init() e.g. base.Init().WithXXX().
1522

1623
// 2) To customize the ContainerBuilder validation override the "void Validate()" method.
1724
// Use Testcontainers' Guard.Argument<TType>(TType, string) or your own guard implementation to validate the module configuration.
1825

1926
// 3) Add custom builder methods to extend the ContainerBuilder capabilities such as "ModuleNameBuilder WithModuleNameConfig(object)".
2027
// Merge the current module configuration with a new instance of the immutable ModuleNameConfiguration type to update the module configuration.
2128

22-
// DockerResourceConfiguration = Init().DockerResourceConfiguration;
29+
// DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
30+
}
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="ModuleNameBuilder" /> class.
34+
/// </summary>
35+
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
36+
/// for the container builder configuration.
37+
/// <remarks>
38+
/// Docker image tags available at <see href="https://hub.docker.com/..." />.
39+
/// </remarks>
40+
public ModuleNameBuilder(IImage image)
41+
: this(new ModuleNameConfiguration())
42+
{
43+
// DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
2344
}
2445

2546
/// <summary>

src/Testcontainers.ActiveMq/ArtemisBuilder.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Testcontainers.ActiveMq;
44
[PublicAPI]
55
public sealed class ArtemisBuilder : ContainerBuilder<ArtemisBuilder, ArtemisContainer, ActiveMqConfiguration>
66
{
7+
[Obsolete("This constant is obsolete and will be removed in the future. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
78
public const string ArtemisImage = "apache/activemq-artemis:2.31.2";
89

910
public const ushort ArtemisMainPort = 61616;
@@ -17,10 +18,42 @@ public sealed class ArtemisBuilder : ContainerBuilder<ArtemisBuilder, ArtemisCon
1718
/// <summary>
1819
/// Initializes a new instance of the <see cref="ArtemisBuilder" /> class.
1920
/// </summary>
21+
[Obsolete("This parameterless constructor is obsolete and will be removed. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
2022
public ArtemisBuilder()
23+
: this(ArtemisImage)
24+
{
25+
}
26+
27+
/// <summary>
28+
/// Initializes a new instance of the <see cref="ArtemisBuilder" /> class.
29+
/// </summary>
30+
/// <param name="image">
31+
/// The full Docker image name, including the image repository and tag
32+
/// (e.g., <c>apache/activemq-artemis:2.31.2</c>).
33+
/// </param>
34+
/// <remarks>
35+
/// Docker image tags available at <see href="https://hub.docker.com/r/apache/activemq-artemis/tags" />.
36+
/// </remarks>
37+
public ArtemisBuilder(string image)
38+
: this(new ActiveMqConfiguration())
39+
{
40+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
41+
}
42+
43+
/// <summary>
44+
/// Initializes a new instance of the <see cref="ArtemisBuilder" /> class.
45+
/// </summary>
46+
/// <param name="image">
47+
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
48+
/// for the container builder configuration.
49+
/// </param>
50+
/// <remarks>
51+
/// Docker image tags available at <see href="https://hub.docker.com/r/apache/activemq-artemis/tags" />.
52+
/// </remarks>
53+
public ArtemisBuilder(IImage image)
2154
: this(new ActiveMqConfiguration())
2255
{
23-
DockerResourceConfiguration = Init().DockerResourceConfiguration;
56+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
2457
}
2558

2659
/// <summary>
@@ -69,7 +102,6 @@ public override ArtemisContainer Build()
69102
protected override ArtemisBuilder Init()
70103
{
71104
return base.Init()
72-
.WithImage(ArtemisImage)
73105
.WithPortBinding(ArtemisMainPort, true)
74106
.WithPortBinding(ArtemisConsolePort, true)
75107
.WithUsername(DefaultUsername)

src/Testcontainers.ActiveMq/Usings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
global using DotNet.Testcontainers.Builders;
55
global using DotNet.Testcontainers.Configurations;
66
global using DotNet.Testcontainers.Containers;
7+
global using DotNet.Testcontainers.Images;
78
global using JetBrains.Annotations;

src/Testcontainers.ArangoDb/ArangoDbBuilder.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Testcontainers.ArangoDb;
44
[PublicAPI]
55
public sealed class ArangoDbBuilder : ContainerBuilder<ArangoDbBuilder, ArangoDbContainer, ArangoDbConfiguration>
66
{
7+
[Obsolete("This constant is obsolete and will be removed in the future. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
78
public const string ArangoDbImage = "arangodb:3.11.5";
89

910
public const ushort ArangoDbPort = 8529;
@@ -15,10 +16,42 @@ public sealed class ArangoDbBuilder : ContainerBuilder<ArangoDbBuilder, ArangoDb
1516
/// <summary>
1617
/// Initializes a new instance of the <see cref="ArangoDbBuilder" /> class.
1718
/// </summary>
19+
[Obsolete("This parameterless constructor is obsolete and will be removed. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
1820
public ArangoDbBuilder()
21+
: this(ArangoDbImage)
22+
{
23+
}
24+
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="ArangoDbBuilder" /> class.
27+
/// </summary>
28+
/// <param name="image">
29+
/// The full Docker image name, including the image repository and tag
30+
/// (e.g., <c>arangodb:3.11.5</c>).
31+
/// </param>
32+
/// <remarks>
33+
/// Docker image tags available at <see href="https://hub.docker.com/_/arangodb/tags" />.
34+
/// </remarks>
35+
public ArangoDbBuilder(string image)
36+
: this(new ArangoDbConfiguration())
37+
{
38+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
39+
}
40+
41+
/// <summary>
42+
/// Initializes a new instance of the <see cref="ArangoDbBuilder" /> class.
43+
/// </summary>
44+
/// <param name="image">
45+
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
46+
/// for the container builder configuration.
47+
/// </param>
48+
/// <remarks>
49+
/// Docker image tags available at <see href="https://hub.docker.com/_/arangodb/tags" />.
50+
/// </remarks>
51+
public ArangoDbBuilder(IImage image)
1952
: this(new ArangoDbConfiguration())
2053
{
21-
DockerResourceConfiguration = Init().DockerResourceConfiguration;
54+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
2255
}
2356

2457
/// <summary>
@@ -56,7 +89,6 @@ public override ArangoDbContainer Build()
5689
protected override ArangoDbBuilder Init()
5790
{
5891
return base.Init()
59-
.WithImage(ArangoDbImage)
6092
.WithPortBinding(ArangoDbPort, true)
6193
.WithPassword(DefaultPassword)
6294
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("Have fun!"));

src/Testcontainers.ArangoDb/Usings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
global using DotNet.Testcontainers.Builders;
55
global using DotNet.Testcontainers.Configurations;
66
global using DotNet.Testcontainers.Containers;
7+
global using DotNet.Testcontainers.Images;
78
global using JetBrains.Annotations;

src/Testcontainers.Azurite/AzuriteBuilder.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Testcontainers.Azurite;
44
[PublicAPI]
55
public sealed class AzuriteBuilder : ContainerBuilder<AzuriteBuilder, AzuriteContainer, AzuriteConfiguration>
66
{
7+
[Obsolete("This constant is obsolete and will be removed in the future. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
78
public const string AzuriteImage = "mcr.microsoft.com/azure-storage/azurite:3.28.0";
89

910
public const ushort BlobPort = 10000;
@@ -28,10 +29,40 @@ static AzuriteBuilder()
2829
/// <summary>
2930
/// Initializes a new instance of the <see cref="AzuriteBuilder" /> class.
3031
/// </summary>
32+
[Obsolete("This parameterless constructor is obsolete and will be removed. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
3133
public AzuriteBuilder()
34+
: this(AzuriteImage)
35+
{
36+
}
37+
38+
/// <summary>
39+
/// Initializes a new instance of the <see cref="AzuriteBuilder" /> class.
40+
/// </summary>
41+
/// <param name="image">
42+
/// The full Docker image name, including the image repository and tag
43+
/// (e.g., <c>mcr.microsoft.com/azure-storage/azurite:3.28.0</c>).
44+
/// </param>
45+
/// <remarks>
46+
/// Docker image tags available at <see href="https://hub.docker.com/r/microsoft/azure-storage-azurite/tags" />.
47+
/// </remarks>
48+
public AzuriteBuilder(string image)
49+
: this(new AzuriteConfiguration())
50+
{
51+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
52+
}
53+
54+
/// <summary>
55+
/// Initializes a new instance of the <see cref="AzuriteBuilder" /> class.
56+
/// </summary>
57+
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
58+
/// for the container builder configuration.
59+
/// <remarks>
60+
/// Docker image tags available at <see href="https://hub.docker.com/r/microsoft/azure-storage-azurite/tags" />.
61+
/// </remarks>
62+
public AzuriteBuilder(IImage image)
3263
: this(new AzuriteConfiguration())
3364
{
34-
DockerResourceConfiguration = Init().DockerResourceConfiguration;
65+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
3566
}
3667

3768
/// <summary>
@@ -97,7 +128,6 @@ public override AzuriteContainer Build()
97128
protected override AzuriteBuilder Init()
98129
{
99130
return base.Init()
100-
.WithImage(AzuriteImage)
101131
.WithPortBinding(BlobPort, true)
102132
.WithPortBinding(QueuePort, true)
103133
.WithPortBinding(TablePort, true)

src/Testcontainers.Azurite/Usings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
global using DotNet.Testcontainers.Builders;
66
global using DotNet.Testcontainers.Configurations;
77
global using DotNet.Testcontainers.Containers;
8+
global using DotNet.Testcontainers.Images;
89
global using JetBrains.Annotations;

src/Testcontainers.BigQuery/BigQueryBuilder.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace Testcontainers.BigQuery;
44
[PublicAPI]
55
public sealed class BigQueryBuilder : ContainerBuilder<BigQueryBuilder, BigQueryContainer, BigQueryConfiguration>
66
{
7+
[Obsolete("This constant is obsolete and will be removed in the future. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
78
public const string BigQueryImage = "ghcr.io/goccy/bigquery-emulator:0.4";
89

910
public const ushort BigQueryPort = 9050;
@@ -13,10 +14,42 @@ public sealed class BigQueryBuilder : ContainerBuilder<BigQueryBuilder, BigQuery
1314
/// <summary>
1415
/// Initializes a new instance of the <see cref="BigQueryBuilder" /> class.
1516
/// </summary>
17+
[Obsolete("This parameterless constructor is obsolete and will be removed. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
1618
public BigQueryBuilder()
19+
: this(BigQueryImage)
20+
{
21+
}
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="BigQueryBuilder" /> class.
25+
/// </summary>
26+
/// <param name="image">
27+
/// The full Docker image name, including the image repository and tag
28+
/// (e.g., <c>ghcr.io/goccy/bigquery-emulator:0.4</c>).
29+
/// </param>
30+
/// <remarks>
31+
/// Docker image tags available at <see href="https://github.com/goccy/bigquery-emulator/pkgs/container/bigquery-emulator" />.
32+
/// </remarks>
33+
public BigQueryBuilder(string image)
34+
: this(new BigQueryConfiguration())
35+
{
36+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
37+
}
38+
39+
/// <summary>
40+
/// Initializes a new instance of the <see cref="BigQueryBuilder" /> class.
41+
/// </summary>
42+
/// <param name="image">
43+
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
44+
/// for the container builder configuration.
45+
/// </param>
46+
/// <remarks>
47+
/// Docker image tags available at <see href="https://github.com/goccy/bigquery-emulator/pkgs/container/bigquery-emulator" />.
48+
/// </remarks>
49+
public BigQueryBuilder(IImage image)
1750
: this(new BigQueryConfiguration())
1851
{
19-
DockerResourceConfiguration = Init().DockerResourceConfiguration;
52+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
2053
}
2154

2255
/// <summary>
@@ -53,7 +86,6 @@ public override BigQueryContainer Build()
5386
protected override BigQueryBuilder Init()
5487
{
5588
return base.Init()
56-
.WithImage(BigQueryImage)
5789
.WithPortBinding(BigQueryPort, true)
5890
.WithProject(DefaultProjectId)
5991
.WithWaitStrategy(Wait.ForUnixContainer().UntilMessageIsLogged("(?s).*listening.*$"));

src/Testcontainers.BigQuery/Usings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
global using DotNet.Testcontainers.Builders;
44
global using DotNet.Testcontainers.Configurations;
55
global using DotNet.Testcontainers.Containers;
6+
global using DotNet.Testcontainers.Images;
67
global using JetBrains.Annotations;

src/Testcontainers.Bigtable/BigtableBuilder.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,50 @@ namespace Testcontainers.Bigtable;
44
[PublicAPI]
55
public sealed class BigtableBuilder : ContainerBuilder<BigtableBuilder, BigtableContainer, BigtableConfiguration>
66
{
7+
[Obsolete("This constant is obsolete and will be removed in the future. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
78
public const string GoogleCloudCliImage = "gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators";
89

910
public const ushort BigtablePort = 9000;
1011

1112
/// <summary>
1213
/// Initializes a new instance of the <see cref="BigtableBuilder" /> class.
1314
/// </summary>
15+
[Obsolete("This parameterless constructor is obsolete and will be removed. Use the constructor with the image parameter instead: https://github.com/testcontainers/testcontainers-dotnet/discussions/1470#discussioncomment-15185721.")]
1416
public BigtableBuilder()
17+
: this(GoogleCloudCliImage)
18+
{
19+
}
20+
21+
/// <summary>
22+
/// Initializes a new instance of the <see cref="BigtableBuilder" /> class.
23+
/// </summary>
24+
/// <param name="image">
25+
/// The full Docker image name, including the image repository and tag
26+
/// (e.g., <c>gcr.io/google.com/cloudsdktool/google-cloud-cli:446.0.1-emulators</c>).
27+
/// </param>
28+
/// <remarks>
29+
/// Docker image tags available at <see href="https://console.cloud.google.com/artifacts/docker/google.com:cloudsdktool/us/gcr.io/google-cloud-cli" />.
30+
/// </remarks>
31+
public BigtableBuilder(string image)
32+
: this(new BigtableConfiguration())
33+
{
34+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
35+
}
36+
37+
/// <summary>
38+
/// Initializes a new instance of the <see cref="BigtableBuilder" /> class.
39+
/// </summary>
40+
/// <param name="image">
41+
/// An <see cref="IImage" /> instance that specifies the Docker image to be used
42+
/// for the container builder configuration.
43+
/// </param>
44+
/// <remarks>
45+
/// Docker image tags available at <see href="https://console.cloud.google.com/artifacts/docker/google.com:cloudsdktool/us/gcr.io/google-cloud-cli" />.
46+
/// </remarks>
47+
public BigtableBuilder(IImage image)
1548
: this(new BigtableConfiguration())
1649
{
17-
DockerResourceConfiguration = Init().DockerResourceConfiguration;
50+
DockerResourceConfiguration = Init().WithImage(image).DockerResourceConfiguration;
1851
}
1952

2053
/// <summary>
@@ -41,7 +74,6 @@ public override BigtableContainer Build()
4174
protected override BigtableBuilder Init()
4275
{
4376
return base.Init()
44-
.WithImage(GoogleCloudCliImage)
4577
.WithPortBinding(BigtablePort, true)
4678
.WithEntrypoint("gcloud")
4779
.WithCommand("beta", "emulators", "bigtable", "start", "--host-port", "0.0.0.0:" + BigtablePort)

0 commit comments

Comments
 (0)