diff --git a/dhorse-api/src/main/java/org/dhorse/api/param/app/AppCreationParam.java b/dhorse-api/src/main/java/org/dhorse/api/param/app/AppCreationParam.java index 0c30e165..96a40055 100644 --- a/dhorse-api/src/main/java/org/dhorse/api/param/app/AppCreationParam.java +++ b/dhorse-api/src/main/java/org/dhorse/api/param/app/AppCreationParam.java @@ -468,6 +468,11 @@ public static class AppExtendNodejsCreationParam implements Serializable { */ private String nodeImage; + /** + * 启动文件 + */ + private String startFile; + public String getNodeVersion() { return nodeVersion; } @@ -484,6 +489,14 @@ public void setNodeImage(String nodeImage) { this.nodeImage = nodeImage; } + public String getStartFile() { + return startFile; + } + + public void setStartFile(String startFile) { + this.startFile = startFile; + } + } /** diff --git a/dhorse-api/src/main/java/org/dhorse/api/response/model/AppExtendNodeJS.java b/dhorse-api/src/main/java/org/dhorse/api/response/model/AppExtendNodejs.java similarity index 69% rename from dhorse-api/src/main/java/org/dhorse/api/response/model/AppExtendNodeJS.java rename to dhorse-api/src/main/java/org/dhorse/api/response/model/AppExtendNodejs.java index adabf4e7..113c1d2f 100644 --- a/dhorse-api/src/main/java/org/dhorse/api/response/model/AppExtendNodeJS.java +++ b/dhorse-api/src/main/java/org/dhorse/api/response/model/AppExtendNodejs.java @@ -2,7 +2,7 @@ import org.dhorse.api.response.model.App.AppExtend; -public class AppExtendNodeJS extends AppExtend { +public class AppExtendNodejs extends AppExtend { private static final long serialVersionUID = 1L; @@ -15,6 +15,11 @@ public class AppExtendNodeJS extends AppExtend { * Node镜像 */ private String nodeImage; + + /** + * 启动文件 + */ + private String startFile; public String getNodeVersion() { return nodeVersion; @@ -32,4 +37,12 @@ public void setNodeImage(String nodeImage) { this.nodeImage = nodeImage; } + public String getStartFile() { + return startFile; + } + + public void setStartFile(String startFile) { + this.startFile = startFile; + } + } \ No newline at end of file diff --git a/dhorse-application/src/main/java/org/dhorse/application/service/AppApplicationService.java b/dhorse-application/src/main/java/org/dhorse/application/service/AppApplicationService.java index 633c12ca..807afd2e 100644 --- a/dhorse-application/src/main/java/org/dhorse/application/service/AppApplicationService.java +++ b/dhorse-application/src/main/java/org/dhorse/application/service/AppApplicationService.java @@ -38,7 +38,7 @@ import org.dhorse.api.response.model.AppExtendJava; import org.dhorse.api.response.model.AppExtendNext; import org.dhorse.api.response.model.AppExtendNode; -import org.dhorse.api.response.model.AppExtendNodeJS; +import org.dhorse.api.response.model.AppExtendNodejs; import org.dhorse.api.response.model.AppExtendNuxt; import org.dhorse.api.response.model.AppExtendPython; import org.dhorse.api.response.model.GlobalConfigAgg; @@ -442,7 +442,7 @@ private AppParam buildBizParam(AppCreationParam requestParam) { BeanUtils.copyProperties(requestParam.getExtendNodeParam(), appExtend); }else if(TechTypeEnum.NODEJS.getCode().equals(requestParam.getTechType()) && requestParam.getExtendNodejsParam() != null) { - appExtend = new AppExtendNodeJS(); + appExtend = new AppExtendNodejs(); BeanUtils.copyProperties(requestParam.getExtendNodejsParam(), appExtend); }else if(TechTypeEnum.HTML.getCode().equals(requestParam.getTechType()) && requestParam.getExtendHtmlParam() != null) { diff --git a/dhorse-application/src/main/java/org/dhorse/application/service/DeploymentApplicationService.java b/dhorse-application/src/main/java/org/dhorse/application/service/DeploymentApplicationService.java index 98a6d320..abc4084f 100644 --- a/dhorse-application/src/main/java/org/dhorse/application/service/DeploymentApplicationService.java +++ b/dhorse-application/src/main/java/org/dhorse/application/service/DeploymentApplicationService.java @@ -42,7 +42,7 @@ import org.dhorse.api.response.model.AppExtendGo; import org.dhorse.api.response.model.AppExtendJava; import org.dhorse.api.response.model.AppExtendNode; -import org.dhorse.api.response.model.AppExtendNodeJS; +import org.dhorse.api.response.model.AppExtendNodejs; import org.dhorse.api.response.model.AppExtendNuxt; import org.dhorse.api.response.model.AppExtendPython; import org.dhorse.api.response.model.DeploymentDetail; @@ -272,8 +272,6 @@ private void deployNotify(DeploymentContext context, DeploymentStatusEnum status message.setSubmitter(context.getSubmitter()); message.setApprover(context.getApprover()); message.setStatus(status.getCode()); - //todo - //message.setTagName(context.get); message.setVerionName(context.getVersionName()); EventResponse response = new EventResponse<>(); @@ -803,7 +801,7 @@ private void buildNodejsImage(DeploymentContext context) { return; } File targetFile = new File(context.getLocalPathOfBranch()); - AppExtendNodeJS appExtend = context.getApp().getAppExtend(); + AppExtendNodejs appExtend = context.getApp().getAppExtend(); String baseImage = Constants.NODE_IMAGE_BASE_URL + appExtend.getNodeVersion().substring(1); if(!StringUtils.isBlank(appExtend.getNodeImage())){ baseImage = appExtend.getNodeImage(); diff --git a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/repository/AppRepository.java b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/repository/AppRepository.java index 8520770f..338efa5a 100644 --- a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/repository/AppRepository.java +++ b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/repository/AppRepository.java @@ -23,7 +23,7 @@ import org.dhorse.api.response.model.AppExtendJava; import org.dhorse.api.response.model.AppExtendNext; import org.dhorse.api.response.model.AppExtendNode; -import org.dhorse.api.response.model.AppExtendNodeJS; +import org.dhorse.api.response.model.AppExtendNodejs; import org.dhorse.api.response.model.AppExtendNuxt; import org.dhorse.api.response.model.AppExtendPython; import org.dhorse.infrastructure.param.AppMemberParam; @@ -149,7 +149,7 @@ private AppExtend queryAppExtend(AppPO appPO) { return JsonUtils.parseToObject(appPO.getExt(), AppExtendNode.class); } if (TechTypeEnum.NODEJS.getCode().equals(appPO.getTechType())) { - return JsonUtils.parseToObject(appPO.getExt(), AppExtendNodeJS.class); + return JsonUtils.parseToObject(appPO.getExt(), AppExtendNodejs.class); } if (TechTypeEnum.HTML.getCode().equals(appPO.getTechType())) { return JsonUtils.parseToObject(appPO.getExt(), AppExtendHtml.class); diff --git a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterHelper.java b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterHelper.java index a8ed4a2c..04c9886f 100644 --- a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterHelper.java +++ b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterHelper.java @@ -403,7 +403,10 @@ public static List updatePrometheus(String kind, Map return paths; } - if(ep != null && kind.equals(ep.getKind()) && (existedAnnotations == null + if(ep != null && kind.equals(ep.getKind()) && (existedAnnotations == null + || StringUtils.isBlank(ep.getScrape()) + || StringUtils.isBlank(ep.getPort()) + || StringUtils.isBlank(ep.getPath()) || !ep.getScrape().equals(existedAnnotations.get("prometheus.io/scrape")) || !ep.getPort().equals(existedAnnotations.get("prometheus.io/port")) || !ep.getPath().equals(existedAnnotations.get("prometheus.io/path")))) { diff --git a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterStrategy.java b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterStrategy.java index 2e91f57e..94e3c408 100644 --- a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterStrategy.java +++ b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/K8sClusterStrategy.java @@ -40,6 +40,7 @@ import org.dhorse.api.response.model.AppExtendDjango; import org.dhorse.api.response.model.AppExtendFlask; import org.dhorse.api.response.model.AppExtendJava; +import org.dhorse.api.response.model.AppExtendNodejs; import org.dhorse.api.response.model.AppExtendNuxt; import org.dhorse.api.response.model.AppExtendPython; import org.dhorse.api.response.model.ClusterNamespace; @@ -1004,15 +1005,19 @@ private void containerOfNodejs(DeploymentContext context, V1Container container) return; } String appHome = Constants.USR_LOCAL_HOME + context.getApp().getAppName(); + String startFile = ((AppExtendNodejs)context.getApp().getAppExtend()).getStartFile(); + if(StringUtils.isBlank(startFile)) { + startFile = "index.js"; + } String commands = new StringBuilder() .append("export NODE_ENV=" + context.getAppEnv().getTag()) .append(" && export HOST=0.0.0.0") .append(" && export PORT=" + context.getAppEnv().getServicePort()) .append(" && cd ").append(appHome) .append(" && npm install --registry=https://registry.npmmirror.com") - .append(" && npm start") + .append(" && exec node " + startFile) .toString(); - container.setCommand(Arrays.asList("/bin/sh", "-c", commands)); + container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); } @@ -1040,8 +1045,8 @@ private void containerOfNuxt(DeploymentContext context, V1Container container) { } commands.append(" && "+ commandType +" install" + registryMirror) .append(" && "+ commandType +" run build") - .append(" && "+ commandType +" start"); - container.setCommand(Arrays.asList("/bin/sh", "-c", commands.toString())); + .append(" && exec "+ commandType +" start"); + container.setCommand(Arrays.asList("sh", "-c", commands.toString())); container.setImage(context.getFullNameOfImage()); } @@ -1087,7 +1092,7 @@ private static void containerOfGo(DeploymentContext context, V1Container contain String commands = new StringBuilder() .append("export GO_ENV=" + context.getAppEnv().getTag()) .append(" && chmod +x "+ executableFile) - .append(" && " + executableFile) + .append(" && exec " + executableFile) .toString(); container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); @@ -1106,7 +1111,7 @@ private static void containerOfPython(DeploymentContext context, V1Container con .append("export PYTHON_ENV=" + context.getAppEnv().getTag()) .append(" && cd " + appHome) .append(" && pip install -r requirements.txt") - .append(" && python " + startFile) + .append(" && exec python " + startFile) .toString(); container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); @@ -1126,7 +1131,7 @@ private static void containerOfFlask(DeploymentContext context, V1Container cont .append(" && export FLASK_ENV=" + context.getAppEnv().getTag()) .append(" && cd " + appHome) .append(" && pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ --use-deprecated=legacy-resolver") - .append(" && flask run --host 0.0.0.0 --port " + context.getAppEnv().getServicePort()) + .append(" && exec flask run --host 0.0.0.0 --port " + context.getAppEnv().getServicePort()) .toString(); container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); @@ -1145,7 +1150,7 @@ private static void containerOfDjango(DeploymentContext context, V1Container con .append("export DJANGO_ENV=" + context.getAppEnv().getTag()) .append(" && cd " + appHome) .append(" && pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ --use-deprecated=legacy-resolver") - .append(" && python ") + .append(" && exec python ") .append(startFile) .append(" runserver") .append(" 0.0.0.0:" + context.getAppEnv().getServicePort()) @@ -1274,8 +1279,8 @@ private V1LifecycleHandler lifecycleHandler(EnvLifecycle.Item item, DeploymentCo */ private void commandsOfJar(V1Container container, DeploymentContext context){ StringBuilder commands = new StringBuilder(); - commands.append("chmod +x $JAVA_HOME/bin/java &&"); - commands.append(" $JAVA_HOME/bin/java"); + commands.append("chmod +x $JAVA_HOME/bin/java"); + commands.append(" && exec $JAVA_HOME/bin/java"); //DHorse定义的Jvm参数 List jvmArgsOfDHorse = jvmArgsOfDHorse(context); for(String arg : jvmArgsOfDHorse) { diff --git a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/k8s/K8sDeploymentHelper.java b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/k8s/K8sDeploymentHelper.java index daebb107..0b7fddf7 100644 --- a/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/k8s/K8sDeploymentHelper.java +++ b/dhorse-infrastructure/src/main/java/org/dhorse/infrastructure/strategy/cluster/k8s/K8sDeploymentHelper.java @@ -24,6 +24,7 @@ import org.dhorse.api.response.model.AppExtendDjango; import org.dhorse.api.response.model.AppExtendFlask; import org.dhorse.api.response.model.AppExtendJava; +import org.dhorse.api.response.model.AppExtendNodejs; import org.dhorse.api.response.model.AppExtendNuxt; import org.dhorse.api.response.model.AppExtendPython; import org.dhorse.api.response.model.EnvHealth; @@ -490,15 +491,19 @@ private static void containerOfNodejs(DeploymentContext context, Container conta return; } String appHome = Constants.USR_LOCAL_HOME + context.getApp().getAppName(); + String startFile = ((AppExtendNodejs)context.getApp().getAppExtend()).getStartFile(); + if(StringUtils.isBlank(startFile)) { + startFile = "index.js"; + } String commands = new StringBuilder() .append("export NODE_ENV=" + context.getAppEnv().getTag()) .append(" && export HOST=0.0.0.0") .append(" && export PORT=" + context.getAppEnv().getServicePort()) .append(" && cd ").append(appHome) .append(" && npm install --registry=https://registry.npmmirror.com") - .append(" && npm start") + .append(" && exec node " + startFile) .toString(); - container.setCommand(Arrays.asList("/bin/sh", "-c", commands)); + container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); } @@ -526,8 +531,8 @@ private static void containerOfNuxt(DeploymentContext context, Container contain } commands.append(" && "+ commandType +" install" + registryMirror) .append(" && "+ commandType +" run build") - .append(" && "+ commandType +" start"); - container.setCommand(Arrays.asList("/bin/sh", "-c", commands.toString())); + .append(" && exec "+ commandType +" start"); + container.setCommand(Arrays.asList("sh", "-c", commands.toString())); container.setImage(context.getFullNameOfImage()); } @@ -573,7 +578,7 @@ private static void containerOfGo(DeploymentContext context, Container container String commands = new StringBuilder() .append("export GO_ENV=" + context.getAppEnv().getTag()) .append(" && chmod +x "+ executableFile) - .append(" && " + executableFile) + .append(" && exec " + executableFile) .toString(); container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); @@ -592,7 +597,7 @@ private static void containerOfPython(DeploymentContext context, Container conta .append("export PYTHON_ENV=" + context.getAppEnv().getTag()) .append(" && cd " + appHome) .append(" && pip install -r requirements.txt") - .append(" && python " + startFile) + .append(" && exec python " + startFile) .toString(); container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); @@ -612,7 +617,7 @@ private static void containerOfFlask(DeploymentContext context, Container contai .append(" && export FLASK_ENV=" + context.getAppEnv().getTag()) .append(" && cd " + appHome) .append(" && pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ --use-deprecated=legacy-resolver") - .append(" && flask run --host 0.0.0.0 --port " + context.getAppEnv().getServicePort()) + .append(" && exec flask run --host 0.0.0.0 --port " + context.getAppEnv().getServicePort()) .toString(); container.setCommand(Arrays.asList("sh", "-c", commands)); container.setImage(context.getFullNameOfImage()); @@ -631,7 +636,7 @@ private static void containerOfDjango(DeploymentContext context, Container conta .append("export DJANGO_ENV=" + context.getAppEnv().getTag()) .append(" && cd " + appHome) .append(" && pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ --use-deprecated=legacy-resolver") - .append(" && python ") + .append(" && exec python ") .append(startFile) .append(" runserver") .append(" 0.0.0.0:" + context.getAppEnv().getServicePort()) @@ -760,8 +765,8 @@ private static LifecycleHandler lifecycleHandler(EnvLifecycle.Item item, Deploym */ private static void commandsOfJar(Container container, DeploymentContext context){ StringBuilder commands = new StringBuilder(); - commands.append("chmod +x $JAVA_HOME/bin/java &&"); - commands.append(" $JAVA_HOME/bin/java"); + commands.append("chmod +x $JAVA_HOME/bin/java"); + commands.append(" && exec $JAVA_HOME/bin/java"); //DHorse定义的Jvm参数 List jvmArgsOfDHorse = jvmArgsOfDHorse(context); for(String arg : jvmArgsOfDHorse) { diff --git a/static/page/app/add.html b/static/page/app/add.html index 24b93fb0..aff47471 100644 --- a/static/page/app/add.html +++ b/static/page/app/add.html @@ -236,6 +236,12 @@ +
+ +
+ +
+
diff --git a/static/page/app/detail.html b/static/page/app/detail.html index 48c88705..c37b7e72 100644 --- a/static/page/app/detail.html +++ b/static/page/app/detail.html @@ -297,6 +297,8 @@ $("#nodeVersionDiv").show(); $("#nodeImage").text(res.data.appExtend.nodeImage); $("#nodeImageDiv").show(); + $("#startFileDiv").show(); + $("#startFile").text(res.data.appExtend.startFile); //Html }else if(res.data.techType == 5){ techType = "Html"; diff --git a/static/page/app/update.html b/static/page/app/update.html index c1fc7aa9..3f977861 100644 --- a/static/page/app/update.html +++ b/static/page/app/update.html @@ -238,6 +238,12 @@
+
+ +
+ +
+