Skip to content

Commit 36c75ef

Browse files
Merge branch 'develop' of github.com:opencb/java-common-libs into develop
2 parents a9ca5fd + 1a1b17d commit 36c75ef

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

commons-lib/src/main/java/org/opencb/commons/utils/DockerUtils.java

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public class DockerUtils {
2626
* @param inputBindings Array of bind mounts for docker input volumes (source-target)
2727
* @param outputBinding Bind mount for docker output volume (source-target)
2828
* @param cmdParams Image command parameters
29-
* @param dockerParams Docker parameters
29+
* @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings)
3030
* @return The command line
3131
* @throws IOException IO exception
3232
*/
3333
public static String buildCommandLine(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
3434
AbstractMap.SimpleEntry<String, String> outputBinding, String cmdParams,
35-
Map<String, String> dockerParams) throws IOException {
35+
Map<String, List<String>> dockerParams) throws IOException {
3636
return buildCommandLine(image, inputBindings, Collections.singletonList(outputBinding), cmdParams, dockerParams);
3737
}
3838

@@ -43,13 +43,13 @@ public static String buildCommandLine(String image, List<AbstractMap.SimpleEntry
4343
* @param inputBindings Array of bind mounts for docker input volumes (source-target)
4444
* @param outputBindings Array of bind mount for docker output volume (source-target)
4545
* @param cmdParams Image command parameters
46-
* @param dockerParams Docker parameters
46+
* @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings)
4747
* @return The command line
4848
* @throws IOException IO exception
4949
*/
5050
public static String buildCommandLine(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
5151
List<AbstractMap.SimpleEntry<String, String>> outputBindings, String cmdParams,
52-
Map<String, String> dockerParams) throws IOException {
52+
Map<String, List<String>> dockerParams) throws IOException {
5353
// Sanity check
5454
if (outputBindings == null || outputBindings.isEmpty()) {
5555
throw new IllegalArgumentException("Missing output binding(s)");
@@ -65,16 +65,28 @@ public static String buildCommandLine(String image, List<AbstractMap.SimpleEntry
6565
setUser = false;
6666
}
6767
for (String key : dockerParams.keySet()) {
68-
if (key.equals("user") && StringUtils.isEmpty(dockerParams.get("user"))) {
69-
// User wants to disable user setting
70-
continue;
71-
}
72-
if (!key.startsWith("-")) {
73-
commandLine.append("--");
74-
}
75-
commandLine.append(key).append(" ");
76-
if (StringUtils.isNotEmpty(dockerParams.get(key))) {
77-
commandLine.append(dockerParams.get(key)).append(" ");
68+
List<String> values = dockerParams.get(key);
69+
if (values == null || values.isEmpty()) {
70+
if (key.equals("user")) {
71+
// User wants to disable user setting
72+
continue;
73+
}
74+
// Parameter without value (flag)
75+
if (!key.startsWith("-")) {
76+
commandLine.append("--");
77+
}
78+
commandLine.append(key).append(" ");
79+
} else {
80+
// Parameter with value(s) - can have multiple values for same key
81+
for (String value : values) {
82+
if (!key.startsWith("-")) {
83+
commandLine.append("--");
84+
}
85+
commandLine.append(key).append(" ");
86+
if (StringUtils.isNotEmpty(value)) {
87+
commandLine.append(value).append(" ");
88+
}
89+
}
7890
}
7991
}
8092
}
@@ -198,7 +210,7 @@ public static boolean login(String registry, String username, String password) t
198210
* @param inputBindings Array of bind mounts for docker input volumes (source-target)
199211
* @param outputBinding Bind mount for docker output volume (source-target)
200212
* @param cmdParams Image command parameters
201-
* @param dockerParams Docker parameters
213+
* @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings)
202214
* @param registry Docker registry URL
203215
* @param username Optional Docker registry username
204216
* @param password Optional Docker registry password
@@ -207,7 +219,7 @@ public static boolean login(String registry, String username, String password) t
207219
*/
208220
public static String run(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
209221
AbstractMap.SimpleEntry<String, String> outputBinding, String cmdParams,
210-
Map<String, String> dockerParams, String registry, String username, String password) throws IOException {
222+
Map<String, List<String>> dockerParams, String registry, String username, String password) throws IOException {
211223
return run(image, inputBindings, outputBinding != null ? Collections.singletonList(outputBinding) : null,
212224
cmdParams, dockerParams, registry, username, password);
213225
}
@@ -219,13 +231,13 @@ public static String run(String image, List<AbstractMap.SimpleEntry<String, Stri
219231
* @param inputBindings Array of bind mounts for docker input volumes (source-target)
220232
* @param outputBinding Bind mount for docker output volume (source-target)
221233
* @param cmdParams Image command parameters
222-
* @param dockerParams Docker parameters
234+
* @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings)
223235
* @return The command line
224236
* @throws IOException IO exception
225237
*/
226238
public static String run(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
227239
AbstractMap.SimpleEntry<String, String> outputBinding, String cmdParams,
228-
Map<String, String> dockerParams) throws IOException {
240+
Map<String, List<String>> dockerParams) throws IOException {
229241
return run(image, inputBindings, outputBinding != null ? Collections.singletonList(outputBinding) : null, cmdParams, dockerParams);
230242
}
231243

@@ -236,13 +248,13 @@ public static String run(String image, List<AbstractMap.SimpleEntry<String, Stri
236248
* @param inputBindings Array of bind mounts for docker input volumes (source-target)
237249
* @param outputBindings Array of bind mount for docker output volume (source-target)
238250
* @param cmdParams Image command parameters
239-
* @param dockerParams Docker parameters
251+
* @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings)
240252
* @return The command line
241253
* @throws IOException IO exception
242254
*/
243255
public static String run(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
244256
List<AbstractMap.SimpleEntry<String, String>> outputBindings, String cmdParams,
245-
Map<String, String> dockerParams) throws IOException {
257+
Map<String, List<String>> dockerParams) throws IOException {
246258
return run(image, inputBindings, outputBindings, cmdParams, dockerParams, null, null, null);
247259
}
248260

@@ -253,7 +265,7 @@ public static String run(String image, List<AbstractMap.SimpleEntry<String, Stri
253265
* @param inputBindings Array of bind mounts for docker input volumes (source-target)
254266
* @param outputBindings Array of bind mount for docker output volume (source-target)
255267
* @param cmdParams Image command parameters
256-
* @param dockerParams Docker parameters
268+
* @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings)
257269
* @param registry Optional Docker registry URL (null if not using private registry)
258270
* @param username Optional Docker registry username
259271
* @param password Optional Docker registry password
@@ -262,7 +274,7 @@ public static String run(String image, List<AbstractMap.SimpleEntry<String, Stri
262274
*/
263275
public static String run(String image, List<AbstractMap.SimpleEntry<String, String>> inputBindings,
264276
List<AbstractMap.SimpleEntry<String, String>> outputBindings, String cmdParams,
265-
Map<String, String> dockerParams, String registry, String username, String password) throws IOException {
277+
Map<String, List<String>> dockerParams, String registry, String username, String password) throws IOException {
266278

267279
checkDockerDaemonAlive();
268280

0 commit comments

Comments
 (0)