Browse Source

feat: ingressHost配置优化

wanghongkai 5 năm trước cách đây
mục cha
commit
3d5181c2c1

+ 23 - 9
src/main/java/cn/seecoder/paas/service/impl/EnvironmentServiceImpl.java

@@ -341,14 +341,16 @@ public class EnvironmentServiceImpl implements EnvironmentService {
                         dockerApi.buildAndPush(directory.toString(), "seecoder-paas-" + labelValue, imageTag, new ProgressHandler() {
                             @Override
                             public void progress(ProgressMessage message) throws DockerException {
-                                sb.append(message.stream());
-                                if (sb.length() > DEFAULT_BUFFER_LENGTH) {
-                                    result.setBuildOutput(result.getBuildOutput() + sb.toString());
-                                    if (result.getBuildOutput().length() > MAX_BUFFER_SIZE) {
-                                        result.setBuildOutput(result.getBuildOutput().substring((int) (result.getBuildOutput().length() - MAX_BUFFER_SIZE)));
+                                if (message.stream() != null) {
+                                    sb.append(message.stream());
+                                    if (sb.length() > DEFAULT_BUFFER_LENGTH) {
+                                        result.setBuildOutput(result.getBuildOutput() + sb.toString());
+                                        if (result.getBuildOutput().length() > MAX_BUFFER_SIZE) {
+                                            result.setBuildOutput(result.getBuildOutput().substring((int) (result.getBuildOutput().length() - MAX_BUFFER_SIZE)));
+                                        }
+                                        sb.setLength(0);
+                                        environmentDAO.save(result);
                                     }
-                                    sb.setLength(0);
-                                    environmentDAO.save(result);
                                 }
                             }
                         });
@@ -369,7 +371,9 @@ public class EnvironmentServiceImpl implements EnvironmentService {
                     }
                 } catch (Exception e) {
                     result.setBuildStatus(BuildStatus.FAIL);
-                    result.setBuildOutput(e.getLocalizedMessage());
+                    if (!e.getLocalizedMessage().contains("Could not acquire image ID or digest following build")) {
+                        result.setBuildOutput(e.getLocalizedMessage());
+                    }
                     environmentDAO.save(result);
                     LoggerUtil.error(logger, e, "构建失败!gitUrl={}, branchOrCommit={}", application.getGitUrl(), result.getBuildTypeValue());
                     return;
@@ -397,9 +401,19 @@ public class EnvironmentServiceImpl implements EnvironmentService {
                     if (configContent.getIngressAnnotations() != null && configContent.getIngressAnnotations().get(port) != null) {
                         ingress.setAnnotations(configContent.getIngressAnnotations().get(port));
                     }
+                    String ingressHost = configContent.getHostPrefix() + "-" + port + "." + deploymentHost;
+                    if (configContent.getIngressPort() != null) {
+                        if (port.equals(configContent.getIngressPort())) {
+                            ingressHost = configContent.getHostPrefix() + "." + deploymentHost;
+                        }
+                    } else {
+                        if (ports.length == 1 || port.equals("80")) {
+                            ingressHost = configContent.getHostPrefix() + "." + deploymentHost;
+                        }
+                    }
                     ingress.setAnnotation(Ingress.REWRITE_ANNOTATION, Ingress.DEFAULT_REWRITE_PATH);
                     ingress.setHttpRules(Collections.singletonList(
-                            Ingress.IngressRule.builder().host(configContent.getHostPrefix() + "-" + port + "." + deploymentHost).ruleValues(
+                            Ingress.IngressRule.builder().host(ingressHost).ruleValues(
                                     Collections.singleton(Ingress.IngressPath.builder()
                                             .path("/")
                                             .serviceName(labelValue)

+ 7 - 1
src/main/java/cn/seecoder/paas/service/model/vo/ConfigVO.java

@@ -27,7 +27,7 @@ public class ConfigVO {
     private static final ConfigContent EMPTY_CONFIG_CONTENT;
 
     static {
-        EMPTY_CONFIG_CONTENT = new ConfigContent(null, Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap(), null, null, Collections.emptyMap());
+        EMPTY_CONFIG_CONTENT = new ConfigContent(null, null, Collections.emptyMap(), null, null, Collections.emptyMap(), Collections.emptyMap(), null, null, Collections.emptyMap());
     }
 
     public static ConfigVO getEmptyConfigVO(ConfigBelongsToType configBelongs, Integer entityId) {
@@ -52,6 +52,12 @@ public class ConfigVO {
         @JsonProperty("servicePort")
         private String servicePort;
 
+        /**
+         * 服务端口
+         */
+        @JsonProperty("ingressPort")
+        private String ingressPort;
+
         /**
          * 环境变量配置
          */