|
|
@@ -3,12 +3,22 @@ package seecoder.devcloud.core;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.spotify.docker.client.DefaultDockerClient;
|
|
|
+import com.spotify.docker.client.DockerCertificates;
|
|
|
+import com.spotify.docker.client.DockerClient;
|
|
|
+import com.spotify.docker.client.DockerConfigReader;
|
|
|
+import com.spotify.docker.client.auth.ConfigFileRegistryAuthSupplier;
|
|
|
+import com.spotify.docker.client.auth.RegistryAuthSupplier;
|
|
|
+import com.spotify.docker.client.exceptions.DockerCertificateException;
|
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+import org.springframework.util.ResourceUtils;
|
|
|
+import org.w3c.dom.Document;
|
|
|
+import org.w3c.dom.NodeList;
|
|
|
import seecoder.devcloud.api.ApplicationProperties;
|
|
|
import seecoder.devcloud.api.k8s.DeploymentApi;
|
|
|
import seecoder.devcloud.api.k8s.IngressApi;
|
|
|
@@ -18,14 +28,24 @@ import seecoder.devcloud.core.pipeline.PipelineException;
|
|
|
import seecoder.devcloud.core.pipeline.config.HandlerConfig;
|
|
|
import seecoder.devcloud.core.pipeline.handler.*;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import javax.xml.parsers.DocumentBuilder;
|
|
|
+import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.net.URI;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RunWith(SpringRunner.class)
|
|
|
@SpringBootTest
|
|
|
class CoreApplicationTests {
|
|
|
|
|
|
@Autowired
|
|
|
- private ApplicationProperties applicationProperties;
|
|
|
+ private ApplicationProperties properties;
|
|
|
|
|
|
@Autowired
|
|
|
private DeploymentApi deploymentApi;
|
|
|
@@ -48,7 +68,9 @@ class CoreApplicationTests {
|
|
|
void k8sDeployment() {
|
|
|
|
|
|
K8sDeploymentHandler handler = new K8sDeploymentHandler();
|
|
|
- context.getConfigs().put("imageName","mysql:5.7");
|
|
|
+ context.getConfigs().put("imageName","seecoder-devcloud-g-p");
|
|
|
+ context.getConfigs().put("imageTag","1616447743417");
|
|
|
+ context.getConfigs().put("port","8081");
|
|
|
try {
|
|
|
handler.process(context);
|
|
|
} catch (PipelineException e) {
|
|
|
@@ -72,7 +94,7 @@ class CoreApplicationTests {
|
|
|
|
|
|
@Test
|
|
|
void k8sService() {
|
|
|
- context.getConfigs().put("port","8000");
|
|
|
+ context.getConfigs().put("port","8081");
|
|
|
K8sServiceHandler k8sServiceHandler = new K8sServiceHandler();
|
|
|
try {
|
|
|
k8sServiceHandler.process(context);
|
|
|
@@ -83,7 +105,7 @@ class CoreApplicationTests {
|
|
|
|
|
|
@Test
|
|
|
void k8sIngress() {
|
|
|
- context.getConfigs().put("servicePort","8000");
|
|
|
+ context.getConfigs().put("servicePort","8081");
|
|
|
K8sIngressHandler ingressHandler = new K8sIngressHandler();
|
|
|
try {
|
|
|
ingressHandler.process(context);
|
|
|
@@ -96,15 +118,41 @@ class CoreApplicationTests {
|
|
|
void k8sImageBuild() {
|
|
|
context.getConfigs().put("repoUrl","http://gitlab.192.168.99.105.nip.io/root/imagebuildetest.git");
|
|
|
context.getConfigs().put("branchName", "master");
|
|
|
- DockerImageBuildHandler dockerImageBuildHandler = new DockerImageBuildHandler();
|
|
|
+ JavaImageBuildHandler javaImageBuildHandler = new JavaImageBuildHandler();
|
|
|
|
|
|
try {
|
|
|
- dockerImageBuildHandler.process(context);
|
|
|
+ javaImageBuildHandler.process(context);
|
|
|
} catch (PipelineException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void k8sImagePush() {
|
|
|
+ String registry = "192.168.99.105:30060";
|
|
|
+ String imageName = "seecoder-devcloud-g-p";
|
|
|
+ String imageTag = "1616399211969";
|
|
|
+ Path dockerConfigPath = null;
|
|
|
+ DockerClient client = null;
|
|
|
+ try {
|
|
|
+ dockerConfigPath = ResourceUtils.getFile("classpath:docker").toPath();
|
|
|
+ if (properties.getDocker().getTls()){
|
|
|
+ client = new DefaultDockerClient(URI.create(properties.getDocker().getHost()), new DockerCertificates(dockerConfigPath));
|
|
|
+ } else {
|
|
|
+ client = new DefaultDockerClient(properties.getDocker().getHost());
|
|
|
+ }
|
|
|
+ } catch (FileNotFoundException | DockerCertificateException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ RegistryAuthSupplier registryAuthSupplier = new ConfigFileRegistryAuthSupplier(new DockerConfigReader(), Paths.get(dockerConfigPath.toString(),"docker-config.json"));
|
|
|
+ client.push(registry + "/" + imageName + ":" + imageTag, registryAuthSupplier.authFor("http://" + registry + "/" + imageName + ":" + imageTag));
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void jsonTrans(){
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
@@ -136,13 +184,39 @@ class CoreApplicationTests {
|
|
|
System.out.println();
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void pomReader(){
|
|
|
+
|
|
|
+ File fXmlFile = Paths.get("C:\\Users\\deponia\\AppData\\Local\\Temp\\seecoder-devcloud-956573437311297579","pom.xml").toFile();
|
|
|
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
|
|
+ DocumentBuilder dBuilder = null;
|
|
|
+ Document doc = null;
|
|
|
+ try {
|
|
|
+ dBuilder = dbFactory.newDocumentBuilder();
|
|
|
+ doc = dBuilder.parse(fXmlFile);
|
|
|
+ doc.getDocumentElement().normalize();
|
|
|
+ NodeList nodes = doc.getChildNodes().item(0).getChildNodes();
|
|
|
+ for (int i = 0; i < 20; i++){
|
|
|
+ System.out.println("dododo: ");
|
|
|
+ System.out.println(nodes.item(i).getNodeName());
|
|
|
+ System.out.println("gogogo: ");
|
|
|
+ System.out.println(nodes.item(i).getNodeValue());
|
|
|
+ System.out.println(nodes.item(i).getTextContent());
|
|
|
+ }
|
|
|
+ System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private void mockContext(){
|
|
|
this.context = Context.builder()
|
|
|
- .namespace("test-group")
|
|
|
- .projectName("test-project")
|
|
|
- .templateName("JAVA8")
|
|
|
+ .namespace("g")
|
|
|
+ .projectName("p")
|
|
|
+ .templateName("SPRINGBOOT-JAVA8")
|
|
|
.pipelineId(1)
|
|
|
- .applicationProperties(applicationProperties)
|
|
|
+ .applicationProperties(properties)
|
|
|
.build();
|
|
|
}
|
|
|
}
|