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

chore: restructure Docker helper methods #799

Merged

Conversation

mdelapenya
Copy link
Collaborator

  • chore: add InAContainer
  • chore: use new internal method for inAContainer
  • chore: extract default gateway calculation to the internal package
  • chore: move sessionID to the internal packages
  • chore: simplify getting the string from the session ID
  • chore: expose DaemonHost in the Docker provider

What does this PR do?

this PR leverages the new internal testcontainersdocker package to move there a few utility functions used to check certain state in Docker, such as

  • default gateway
  • check if it's running in a container
  • retrieve the session ID

We were not able to move the calculation of the daemonHost to the internal package because it's coupled with the DockerProvider struct, and moving the function to the internal would have caused a package cycle.
Therefore we are simply exposing the DaemonHost function in the DockerProvider struct, so that it can be consumed from anybody being able to obtain a DockerProvider instance using the NewDockerProvider function.
This new exposed function will call the already existing one, which was already private and easy to rename/move.

Why is it important?

These changes come with two major improvements:

  • refactor of the code, moving internal parts of the library to the internal packages
  • add visibility to the upcoming example modules to certain functions that calculate the DaemonHost. As an example, the localstack module, which needs it to prepare the EnvVars to be used to run the container.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner January 31, 2023 16:46
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Jan 31, 2023
@mdelapenya mdelapenya self-assigned this Jan 31, 2023
@netlify
Copy link

netlify bot commented Jan 31, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 4eecc05
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/63d94df5b889640008eec1ef
😎 Deploy Preview https://deploy-preview-799--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 settings.

return inAContainer("/.dockerenv")
}

func inAContainer(path string) bool {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Making it testable

@mdelapenya mdelapenya merged commit a201e1d into testcontainers:main Feb 1, 2023
@mdelapenya mdelapenya deleted the add-internal-docker-functions branch February 1, 2023 09:11
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Feb 10, 2023
* main:
  chore: update Docker labels for containers (testcontainers#813)
  fix: nil pointer dereference in HealthStrategy (testcontainers#802)
  fix: Synchronise writes to containers map (testcontainers#812)
  chore(deps): bump google.golang.org/api from 0.108.0 to 0.109.0 in /examples (testcontainers#810)
  chore(deps): bump cloud.google.com/go/spanner in /examples/spanner (testcontainers#806)
  chore: restructure Docker helper methods (testcontainers#799)
  Verify Reaper state to create new or return existing instance (testcontainers#782)
  docs: add intel as user (testcontainers#798)
  chore: bump containerd in examples (testcontainers#797)
  chore(deps): bump github.com/containerd/containerd from 1.6.15 to 1.6.16 (testcontainers#793)
  chore: extract docker host calculation to an internal package (testcontainers#796)
  chore: run "go mod tidy" automatically when creating examples (testcontainers#794)
  chore: build images with backoff retries (testcontainers#792)
  fix: use right import package for compose in docs (testcontainers#791)
  chore(deps): bump google.golang.org/grpc from 1.52.1 to 1.52.3 in /examples (testcontainers#790)
  Add devcontainer file (testcontainers#765)
  chore: check dependabot dependencies weekly (testcontainers#789)
  chore(deps): bump google.golang.org/grpc from 1.52.0 to 1.52.1 in /examples (testcontainers#783)
  chore: support for titles in examples (testcontainers#775)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants