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

Add config option for launching dev services on shared network #39177

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public class GlobalDevServicesConfig {
@ConfigItem
public Optional<Duration> timeout;

/**
* An advanced option that makes Quarkus launch all Dev Services containers on shared container network
*/
@ConfigItem
public Optional<Boolean> launchOnSharedNetwork;

public static class Enabled implements BooleanSupplier {

final GlobalDevServicesConfig config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@
import io.quarkus.deployment.builditem.DevServicesLauncherConfigResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesNativeConfigResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesResultBuildItem;
import io.quarkus.deployment.builditem.DevServicesSharedNetworkBuildItem;
import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
import io.quarkus.deployment.dev.devservices.GlobalDevServicesConfig;

class DevServicesConfigBuildStep {
static volatile Map<String, String> oldConfig;

@BuildStep
void sharedNetwork(GlobalDevServicesConfig config, BuildProducer<DevServicesSharedNetworkBuildItem> producer) {
if (config.launchOnSharedNetwork.orElse(false)) {
producer.produce(new DevServicesSharedNetworkBuildItem());
}
}

@BuildStep
List<DevServicesConfigResultBuildItem> deprecated(List<DevServicesNativeConfigResultBuildItem> items) {
return items.stream().map(s -> new DevServicesConfigResultBuildItem(s.getKey(), s.getValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.utility.Base58;

import com.github.dockerjava.api.command.CreateNetworkCmd;

public final class ConfigureUtil {

private static final Map<String, Properties> DEVSERVICES_PROPS = new ConcurrentHashMap<>();
Expand All @@ -35,6 +40,12 @@ public static String configureSharedNetwork(GenericContainer<?> container, Strin
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);
} catch (Exception e) {
throw new IllegalStateException("Unable to obtain SHARED network from testcontainers", e);
Expand Down
Loading