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

fix: enhance host configuration port binding #2512

Merged

Conversation

wilsouza
Copy link
Contributor

What does this PR do?

This PR refactors the mergePortBinding function to accommodate exposed ports with their respective protocols.

Why is it important?

It enables to configure port binding to an exposed port declared with protocol.

Related issues

How to test this PR

Create a container with following request should map exposed container redis port to port binding configured.

genericContainerReq := testcontainers.GenericContainerRequest{
	ContainerRequest: req := testcontainers.ContainerRequest{
		Image:        "redis:6.2",
		Name:         "redis",
		ExposedPorts: []string{"6379/tcp"},
		WaitingFor:   wait.ForExposedPort(),
		HostConfigModifier: func(hc *container.HostConfig) {
			hc.PortBindings = map[nat.Port][]nat.PortBinding{
				"6379/tcp": {{HostIP: "0.0.0.0", HostPort: "6379"}},
			}
		},
	},
	Started:          true,
}

container, err := testcontainers.GenericContainer(context.Background(), genericContainerReq)

The container should be configured with port map 6379:6379

docker ps

CONTAINER ID   IMAGE                       COMMAND                  CREATED         STATUS         PORTS                     NAMES
ee95a18b3ccc   redis:6.2                   "docker-entrypoint.s…"   6 seconds ago   Up 6 seconds   0.0.0.0:6379->6379/tcp    redis

@wilsouza wilsouza requested a review from a team as a code owner April 24, 2024 06:09
Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 440ee47
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6629bf737f92bb000828d898
😎 Deploy Preview https://deploy-preview-2512--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.

@wilsouza wilsouza force-pushed the fix/hostmodifier-port-binding branch from b42ed50 to 8983fea Compare April 24, 2024 06:57
@mdelapenya mdelapenya self-assigned this Apr 24, 2024
@mdelapenya mdelapenya added the bug An issue with the library label Apr 24, 2024
@mdelapenya
Copy link
Member

@wilsouza could you run make tidy-all in the root of the project? Please make sure you have Go 1.21. We need to spread the go.mod changes (removing a dep) across all submodules 🙏

Willian S. de Souza added 2 commits April 24, 2024 23:19
This commit refactors the mergePortBinding function to accommodate exposed ports with their respective protocols.
@wilsouza wilsouza force-pushed the fix/hostmodifier-port-binding branch from 0fbbc73 to 440ee47 Compare April 25, 2024 02:26
Copy link
Contributor Author

@wilsouza wilsouza left a comment

Choose a reason for hiding this comment

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

@mdelapenya, I've executed the make tidy-all command. I've also performed a rebase operation on the branch to resolve conflicts.

Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@mdelapenya mdelapenya merged commit edc0279 into testcontainers:main Apr 25, 2024
104 checks passed
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Apr 25, 2024
* main:
  fix: enhance host configuration port binding (testcontainers#2512)
@wilsouza wilsouza deleted the fix/hostmodifier-port-binding branch April 25, 2024 13:17
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Apr 26, 2024
* main: (34 commits)
  break: return error from Customize request option (testcontainers#2267)
  fix: wrong copy paste (testcontainers#2515)
  docs: add documentation for Exec method (testcontainers#2451)
  docs: document the SSHd tunnel (testcontainers#2514)
  fix: enhance host configuration port binding (testcontainers#2512)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  feat: support passing io.Reader for compose files when creating a compose instance (testcontainers#2509)
  chore: add funding button for testcontainers (testcontainers#2510)
  feat: support Ryuk for the compose module (testcontainers#2485)
  chore(deps): bump golang.org/x/net in modules (minio, gcloud, weaviate, compose, qdrant, couchbase, k3s, milvus, mockserver, pulsar, kafka) (testcontainers#2505)
  fix: fallback to URL-path when parsing auth config URL without scheme (testcontainers#2488)
  fix(postgres): Fix the non-default dbname error (testcontainers#2489)
  feat: Bump default postgres version (testcontainers#2481)
  support Dolt (testcontainers#2177)
  chore: create TLS certs in a consistent manner (testcontainers#2478)
  chore(deps): bump idna from 3.6 to 3.7 (testcontainers#2480)
  Elasticsearch disable CA retrieval when ssl is disabled (testcontainers#2475)
  ...
mdelapenya added a commit to khartld/testcontainers-go that referenced this pull request May 7, 2024
* main: (44 commits)
  feat: expose JSON representation of a container with Inspect (testcontainers#2534)
  chore(deps): bump test-summary action to v2.3 (testcontainers#2535)
  chore(deps): bump jinja2 from 3.1.3 to 3.1.4 (testcontainers#2533)
  Update devcontainer image (testcontainers#2531)
  chore(influxdb): include more characters in wait for log regex (testcontainers#2532)
  fix(compose): avoid race conditions when caching services (testcontainers#2528)
  chore(deps): bump golangci/golangci-lint-action from 3.7.0 to 5.1.0 (testcontainers#2525)
  chore(deps): bump mkdocs-material from 8.2.7 to 9.1.21 (testcontainers#2524)
  chore(compose): return error in options (testcontainers#2520)
  chore(deps): bump github.com/compose-spec/compose-go/v2 from v2.0.0-rc8 to v2.1.0 (testcontainers#2519)
  chore(deps): bump github.com/containerd/containerd from 1.7.12 to 1.7.15 (testcontainers#2517)
  break: return error from Customize request option (testcontainers#2267)
  fix: wrong copy paste (testcontainers#2515)
  docs: add documentation for Exec method (testcontainers#2451)
  docs: document the SSHd tunnel (testcontainers#2514)
  fix: enhance host configuration port binding (testcontainers#2512)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  ...
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]: Issue with Port Mapping in ContainerRequest
2 participants