From fab7c148a98f67e936f9963dcdf76294a9bbc854 Mon Sep 17 00:00:00 2001 From: pfurio Date: Fri, 14 Nov 2025 10:23:35 +0100 Subject: [PATCH] lib: support multiple values for same key, #TASK-7610 --- .../org/opencb/commons/utils/DockerUtils.java | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/commons-lib/src/main/java/org/opencb/commons/utils/DockerUtils.java b/commons-lib/src/main/java/org/opencb/commons/utils/DockerUtils.java index 892fe755..11462b26 100644 --- a/commons-lib/src/main/java/org/opencb/commons/utils/DockerUtils.java +++ b/commons-lib/src/main/java/org/opencb/commons/utils/DockerUtils.java @@ -26,13 +26,13 @@ public class DockerUtils { * @param inputBindings Array of bind mounts for docker input volumes (source-target) * @param outputBinding Bind mount for docker output volume (source-target) * @param cmdParams Image command parameters - * @param dockerParams Docker parameters + * @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings) * @return The command line * @throws IOException IO exception */ public static String buildCommandLine(String image, List> inputBindings, AbstractMap.SimpleEntry outputBinding, String cmdParams, - Map dockerParams) throws IOException { + Map> dockerParams) throws IOException { return buildCommandLine(image, inputBindings, Collections.singletonList(outputBinding), cmdParams, dockerParams); } @@ -43,13 +43,13 @@ public static String buildCommandLine(String image, List> inputBindings, List> outputBindings, String cmdParams, - Map dockerParams) throws IOException { + Map> dockerParams) throws IOException { // Sanity check if (outputBindings == null || outputBindings.isEmpty()) { throw new IllegalArgumentException("Missing output binding(s)"); @@ -65,16 +65,28 @@ public static String buildCommandLine(String image, List values = dockerParams.get(key); + if (values == null || values.isEmpty()) { + if (key.equals("user")) { + // User wants to disable user setting + continue; + } + // Parameter without value (flag) + if (!key.startsWith("-")) { + commandLine.append("--"); + } + commandLine.append(key).append(" "); + } else { + // Parameter with value(s) - can have multiple values for same key + for (String value : values) { + if (!key.startsWith("-")) { + commandLine.append("--"); + } + commandLine.append(key).append(" "); + if (StringUtils.isNotEmpty(value)) { + commandLine.append(value).append(" "); + } + } } } } @@ -198,7 +210,7 @@ public static boolean login(String registry, String username, String password) t * @param inputBindings Array of bind mounts for docker input volumes (source-target) * @param outputBinding Bind mount for docker output volume (source-target) * @param cmdParams Image command parameters - * @param dockerParams Docker parameters + * @param dockerParams Docker parameters (each key can have multiple values, e.g., for multiple --env settings) * @param registry Docker registry URL * @param username Optional Docker registry username * @param password Optional Docker registry password @@ -207,7 +219,7 @@ public static boolean login(String registry, String username, String password) t */ public static String run(String image, List> inputBindings, AbstractMap.SimpleEntry outputBinding, String cmdParams, - Map dockerParams, String registry, String username, String password) throws IOException { + Map> dockerParams, String registry, String username, String password) throws IOException { return run(image, inputBindings, outputBinding != null ? Collections.singletonList(outputBinding) : null, cmdParams, dockerParams, registry, username, password); } @@ -219,13 +231,13 @@ public static String run(String image, List> inputBindings, AbstractMap.SimpleEntry outputBinding, String cmdParams, - Map dockerParams) throws IOException { + Map> dockerParams) throws IOException { return run(image, inputBindings, outputBinding != null ? Collections.singletonList(outputBinding) : null, cmdParams, dockerParams); } @@ -236,13 +248,13 @@ public static String run(String image, List> inputBindings, List> outputBindings, String cmdParams, - Map dockerParams) throws IOException { + Map> dockerParams) throws IOException { return run(image, inputBindings, outputBindings, cmdParams, dockerParams, null, null, null); } @@ -253,7 +265,7 @@ public static String run(String image, List> inputBindings, List> outputBindings, String cmdParams, - Map dockerParams, String registry, String username, String password) throws IOException { + Map> dockerParams, String registry, String username, String password) throws IOException { checkDockerDaemonAlive();