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

Closed
wants to merge 2 commits into 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

Copy link

github-actions bot commented Jun 2, 2024

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Jun 2, 2024
@scrocquesel scrocquesel removed the stale label Jun 7, 2024
Copy link

github-actions bot commented Aug 6, 2024

This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Aug 6, 2024
Copy link

This PR was closed because it has been stalled for 10 days with no activity.

@github-actions github-actions bot closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalStack Dev Services container cannot connect to host network
2 participants