testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.79k stars 275 forks source link

[Enhancement]: Resolve variables (`ARG`s) during Docker image build #980

Open HofmeisterAn opened 1 year ago

HofmeisterAn commented 1 year ago

Problem

Testcontainers for .NET cannot resolve variables (ARGs) during the Docker image build process. Currently, Testcontainers does not pull base images in advance that utilize variables. Hence, if the images are not already present on the host, they will not be pulled, causing the Docker image build process to fail.

Solution

To pull base images that utilize variables in advance too, Testcontainers needs to have the capability to resolve the default values and build arguments of variables.

Benefit

Developers will not be required to manually pull the images beforehand, enabling a more streamlined Docker image building and testing configuration.

Alternatives

Pull images manually beforehand.

Would you like to help contributing this enhancement?

Yes

HofmeisterAn commented 1 year ago

Resolving variables (ARGs) should be done here (the matched lines contains already an arg Regex group):

https://github.com/testcontainers/testcontainers-dotnet/blob/604ae2c341b5ad0fe8c1e921dc40efd5bd799ff2/src/Testcontainers/Images/DockerfileArchive.cs#L69-L115

samba2 commented 6 months ago

I am missing the parsing of "ARG" as well. I use Testcontainers to smoke test a rather complicated Dockerfile which is configured by builds-args/ ARGS. At the moment I manually maintain a second Dockerfile just for the Testcontainers E2E test.