diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java index 1ee7a81a47cde7..4f8f978ee3fc6e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java @@ -293,6 +293,12 @@ public static class Container { */ @ConfigItem Map additionalExposedPorts; + + /** + * A set of labels to add to the launched container + */ + @ConfigItem + Map labels; } public enum Mode { diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java index 629c90935f00fc..97ff47ccefb76d 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java @@ -42,6 +42,8 @@ public class DefaultDockerContainerLauncher implements DockerContainerArtifactLa private String containerImage; private boolean pullRequired; private Map additionalExposedPorts; + + private Map labels; private final Map systemProps = new HashMap<>(); private boolean isSsl; private final String containerName = "quarkus-integration-test-" + RandomStringUtils.random(5, true, false); @@ -60,6 +62,7 @@ public void init(DockerContainerArtifactLauncher.DockerInitContext initContext) this.containerImage = initContext.containerImage(); this.pullRequired = initContext.pullRequired(); this.additionalExposedPorts = initContext.additionalExposedPorts(); + this.labels = initContext.labels(); } @Override @@ -136,6 +139,11 @@ public void start() throws IOException { for (var e : env.entrySet()) { args.addAll(envAsLaunchArg(e.getKey(), e.getValue())); } + + for (var e : labels.entrySet()) { + args.add("--label"); + args.add(e.getKey() + "=" + e.getValue()); + } args.add(containerImage); final Path logFile = PropertyTestUtil.getLogFilePath(); diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/DockerContainerArtifactLauncher.java b/test-framework/common/src/main/java/io/quarkus/test/common/DockerContainerArtifactLauncher.java index b80f682e3e9f40..97cfb81fa9c8df 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/DockerContainerArtifactLauncher.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/DockerContainerArtifactLauncher.java @@ -11,5 +11,7 @@ interface DockerInitContext extends InitContext { boolean pullRequired(); Map additionalExposedPorts(); + + Map labels(); } } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java index aa23e3870c5882..8c71c9fdc0b5b4 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java @@ -51,7 +51,8 @@ public DockerContainerArtifactLauncher create(CreateContext context) { context.devServicesLaunchResult(), containerImage, pullRequired, - additionalExposedPorts(config))); + additionalExposedPorts(config), + labels(config))); return launcher; } else { throw new IllegalStateException("The container image to be launched could not be determined"); @@ -66,20 +67,32 @@ private Map additionalExposedPorts(SmallRyeConfig config) { } } + private Map labels(SmallRyeConfig config) { + try { + return config.getValues("quarkus.test.container.labels", String.class, String.class); + } catch (NoSuchElementException e) { + return Collections.emptyMap(); + } + } + static class DefaultDockerInitContext extends DefaultInitContextBase implements DockerContainerArtifactLauncher.DockerInitContext { private final String containerImage; private final boolean pullRequired; private final Map additionalExposedPorts; + private Map labels; public DefaultDockerInitContext(int httpPort, int httpsPort, Duration waitTime, String testProfile, List argLine, Map env, ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult, - String containerImage, boolean pullRequired, Map additionalExposedPorts) { + String containerImage, boolean pullRequired, + Map additionalExposedPorts, + Map labels) { super(httpPort, httpsPort, waitTime, testProfile, argLine, env, devServicesLaunchResult); this.containerImage = containerImage; this.pullRequired = pullRequired; this.additionalExposedPorts = additionalExposedPorts; + this.labels = labels; } @Override @@ -96,5 +109,10 @@ public boolean pullRequired() { public Map additionalExposedPorts() { return additionalExposedPorts; } + + @Override + public Map labels() { + return labels; + } } }