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

feat: Connection to host network from LocalStack container #1198

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dabg3
Copy link

@dabg3 dabg3 commented Mar 28, 2024

close #1161

Comment on lines +308 to +310
if (localStackDevServicesBuildTimeConfig.accessToHost()) {
Testcontainers.exposeHostPorts(localStackDevServicesBuildTimeConfig.hostPort());
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (localStackDevServicesBuildTimeConfig.accessToHost()) {
Testcontainers.exposeHostPorts(localStackDevServicesBuildTimeConfig.hostPort());
}
container.withAccessToHost(localStackDevServicesBuildTimeConfig.accessToHost);

This would force the host access setup and let users configure exposed host port themself.

Copy link
Author

@dabg3 dabg3 Apr 2, 2024

Choose a reason for hiding this comment

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

How would users be able to configure exposed port?
I've tried by intercepting the quarkus startup event on my application:

@ApplicationScoped
@IfBuildProfile("dev")
public class DevLifecycleBean {

    @ConfigProperty(name = "quarkus.http.port")
    int port;

    void onStart(@Observes StartupEvent ev) {
        Testcontainers.exposeHostPorts(port);
    }
}

exposeHostPorts() gets called with the right port as argument but then connection to host is refused, I've not investigated why though.

Apart from the difficulties, I do not like much this solution because a seamless integration is being traded for boilerplate code + testcontainers runtime dependency on the application side.
In my solution the host port is user-configurable via host-port property, however most of the time would be retrieved from quarkus.http.port property without requiring tweaks.
An edit I could make is accepting multiple ports instead of just 1, if that's useful.
The same approach is used on the Quarkus Jib extension.

https://github.com/quarkusio/quarkus/blob/0f776ad0434619b428439c1d97257cf1555dd76c/extensions/container-image/container-image-jib/deployment/src/main/java/io/quarkus/container/image/jib/deployment/ContainerImageJibConfig.java#L116-L120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalStack Dev Services container cannot connect to host network
2 participants