testcontainers-dotnet icon indicating copy to clipboard operation
testcontainers-dotnet copied to clipboard

[Enhancement]: Support for custom .dockerignore files

Open pvervaet opened this issue 1 year ago • 7 comments

Problem

In my buildcontext there live several dockerfiles. Each one has it's own dockerignore file. It seems like there is no way to specify a custom dockerignore file at the moment. Would it be possible to support the standard approach for dockerignore files? https://docs.docker.com/build/building/context/#dockerignore-files

Solution

  • Either support the custom naming convention and automatically pick the right dockerignore file
  • Or have a way to specify the file .WithDockerignore("/somefolder/custom.Dockerfile.dockerignore")

Benefit

  • Support basic docker functionality
  • Many dockerfiles will be useable within one context. Now it's more or less impossible.

Alternatives

I see the 2 proposed solutions as only options

Would you like to help contributing this enhancement?

No

pvervaet avatar May 21 '24 06:05 pvervaet

Nobody?

pvervaet avatar Jun 11 '24 06:06 pvervaet

I am not going to implement this soon, but if someone would like to implement this feature in the meantime, I would like to provide some guidance. The .dockerignore file name is passed to the Tar(CancellationToken) member here:

https://github.com/testcontainers/testcontainers-dotnet/blob/b5c926a2a4957deec277cc20450841c67f5f301f/src/Testcontainers/Images/DockerfileArchive.cs#L129

We need to pass the correct file name. We can (probably) simply check whether a specific ignore file exists for the Dockerfile or not.

HofmeisterAn avatar Jun 13 '24 16:06 HofmeisterAn

I have a branch ready with this change but I get an error when trying to push the branch:

Error encountered while pushing to the remote repository: Git failed with a fatal error.
Git failed with a fatal error.
unable to access 'https://github.com/testcontainers/testcontainers-dotnet.git/': The requested URL returned error: 403

I have to be made contributer or something @HofmeisterAn ?

pvervaet avatar Jun 21 '24 08:06 pvervaet

You cannot simply push to the repository, please see: Contributing to a project.

HofmeisterAn avatar Jun 21 '24 13:06 HofmeisterAn

Hi @pvervaet, I'm looking to implement this also - can you share what you have done so far?

ifan-t avatar Nov 16 '24 14:11 ifan-t

Hi @ifan-t, my priorities shifted and was not able to spend any time on this yet. I am however still interested in a solution as it will be needed in the future. Also it seems like a no-brainer to support this.

pvervaet avatar Nov 17 '24 07:11 pvervaet

@pvervaet understood. This is how I've done it, just need to add tests https://github.com/ifan-t/testcontainers-dotnet/commit/dc31914afcb0b3a1128d29147d36e30e7b491059

ifan-t avatar Nov 17 '24 18:11 ifan-t