Skip to content

Commit 7f0bf14

Browse files
authored
Merge pull request quarkusio#35880 from HerrDerb/add-volumn-mounbts-for-test-container
Add volume mounts for test container
2 parents cd3dece + 2a70bec commit 7f0bf14

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/testing/TestConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ public static class Container {
299299
*/
300300
@ConfigItem
301301
Map<String, String> labels;
302+
303+
/**
304+
* A set of volume mounts to add to the launched container
305+
*/
306+
@ConfigItem
307+
Map<String, String> volumeMounts;
302308
}
303309

304310
public enum Mode {

test-framework/common/src/main/java/io/quarkus/test/common/DefaultDockerContainerLauncher.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class DefaultDockerContainerLauncher implements DockerContainerArtifactLa
4343
private boolean pullRequired;
4444
private Map<Integer, Integer> additionalExposedPorts;
4545

46+
private Map<String, String> volumeMounts;
4647
private Map<String, String> labels;
4748
private final Map<String, String> systemProps = new HashMap<>();
4849
private boolean isSsl;
@@ -62,6 +63,7 @@ public void init(DockerContainerArtifactLauncher.DockerInitContext initContext)
6263
this.containerImage = initContext.containerImage();
6364
this.pullRequired = initContext.pullRequired();
6465
this.additionalExposedPorts = initContext.additionalExposedPorts();
66+
this.volumeMounts = initContext.volumeMounts();
6567
this.labels = initContext.labels();
6668
}
6769

@@ -115,6 +117,10 @@ public void start() throws IOException {
115117
args.add("-p");
116118
args.add(entry.getKey() + ":" + entry.getValue());
117119
}
120+
for (Map.Entry<String, String> entry : volumeMounts.entrySet()) {
121+
args.add("-v");
122+
args.add(entry.getKey() + ":" + entry.getValue());
123+
}
118124
// if the dev services resulted in creating a dedicated network, then use it
119125
if (devServicesLaunchResult.networkId() != null) {
120126
args.add("--net=" + devServicesLaunchResult.networkId());

test-framework/common/src/main/java/io/quarkus/test/common/DockerContainerArtifactLauncher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ interface DockerInitContext extends InitContext {
1313
Map<Integer, Integer> additionalExposedPorts();
1414

1515
Map<String, String> labels();
16+
17+
Map<String, String> volumeMounts();
1618
}
1719
}

test-framework/junit5/src/main/java/io/quarkus/test/junit/launcher/DockerContainerLauncherProvider.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ public DockerContainerArtifactLauncher create(CreateContext context) {
5252
containerImage,
5353
pullRequired,
5454
additionalExposedPorts(config),
55-
labels(config)));
55+
labels(config),
56+
volumeMounts(config)));
5657
return launcher;
5758
} else {
5859
throw new IllegalStateException("The container image to be launched could not be determined");
@@ -67,6 +68,14 @@ private Map<Integer, Integer> additionalExposedPorts(SmallRyeConfig config) {
6768
}
6869
}
6970

71+
private Map<String, String> volumeMounts(SmallRyeConfig config) {
72+
try {
73+
return config.getValues("quarkus.test.container.volume-mounts", String.class, String.class);
74+
} catch (NoSuchElementException e) {
75+
return Collections.emptyMap();
76+
}
77+
}
78+
7079
private Map<String, String> labels(SmallRyeConfig config) {
7180
try {
7281
return config.getValues("quarkus.test.container.labels", String.class, String.class);
@@ -81,18 +90,21 @@ static class DefaultDockerInitContext extends DefaultInitContextBase
8190
private final boolean pullRequired;
8291
private final Map<Integer, Integer> additionalExposedPorts;
8392
private Map<String, String> labels;
93+
private Map<String, String> volumeMounts;
8494

8595
public DefaultDockerInitContext(int httpPort, int httpsPort, Duration waitTime, String testProfile,
8696
List<String> argLine, Map<String, String> env,
8797
ArtifactLauncher.InitContext.DevServicesLaunchResult devServicesLaunchResult,
8898
String containerImage, boolean pullRequired,
8999
Map<Integer, Integer> additionalExposedPorts,
90-
Map<String, String> labels) {
100+
Map<String, String> labels,
101+
Map<String, String> volumeMounts) {
91102
super(httpPort, httpsPort, waitTime, testProfile, argLine, env, devServicesLaunchResult);
92103
this.containerImage = containerImage;
93104
this.pullRequired = pullRequired;
94105
this.additionalExposedPorts = additionalExposedPorts;
95106
this.labels = labels;
107+
this.volumeMounts = volumeMounts;
96108
}
97109

98110
@Override
@@ -114,5 +126,11 @@ public Map<Integer, Integer> additionalExposedPorts() {
114126
public Map<String, String> labels() {
115127
return labels;
116128
}
129+
130+
@Override
131+
public Map<String, String> volumeMounts() {
132+
return volumeMounts;
133+
}
134+
117135
}
118136
}

0 commit comments

Comments
 (0)