Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show docker build errors on ImageFromDockerfileBuilder build #656

Closed
RAAvenger opened this issue Nov 6, 2022 · 8 comments
Closed

show docker build errors on ImageFromDockerfileBuilder build #656

RAAvenger opened this issue Nov 6, 2022 · 8 comments
Assignees
Labels
dependencies Pull requests that update a dependency file question Have you tried our Slack workspace (https://testcontainers.slack.com)?

Comments

@RAAvenger
Copy link

RAAvenger commented Nov 6, 2022

problem
We used "--mount=type=cache,id=nuget,target=/root/.nuget/packages " in our dockerfile, so on docker build a buildkit related error occurred and build failed but only thing we could see was an "InvalidOperationException" saying "Docker image myimage has not been created.".
To debug this situation we set a logger to TestcontainersSettings.Logger and then we have seen actual problem.

solution
It could be nice if you observed docker log and on error, throw an exception with error's message.

@HofmeisterAn
Copy link
Collaborator

Unfortunately, this is a limitation of Docker.DotNet. The latest release does not handle the error response. It got recently fixed in the development branch, though: dotnet/Docker.DotNet#590. I update the dependency soon as it is released.

Notice we are also thinking about a default logging mechanism that works with different test frameworks in the future to provide more information what Testcontainers is doing.

@HofmeisterAn HofmeisterAn self-assigned this Nov 6, 2022
@HofmeisterAn HofmeisterAn added question Have you tried our Slack workspace (https://testcontainers.slack.com)? dependencies Pull requests that update a dependency file labels Nov 6, 2022
@HofmeisterAn
Copy link
Collaborator

Since Docker.DotNet has just released a new version (that includes the mentioned fix above), you will receive error messages (exceptions) if building or pulling images fails. I have updated the dependency and it will be included in the next TC release.

@DanielHabenicht
Copy link
Contributor

Is this already out? Because I still can't see the error of the build in the exception.

@HofmeisterAn
Copy link
Collaborator

HofmeisterAn commented Jun 6, 2023

Yes, it should be included in version 3.1.0 and should log an error if the message contains one:

if (!string.IsNullOrWhiteSpace(value.ErrorMessage))
{
_logger.LogError(value.ErrorMessage);
}

You can set a custom logger and forward traces if necessary, they are ignored to not pollute the output.

@DanielHabenicht
Copy link
Contributor

I am on 3.2.0 and I did not get an error message without adding a logger for the trace output (see: #914)

@HofmeisterAn
Copy link
Collaborator

Unfortunate, then the message it not part of error property 😞. I am not happy with the current situation either. Increasing the log level or forwarding the messages to information will pollute the log output. However, leaving it unchanged is also not ideal.

@DanielHabenicht
Copy link
Contributor

Thats unfortunate then. Hopefully Docker.DotNet can add it still.

Coming from XUnit adding the logger to TestContainer (when using it in an IClassFixture) is quite complicated maybe we could add a
A. a quick switch for setting Testcontainer to log everyhing (even Debug)
B. n easier way to add IOutputHelper / respectively just Console.Out (TextWriter) to visualize the output.

@HofmeisterAn
Copy link
Collaborator

A. a quick switch for setting Testcontainer to log everyhing (even Debug)

Maybe being able to set the default log level for the provided logger would be a good trade-off. If more customization is necessary, developers can still use a custom logger.

B. n easier way to add IOutputHelper / respectively just Console.Out (TextWriter) to visualize the output.

Providing a good logging mechanism is not easy for us. I have described it here and here. However, we can certainly implement a module (an independent NuGet package) specifically for test frameworks like xUnit.net or NUnit to integrate with their default logging mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file question Have you tried our Slack workspace (https://testcontainers.slack.com)?
Projects
None yet
Development

No branches or pull requests

3 participants