-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add the ability to ask for devservices to use the shared network #39156
Comments
/cc @geoand (devservices), @stuartwdouglas (devservices) |
Can you give #39177 a try please? The property to use is |
The project for which I have the need is still using 3.4.3. I know it's bad, but we have a blocker for the moment. I will to try to backport your patch though. |
Ok I did backport your fix, that works as expected. Almost. Devservices launched by extension use a different network because of this : quarkus/extensions/devservices/common/src/main/java/io/quarkus/devservices/common/ConfigureUtil.java Line 30 in 44f9b08
Which means If I launch a container configuring it via |
I am not sure I understand when this happens, can you elaborate? |
When an extension such as oidc or postgresql launch devservices, they're thread is attached to the "deployment" classloader. Thus they will not be attached to the same docker/podman network. |
Oh, I see. I kinda doubt we'll be able to fix that though... |
Coudn't we use the |
How? |
not sure... I was just looking at the |
Ok so here's what I came up with to make it work. Be ware that's an ugly hack : Class<?> networkClass = tccl.getParent().loadClass("org.testcontainers.containers.Network");
Object sharedNetwork = networkClass.getField("SHARED").get(null);
Consumer<CreateNetworkCmd> addDevservicesLabel = cmd -> cmd.withLabels(Map.of("quarkus.devservices.network", "shared"));
Field createNetworkCmdModifiersField = sharedNetwork.getClass().getSuperclass().getDeclaredField("createNetworkCmdModifiers");
createNetworkCmdModifiersField.setAccessible(true);
createNetworkCmdModifiersField.set(sharedNetwork, Set.of(addDevservicesLabel));
container.setNetwork((Network) sharedNetwork); That code is the com.github.dockerjava.api.model.Network lookedUpNetwork = DockerClientFactory.lazyClient().listNetworksCmd().exec().stream()
.filter(network -> network.labels.containsKey("quarkus.devservices.network"))
.findFirst()
.orElseThrow();
sharedNetwork = new Network() {
@Override
public String getId() {
return lookedUpNetwork.getId();
}
@Override
public void close() {
/* NOOP */
}
@Override
public Statement apply(Statement statement, Description description) {
return null;
}
}; |
Where did you put that hack? I didn't catch that part. |
oups sorry I was a bit quick : Labeling the network is done here The lookup is done in my application code. I think the main point here is labeling the network. There is no easy identification of the devservice network as of today (its id is random) |
That's an excellent point. |
yes of course, directly to your branch ? via a fork/pr to it ? |
Whatever you like :) |
I don't have write access to your repo. |
2 options:
|
This will be done by tomorrow ! |
👌 |
@jtama could you elaborate on that? Is this something that needs fixing on our side? |
@gsmet I am not sure whether you should do something or I should. Let me explain. We have this module that depends on kafka-stream extension, and that may or not depending on runtime event, in anyway, the kstream topolgy initialized at start time. The 3.6.0 version of the extension added devui related code that need a topology to be defined at startup otherwise it will trigger a |
Hi @jtama and @geoand, |
Hi @lbroudoux |
Sorry if I'm polluting this thread a bit but as I'm having issues on a very related topic, I'd like to share findings to see if we can find a common solution... As explained in this other thread comment, I'm facing problems in dev and test modes because database-related devservices are automatically joining the shared network when it exists. Combining the existing, this issue and mine, there are now 3 different situations where a shared network can be created:
I think there's a situation where:
and where database-related services should still not join the available shared network (otherwise, they would become unreachable for the application.) I started exploring things to see what can be used Maybe we should have a way to differentiate between a shared network created because of What do you think? |
A container launched in a shared network can still be used by code running on the host. The only subtlety is the devservice would have to configure url using the host ip instead of the network alias (that's what I've done). |
Hum... maybe that could be another way to solve this issue: having the database devservices setting the connection url properties to use the container IP and not the randomly generated host alias 🤔 ... |
I agree with as I wrote here, so I am not sure I understand the original problem. |
I submitted a PR embedding the |
Signed-off-by: Laurent Broudoux <[email protected]>
Signed-off-by: Laurent Broudoux <[email protected]>
Signed-off-by: Laurent Broudoux <[email protected]>
Description
As of now, the only way to ask for dev services to be run in the shared network is to produce a
DevServicesSharedNetworkBuildItem
, which I think is only done here :quarkus/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestUtil.java
Line 292 in 607ece4
It would be great to be able to ask for it through configuration. I first thought that was what quarkus..devservice.shared was for, it turned out it was not ;).
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: