|
@@ -1,14 +1,23 @@
|
|
|
package cn.reghao.devops.web.devops;
|
|
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.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.junit.Test;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author reghao
|
|
* @author reghao
|
|
|
* @date 2022-05-07 09:32:40
|
|
* @date 2022-05-07 09:32:40
|
|
|
*/
|
|
*/
|
|
|
|
|
+@Slf4j
|
|
|
public class DockerTest {
|
|
public class DockerTest {
|
|
|
@Test
|
|
@Test
|
|
|
public void dockerListTest() {
|
|
public void dockerListTest() {
|
|
@@ -19,12 +28,49 @@ public class DockerTest {
|
|
|
System.out.println();
|
|
System.out.println();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void setLogLevel() {
|
|
|
|
|
+ LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
|
|
|
|
|
+ Logger rootLogger = loggerContext.getLogger("ROOT");
|
|
|
|
|
+ rootLogger.setLevel(Level.INFO);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Test
|
|
@Test
|
|
|
public void dockerBuildTest() throws Exception {
|
|
public void dockerBuildTest() throws Exception {
|
|
|
|
|
+ setLogLevel();
|
|
|
DockerImpl docker = new DockerImpl();
|
|
DockerImpl docker = new DockerImpl();
|
|
|
- String repoTag = "file:12345678";
|
|
|
|
|
|
|
+ /*String repoTag = "file:12345678";
|
|
|
String compileHome = "/home/reghao/code/aha/tnb/file/file-service";
|
|
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
|
|
@Test
|