quarkiverse / quarkus-amazon-services

Quarkus Amazon Services extensions
Apache License 2.0
36 stars 48 forks source link

LocalStack Dev Services container cannot connect to host network #1161

Open dabg3 opened 4 months ago

dabg3 commented 4 months ago

I'm leveraging the Quarkus Dev Services feature to start an EventBridge instance when launching my application via mvn quarkus:dev. The application exposes a REST endpoint which has been set up as API destination in EventBridge, it is associated with a rule so that it gets called when a certain event passes through.

So EventBridge runs in a container, the application on the host. The problem is that the localstack container has no way to reach the host network, in /etc/hosts there isn't a host.docker.internal entry. I can't find a way to pass the --add-host flag either, it may be viable via the DOCKER_FLAGS env variable but that cannot be specified on the quarkus extension.

TestContainers allows to expose host ports to the container or to set a different network mode, is this a missing functionality of the quarkus-extension? or did I overlook something?

scrocquesel commented 4 months ago

A property could be added to the LocalStackDevServicesBuildTimeConfig configuration

https://github.com/quarkiverse/quarkus-amazon-services/blob/6427b385b58a005f4d083fd37712d8b38b2990ae/common/runtime/src/main/java/io/quarkus/amazon/common/runtime/LocalStackDevServicesBuildTimeConfig.java#L13

    /**
     * Indicates if the container would make a connection to the host network.
     * {@code Testcontainers.exposeHostPorts(...)} need to be called to define the target port on the host
     */
    @WithDefault("false")
    boolean accessToHost();

And the container can be configured here

https://github.com/quarkiverse/quarkus-amazon-services/blob/6427b385b58a005f4d083fd37712d8b38b2990ae/common/deployment/src/main/java/io/quarkus/amazon/common/deployment/DevServicesLocalStackProcessor.java#L326

Would you mind propose a PR for this and test it with your requirement ?

dabg3 commented 4 months ago

Sure! I'll start working on it in a couple of days. Thank you for the inputs

scrocquesel commented 2 months ago

I opened a discussion at quarkus quarkusio/quarkus#40573