Skip to content

fix: check if the discovered docker socket responds#2741

Merged
mdelapenya merged 26 commits intotestcontainers:mainfrom
mdelapenya:docker-socket-info
Aug 28, 2024
Merged

fix: check if the discovered docker socket responds#2741
mdelapenya merged 26 commits intotestcontainers:mainfrom
mdelapenya:docker-socket-info

Conversation

@mdelapenya
Copy link
Member

@mdelapenya mdelapenya commented Aug 21, 2024

What does this PR do?

This PR adds a check for each discovered Docker host in order to verify if a vanilla Docker client can talk to that host.

Why is it important?

It will remove the confusion when a testcontainers.properties file exists and the Testcontainers Desktop (TCD) app has been used in the past, adding a tc.host entry in the properties. In the case TCD is not running, and the container runtime is running (i.e. Docker Desktop), then the latter should be used. Before this fix, the code will cause the discovery algorithm to get the tc.host entry first (it simply exists) and use it, even though it's not responding.

With this fix we'll fail if that Docker host is not accessible, continuing with the Docker host resolution.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner August 21, 2024 10:20
@mdelapenya mdelapenya added the bug An issue with the library label Aug 21, 2024
@mdelapenya mdelapenya self-assigned this Aug 21, 2024
@netlify
Copy link

netlify bot commented Aug 21, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 9dfd4fb
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/66cf4fa5478b1900083be53e
😎 Deploy Preview https://deploy-preview-2741--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

This reverts commit c6c4832.
This reverts commit fbadada.
… resolution

This way the tests are able to verify if the socket/host is reachable by calling a mock client.

The production code will use the default callback check, which calls a vanilla docker client using the discovered host as host
@mdelapenya
Copy link
Member Author

@ash2k could you double check this is fixing #2622 ? Thanks!

Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this might have some edge cases, so have asked a few questions.

Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one nit, if you're so inclined.

* main:
  chore: use new testcontainers/ryuk:0.9.0 image (testcontainers#2750)
  chore(deps): bump minimal Go version from 1.21 to 1.22 (testcontainers#2743)
  chore(deps): bump github/codeql-action from 3.24.9 to 3.25.15 (testcontainers#2677)
dockerHost := extractDockerHost(ctx)
dockerHost, err := extractDockerHost(ctx)
if err != nil {
panic(err) // Docker host is required to get the Docker socket
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bug: This results in ExtractDockerSocket panic which is used in other non internal functions including its namesake ExtractDockerSocket none of which mention they can panic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments to the functions, could you please check that? 🙏

@mdelapenya mdelapenya requested a review from stevenh August 28, 2024 12:08
Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if should make a breaking change to either return errors all the way or rename exposed to be "Must" functions, as even with it mentioned in the docs its easy to miss, resulting in unexpected failures.

@mdelapenya mdelapenya requested a review from stevenh August 28, 2024 13:01
Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for going the extra mile on this, feels must better to make it explicit.

Just a couple of minor things to consider

@mdelapenya mdelapenya requested a review from stevenh August 28, 2024 15:08
Copy link
Contributor

@stevenh stevenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mdelapenya mdelapenya merged commit c6d8a6c into testcontainers:main Aug 28, 2024
@mdelapenya mdelapenya deleted the docker-socket-info branch August 28, 2024 18:40
mdelapenya added a commit that referenced this pull request Sep 3, 2024
* main:
  feat(wait): for file (#2731)
  feat(compose): select services via profiles (#2758)
  chore(deps): bump mkdocs-markdownextradata-plugin from 0.2.5 to 0.2.6 (#2761)
  fix: update template too (#2763)
  chore(deps): bump actions/checkout from 4.1.1 to 4.1.7 (#2762)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.0.4 to 6.2.2 (#2760)
  fix: check if the discovered docker socket responds (#2741)
  Upgrade milvus-io/milvus-sdk-go to avoid checksum mismatch. (#2753)
  Fix trailing slash on Image Prefix (#2747)
  chore: use new testcontainers/ryuk:0.9.0 image (#2750)
  chore(deps): bump minimal Go version from 1.21 to 1.22 (#2743)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Sep 9, 2024
* main:
  docs: refine heading badges in README (testcontainers#2770)
  feat(wait): for file (testcontainers#2731)
  feat(compose): select services via profiles (testcontainers#2758)
  chore(deps): bump mkdocs-markdownextradata-plugin from 0.2.5 to 0.2.6 (testcontainers#2761)
  fix: update template too (testcontainers#2763)
  chore(deps): bump actions/checkout from 4.1.1 to 4.1.7 (testcontainers#2762)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.0.4 to 6.2.2 (testcontainers#2760)
  fix: check if the discovered docker socket responds (testcontainers#2741)
  Upgrade milvus-io/milvus-sdk-go to avoid checksum mismatch. (testcontainers#2753)
  Fix trailing slash on Image Prefix (testcontainers#2747)
  chore: use new testcontainers/ryuk:0.9.0 image (testcontainers#2750)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Sep 11, 2024
* main:
  ci: add generate for mocks (testcontainers#2774)
  fix: docker config error handling when config file does not exist (testcontainers#2772)
  docs: refine heading badges in README (testcontainers#2770)
  feat(wait): for file (testcontainers#2731)
  feat(compose): select services via profiles (testcontainers#2758)
  chore(deps): bump mkdocs-markdownextradata-plugin from 0.2.5 to 0.2.6 (testcontainers#2761)
  fix: update template too (testcontainers#2763)
  chore(deps): bump actions/checkout from 4.1.1 to 4.1.7 (testcontainers#2762)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.0.4 to 6.2.2 (testcontainers#2760)
  fix: check if the discovered docker socket responds (testcontainers#2741)
  Upgrade milvus-io/milvus-sdk-go to avoid checksum mismatch. (testcontainers#2753)
  Fix trailing slash on Image Prefix (testcontainers#2747)
  chore: use new testcontainers/ryuk:0.9.0 image (testcontainers#2750)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue with the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Docker address confusion

2 participants