From 03dcc0b21f649f5663ec00aaf0768559bbc47bd9 Mon Sep 17 00:00:00 2001 From: Michal Vala Date: Mon, 22 Jun 2020 13:56:14 +0200 Subject: [PATCH] fix typescriptdto test when running with podman (#17190) Signed-off-by: Michal Vala --- .../dto/TypeScriptDTOGeneratorMojoITest.java | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java b/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java index 1930a4ec1a..e9bc53b8c4 100644 --- a/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java +++ b/core/che-core-typescript-dto-maven-plugin/src/it/java/org/eclipse/che/plugin/typescript/dto/TypeScriptDTOGeneratorMojoITest.java @@ -11,6 +11,7 @@ */ package org.eclipse.che.plugin.typescript.dto; +import java.util.concurrent.TimeUnit; import org.eclipse.che.api.core.util.SystemInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -114,13 +115,19 @@ public class TypeScriptDTOGeneratorMojoITest { } /** - * Generates a docker exec command used to launch node commands + * Generates a docker exec command used to launch node commands. Uses podman if present on the + * system. + * * @return list of command parameters */ - protected List getDockerExec() { + protected List getDockerExec() throws IOException, InterruptedException { // setup command line - List command = new ArrayList(); - command.add("docker"); + List command = new ArrayList<>(); + if (hasPodman()) { + command.add("podman"); + } else { + command.add("docker"); + } command.add("run"); command.add("--rm"); command.add("-v"); @@ -236,11 +243,19 @@ public class TypeScriptDTOGeneratorMojoITest { * @return an updated command with chown applied on it */ protected String wrapLinuxCommand(String command) throws IOException, InterruptedException { - - String setGroup = "export GROUP_NAME=`(getent group " + getGid() + " || (groupadd -g " + getGid() + " user && echo user:x:" + getGid() +")) | cut -d: -f1`"; - String setUser = "export USER_NAME=`(getent passwd " + getUid() + " || (useradd -u " + getUid() + " -g ${GROUP_NAME} user && echo user:x:" + getGid() +")) | cut -d: -f1`"; - String chownCommand= "chown --silent -R ${USER_NAME}.${GROUP_NAME} /usr/src/app || true"; - return setGroup + " && " + setUser + " && " + chownCommand + " && " + command + " && " + chownCommand; + if (hasPodman()) { + LOG.debug("using podman, don't need to wrap anything"); + return command; + } + String setGroup = + "export GROUP_NAME=`(getent group " + getGid() + " || (groupadd -g " + getGid() + + " user && echo user:x:" + getGid() + ")) | cut -d: -f1`"; + String setUser = + "export USER_NAME=`(getent passwd " + getUid() + " || (useradd -u " + getUid() + + " -g ${GROUP_NAME} user && echo user:x:" + getGid() + ")) | cut -d: -f1`"; + String chownCommand = "chown --silent -R ${USER_NAME}.${GROUP_NAME} /usr/src/app || true"; + return setGroup + " && " + setUser + " && " + chownCommand + " && " + command + " && " + + chownCommand; } @@ -304,4 +319,17 @@ public class TypeScriptDTOGeneratorMojoITest { } + private boolean hasPodman() throws InterruptedException, IOException { + if (SystemInfo.isLinux()) { + ProcessBuilder podmanProcessBuilder = new ProcessBuilder("which", "podman"); + Process podmanProcess = podmanProcessBuilder.start(); + if (podmanProcess.waitFor(1, TimeUnit.SECONDS)) { + return podmanProcess.exitValue() == 0; + } else { + return false; + } + } else { + return false; + } + } }