reghao 1 год назад
Родитель
Сommit
2a6d227280

+ 48 - 2
web/src/test/java/cn/reghao/devops/web/devops/DockerTest.java

@@ -1,14 +1,23 @@
 package cn.reghao.devops.web.devops;
 
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
 import cn.reghao.devops.common.docker.DockerImpl;
+import cn.reghao.devops.common.docker.model.Config;
+import cn.reghao.devops.common.docker.model.Volumes;
+import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
+import org.slf4j.LoggerFactory;
 
+import java.util.*;
 import java.util.regex.Pattern;
 
 /**
  * @author reghao
  * @date 2022-05-07 09:32:40
  */
+@Slf4j
 public class DockerTest {
     @Test
     public void dockerListTest() {
@@ -19,12 +28,49 @@ public class DockerTest {
         System.out.println();
     }
 
+    private void setLogLevel() {
+        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
+        Logger rootLogger = loggerContext.getLogger("ROOT");
+        rootLogger.setLevel(Level.INFO);
+    }
+
     @Test
     public void dockerBuildTest() throws Exception {
+        setLogLevel();
         DockerImpl docker = new DockerImpl();
-        String repoTag = "file:12345678";
+        /*String repoTag = "file:12345678";
         String compileHome = "/home/reghao/code/aha/tnb/file/file-service";
-        docker.build(repoTag, compileHome);
+        docker.build(repoTag, compileHome);*/
+
+        String image = "docker.alpha.iquizoo.com/node:14.21";
+        String sourceCodeDir = "/home/reghao/Downloads/0/tnbapp";
+        sourceCodeDir = "/home/reghao/Downloads/iquizoo.admin/";
+        String nodeModulesDir = "/home/reghao/Downloads/0/node_modules";
+        String buildCmd = "npm run build";
+        String buildCmd1 = "npm i && npm run build";
+        String buildCmd2 = "npm run test";
+        String buildCmd3 = "npm --registry http://registry.npm.taobao.org i && npm run test";
+        String buildCmd4 = "npm --registry http://registry.npm.taobao.org i";
+
+        Config config = new Config(image);
+        config.setVolumes(new Volumes());
+        config.setCmd(List.of("sh", "-c", "cd /front && " + buildCmd));
+
+        Map<String, String> map = config.getVolumes().getMap();
+        map.put(sourceCodeDir, "/front");
+        //map.put(nodeModulesDir, "/front/node_modules");
+
+        long start = 0;
+
+
+        start = System.currentTimeMillis();
+        docker.runAndRm(config);
+        log.info("cost {} ms", System.currentTimeMillis()-start);
+
+        /*config.setCmd(List.of("sh", "-c", "cd /front && " + buildCmd1));
+        start = System.currentTimeMillis();
+        docker.runAndRm(config);
+        log.info("cost {} ms", System.currentTimeMillis()-start);*/
     }
 
     @Test

+ 23 - 0
web/src/test/java/cn/reghao/devops/web/devops/GitTest.java

@@ -1,8 +1,12 @@
 package cn.reghao.devops.web.devops;
 
 import cn.reghao.devops.web.mgr.build.model.constant.RepoAuthType;
+import cn.reghao.devops.web.mgr.build.tool.compiler.ShellCompiler;
 import cn.reghao.devops.web.mgr.build.tool.repo.GitImpl;
 import cn.reghao.devops.web.mgr.builds.model.po.RepoAuthConfig;
+import cn.reghao.jutil.jdk.shell.Shell;
+import cn.reghao.jutil.jdk.shell.ShellExecutor;
+import cn.reghao.jutil.jdk.shell.ShellResult;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.internal.storage.file.FileRepository;
@@ -84,4 +88,23 @@ public class GitTest {
             git.checkout().setStartPoint(revCommit);
         }
     }
+
+    @Test
+    public void compilerTest() {
+        ShellExecutor shell = new ShellExecutor();
+
+        String versionCmd = "/opt/env/java/maven/maven-3.6.0/bin/mvn -v";
+        versionCmd = "/opt/env/dotnet/dotnet-sdk-7.0.203-linux-x64/dotnet --info";
+        versionCmd = "/opt/env/node/node-v14.19.3-linux-x64/bin/node -v";
+        versionCmd = "/usr/bin/python --version";
+        versionCmd = "/usr/bin/java -version";
+        versionCmd = "/usr/bin/cmake --version";
+        versionCmd = "/usr/bin/g++ -v";
+        versionCmd = "/usr/bin/gcc -v";
+
+        ShellResult shellResult = shell.exec(versionCmd.split("\\s+"));
+        if (shellResult.getExitCode() == 0) {
+            System.out.println(shellResult.getResult());
+        }
+    }
 }