|
|
@@ -20,10 +20,7 @@ import cn.seecoder.paas.util.ApplicationProperties;
|
|
|
import cn.seecoder.paas.util.AsyncWrapper;
|
|
|
import cn.seecoder.paas.util.LoggerUtil;
|
|
|
import cn.seecoder.paas.util.ServiceException;
|
|
|
-import cn.seecoder.paas.util.enums.BuildStatus;
|
|
|
-import cn.seecoder.paas.util.enums.BuildType;
|
|
|
-import cn.seecoder.paas.util.enums.ConfigBelongsToType;
|
|
|
-import cn.seecoder.paas.util.enums.ResourceLabel;
|
|
|
+import cn.seecoder.paas.util.enums.*;
|
|
|
import com.spotify.docker.client.ProgressHandler;
|
|
|
import com.spotify.docker.client.exceptions.DockerException;
|
|
|
import com.spotify.docker.client.messages.ProgressMessage;
|
|
|
@@ -39,6 +36,7 @@ import javax.transaction.Transactional;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -121,7 +119,7 @@ public class EnvironmentServiceImpl implements EnvironmentService {
|
|
|
if (environment == null) {
|
|
|
throw ServiceException.BAD_REQUEST;
|
|
|
}
|
|
|
- BeanUtils.copyProperties(environmentVO, environment, "id", "appId", "buildStatus", "buildOutput");
|
|
|
+ BeanUtils.copyProperties(environmentVO, environment, "id", "appId", "buildStatus", "buildOutput", "deployStatus", "image", "buildStartTime", "deployStartTime");
|
|
|
}
|
|
|
EnvironmentVO result = EnvironmentConverter.convertToVO(environmentDAO.save(environment));
|
|
|
ConfigVO resultConfigVO;
|
|
|
@@ -186,8 +184,8 @@ public class EnvironmentServiceImpl implements EnvironmentService {
|
|
|
if (result == null) {
|
|
|
throw ServiceException.BAD_REQUEST;
|
|
|
}
|
|
|
- if (result.getBuildStatus() == BuildStatus.BUILDING) {
|
|
|
- throw new ServiceException("101", "存在正在进行的构建!");
|
|
|
+ if (result.getBuildStatus() == BuildStatus.BUILDING || result.getDeployStatus() == DeployStatus.DEPLOYING) {
|
|
|
+ throw new ServiceException("101", "存在正在进行的构建或部署!");
|
|
|
}
|
|
|
Config config = configDAO.findByConfigBelongsAndAndEntityId(ConfigBelongsToType.ENVIRONMENT, id);
|
|
|
if (config == null) {
|
|
|
@@ -199,6 +197,8 @@ public class EnvironmentServiceImpl implements EnvironmentService {
|
|
|
}
|
|
|
result.setBuildOutput("");
|
|
|
result.setBuildStatus(BuildStatus.BUILDING);
|
|
|
+ result.setBuildStartTime(LocalDateTime.now());
|
|
|
+ result.setDeployStatus(DeployStatus.NOT_STARTED);
|
|
|
asyncWrapper.asyncInvoke(() -> buildAsync(id));
|
|
|
return EnvironmentConverter.convertToVO(environmentDAO.save(result));
|
|
|
}
|
|
|
@@ -223,151 +223,221 @@ public class EnvironmentServiceImpl implements EnvironmentService {
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
- void buildAsync(Integer id) throws ServiceException {
|
|
|
+ void buildAsync(Integer id) {
|
|
|
Environment result = environmentDAO.findById(id).get();
|
|
|
- Config config = configDAO.findByConfigBelongsAndAndEntityId(ConfigBelongsToType.ENVIRONMENT, id);
|
|
|
- Application application = applicationDAO.findById(result.getAppId()).get();
|
|
|
- ConfigVO.ConfigContent configContent = ConfigConverter.convertToVO(config).getConfig();
|
|
|
- String labelKey = ResourceLabel.RESOURCE.getCode();
|
|
|
- String labelValue = ResourceLabel.RESOURCE.getGenerator().gen("environment", String.valueOf(result.getAppId()), String.valueOf(result.getId()));
|
|
|
- Map<String, String> labelsMap = Collections.singletonMap(labelKey, labelValue);
|
|
|
- String deploymentNamespace = applicationProperties.getDeploymentNamespace();
|
|
|
- String deploymentHost = applicationProperties.getDeploymentHost();
|
|
|
- String imageName = result.getBuildTypeValue();
|
|
|
- // 1. 有git从git拿到地址进行构建并push
|
|
|
- if (result.getBuildType() == BuildType.FROM_BRANCH_OR_COMMIT) {
|
|
|
- try {
|
|
|
- Path directory = Files.createTempDirectory("seecoder-paas-");
|
|
|
- Git git = gitApi.clone(application.getGitUrl(), directory.toString());
|
|
|
- if (Files.exists(Paths.get(directory.toString(), "Dockerfile"))) {
|
|
|
- git.reset().setMode(ResetCommand.ResetType.HARD).setRef(result.getBuildTypeValue()).call();
|
|
|
- String imageTag = String.valueOf(new Date().getTime());
|
|
|
- dockerApi.buildAndPush(directory.toString(), "seecoder-paas-" + labelValue, imageTag, new ProgressHandler() {
|
|
|
- @Override
|
|
|
- public void progress(ProgressMessage message) throws DockerException {
|
|
|
- result.setBuildOutput(message.stream());
|
|
|
- environmentDAO.save(result);
|
|
|
+ try {
|
|
|
+ Config config = configDAO.findByConfigBelongsAndAndEntityId(ConfigBelongsToType.ENVIRONMENT, id);
|
|
|
+ Application application = applicationDAO.findById(result.getAppId()).get();
|
|
|
+ ConfigVO.ConfigContent configContent = ConfigConverter.convertToVO(config).getConfig();
|
|
|
+ String labelKey = ResourceLabel.RESOURCE.getCode();
|
|
|
+ String labelValue = ResourceLabel.RESOURCE.getGenerator().gen("environment", String.valueOf(result.getAppId()), String.valueOf(result.getId()));
|
|
|
+ Map<String, String> labelsMap = Collections.singletonMap(labelKey, labelValue);
|
|
|
+ String deploymentNamespace = applicationProperties.getDeploymentNamespace();
|
|
|
+ String deploymentHost = applicationProperties.getDeploymentHost();
|
|
|
+ String imageName = result.getBuildTypeValue();
|
|
|
+ // 1. 有git从git拿到地址进行构建并push
|
|
|
+ if (result.getBuildType() == BuildType.FROM_BRANCH_OR_COMMIT) {
|
|
|
+ try {
|
|
|
+ Path directory = Files.createTempDirectory("seecoder-paas-");
|
|
|
+ Git git = gitApi.clone(application.getGitUrl(), directory.toString());
|
|
|
+ if (Files.exists(Paths.get(directory.toString(), "Dockerfile"))) {
|
|
|
+ git.reset().setMode(ResetCommand.ResetType.HARD).setRef(result.getBuildTypeValue()).call();
|
|
|
+ String imageTag = String.valueOf(new Date().getTime());
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ final int DEFAULT_BUFFER_LENGTH = 200;
|
|
|
+ final long MAX_BUFFER_SIZE = 1 << 18;
|
|
|
+ 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)));
|
|
|
+ }
|
|
|
+ sb.setLength(0);
|
|
|
+ environmentDAO.save(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (sb.length() > 0) {
|
|
|
+ result.setBuildOutput(result.getBuildOutput() + sb.toString());
|
|
|
}
|
|
|
- });
|
|
|
- imageName = applicationProperties.getDocker().getRegistry() + "/seecoder-paas-" + labelValue + ":" + imageTag;
|
|
|
- result.setBuildStatus(BuildStatus.SUCCESS);
|
|
|
- environmentDAO.save(result);
|
|
|
- } else {
|
|
|
+ imageName = applicationProperties.getK8s().getImageRegistry() + "/seecoder-paas-" + labelValue + ":" + imageTag;
|
|
|
+ result.setBuildStatus(BuildStatus.SUCCESS);
|
|
|
+ result.setDeployStatus(DeployStatus.DEPLOYING);
|
|
|
+ result.setDeployStartTime(LocalDateTime.now());
|
|
|
+ result.setImage(imageName);
|
|
|
+ environmentDAO.save(result);
|
|
|
+ } else {
|
|
|
+ result.setBuildStatus(BuildStatus.FAIL);
|
|
|
+ result.setBuildOutput("找不到构建文件Dockerfile!");
|
|
|
+ environmentDAO.save(result);
|
|
|
+ throw new ServiceException("102", "找不到构建文件Dockerfile!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
result.setBuildStatus(BuildStatus.FAIL);
|
|
|
- result.setBuildOutput("找不到构建文件Dockerfile!");
|
|
|
+ result.setBuildOutput(e.getLocalizedMessage());
|
|
|
environmentDAO.save(result);
|
|
|
- throw new ServiceException("102", "找不到构建文件Dockerfile!");
|
|
|
+ LoggerUtil.error(logger, e, "构建失败!gitUrl={}, branchOrCommit={}", application.getGitUrl(), result.getBuildTypeValue());
|
|
|
+ return;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- result.setBuildStatus(BuildStatus.FAIL);
|
|
|
- result.setBuildOutput(e.getLocalizedMessage());
|
|
|
- environmentDAO.save(result);
|
|
|
- LoggerUtil.error(logger, "构建失败!gitUrl={}, branchOrCommit={}", application.getGitUrl(), result.getBuildTypeValue());
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- String[] ports = configContent.getServicePort().split(",");
|
|
|
- if (configContent.getHostPrefix() != null) {
|
|
|
- for (String port : ports) {
|
|
|
- // ingress
|
|
|
- List<Ingress> ingresses = ingressApi.getByCondition(K8sObjectRequest.builder()
|
|
|
- .name(labelValue + "-" + port)
|
|
|
- .namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
- Ingress ingress = new Ingress();
|
|
|
- ingress.setNamespace(deploymentNamespace);
|
|
|
- ingress.setName(labelValue + "-" + port);
|
|
|
- ingress.setLabels(labelsMap);
|
|
|
- ingress.setHttpRules(Collections.singletonList(
|
|
|
- Ingress.IngressRule.builder().host(configContent.getHostPrefix() + "-" + port + "." + deploymentHost).ruleValues(
|
|
|
- Collections.singleton(Ingress.IngressPath.builder()
|
|
|
- .path("/")
|
|
|
- .serviceName(labelValue)
|
|
|
- .port(Integer.parseInt(port))
|
|
|
- .build())
|
|
|
- ).build()
|
|
|
- ));
|
|
|
- if (CollectionUtils.isEmpty(ingresses) || ingresses.size() != 1) {
|
|
|
- ingressApi.create(ingress);
|
|
|
- } else {
|
|
|
- ingressApi.update(ingress);
|
|
|
+ String[] ports = configContent.getServicePort().split(",");
|
|
|
+ if (configContent.getHostPrefix() != null) {
|
|
|
+ for (String port : ports) {
|
|
|
+ // ingress
|
|
|
+ List<Ingress> ingresses = ingressApi.getByCondition(K8sObjectRequest.builder()
|
|
|
+ .name(labelValue + "-" + port)
|
|
|
+ .namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
+ Ingress ingress = new Ingress();
|
|
|
+ ingress.setNamespace(deploymentNamespace);
|
|
|
+ ingress.setName(labelValue + "-" + port);
|
|
|
+ ingress.setLabels(labelsMap);
|
|
|
+ ingress.setHttpRules(Collections.singletonList(
|
|
|
+ Ingress.IngressRule.builder().host(configContent.getHostPrefix() + "-" + port + "." + deploymentHost).ruleValues(
|
|
|
+ Collections.singleton(Ingress.IngressPath.builder()
|
|
|
+ .path("/")
|
|
|
+ .serviceName(labelValue)
|
|
|
+ .port(Integer.parseInt(port))
|
|
|
+ .build())
|
|
|
+ ).build()
|
|
|
+ ));
|
|
|
+ if (CollectionUtils.isEmpty(ingresses) || ingresses.size() != 1) {
|
|
|
+ ingressApi.create(ingress);
|
|
|
+ } else {
|
|
|
+ ingressApi.update(ingress);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- // service
|
|
|
- List<Service> svcs = serviceApi.getByCondition(K8sObjectRequest.builder().namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
- Service svc = Service.builder().name(labelValue).labels(labelsMap).namespace(deploymentNamespace).selectors(labelsMap).servicePorts(
|
|
|
- Arrays.stream(ports).map(port ->
|
|
|
- ServicePort.builder()
|
|
|
- .name(labelValue + "-" + port)
|
|
|
- .port(Integer.parseInt(port))
|
|
|
- .targetPort(Integer.parseInt(port))
|
|
|
- .build()).collect(Collectors.toSet())).build();
|
|
|
- if (CollectionUtils.isEmpty(svcs) || svcs.size() != 1) {
|
|
|
- serviceApi.create(svc);
|
|
|
- } else {
|
|
|
- serviceApi.update(svc);
|
|
|
- }
|
|
|
- // 检查secret,没有则创建
|
|
|
- SecretVO secretVO = secretApi.getSecretByName(deploymentNamespace, DEFAULT_IMAGE_PULL_SECRET_NAME);
|
|
|
- if (secretVO == null) {
|
|
|
- secretApi.createPrivateRegistrySecret(
|
|
|
+ // service
|
|
|
+ List<Service> svcs = serviceApi.getByCondition(K8sObjectRequest.builder().namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
+ Service svc = Service.builder().name(labelValue).labels(labelsMap).namespace(deploymentNamespace).selectors(labelsMap).servicePorts(
|
|
|
+ Arrays.stream(ports).map(port ->
|
|
|
+ ServicePort.builder()
|
|
|
+ .name(labelValue + "-" + port)
|
|
|
+ .port(Integer.parseInt(port))
|
|
|
+ .targetPort(Integer.parseInt(port))
|
|
|
+ .build()).collect(Collectors.toSet())).build();
|
|
|
+ if (CollectionUtils.isEmpty(svcs) || svcs.size() != 1) {
|
|
|
+ serviceApi.create(svc);
|
|
|
+ } else {
|
|
|
+ serviceApi.update(svc);
|
|
|
+ }
|
|
|
+ // 检查secret,没有则创建
|
|
|
+ SecretVO secretVO = secretApi.getSecretByName(deploymentNamespace, DEFAULT_IMAGE_PULL_SECRET_NAME);
|
|
|
+ if (secretVO == null) {
|
|
|
+ secretApi.createPrivateRegistrySecret(
|
|
|
deploymentNamespace,
|
|
|
DEFAULT_IMAGE_PULL_SECRET_NAME,
|
|
|
applicationProperties.getK8s().getImageRegistry(),
|
|
|
applicationProperties.getDocker().getRegistryUsername(),
|
|
|
applicationProperties.getDocker().getRegistryPassword()
|
|
|
- );
|
|
|
- }
|
|
|
- // configMap
|
|
|
- List<ConfigMap> configMaps = configMapApi.getByCondition(K8sObjectRequest.builder().namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
- ConfigMap configMap = ConfigMap.builder().data(configContent.getMounts()).build();
|
|
|
- configMap.setName(labelValue);
|
|
|
- configMap.setNamespace(deploymentNamespace);
|
|
|
- configMap.setLabel(labelKey, labelValue);
|
|
|
- if (CollectionUtils.isEmpty(configMaps) || configMaps.size() != 1) {
|
|
|
- configMapApi.create(configMap);
|
|
|
- } else {
|
|
|
- configMapApi.update(configMap);
|
|
|
- }
|
|
|
- // deployment
|
|
|
- List<Deployment> deployments = deploymentApi.getByCondition(K8sObjectRequest.builder().namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
- Deployment deployment = Deployment.builder()
|
|
|
- .imagePullSecrets(Collections.singletonList(DEFAULT_IMAGE_PULL_SECRET_NAME))
|
|
|
- .replicas(configContent.getReplicas() == null ? 1 : configContent.getReplicas())
|
|
|
- .volumes(Collections.singletonList(new V1VolumeBuilder().withName(labelValue).withConfigMap(
|
|
|
+ );
|
|
|
+ }
|
|
|
+ // configMap
|
|
|
+ List<ConfigMap> configMaps = configMapApi.getByCondition(K8sObjectRequest.builder().namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
+ ConfigMap configMap = ConfigMap.builder().data(configContent.getMountsConfigMaps()).build();
|
|
|
+ configMap.setName(labelValue);
|
|
|
+ configMap.setNamespace(deploymentNamespace);
|
|
|
+ configMap.setLabel(labelKey, labelValue);
|
|
|
+ if (CollectionUtils.isEmpty(configMaps) || configMaps.size() != 1) {
|
|
|
+ configMapApi.create(configMap);
|
|
|
+ } else {
|
|
|
+ configMapApi.update(configMap);
|
|
|
+ }
|
|
|
+ // deployment
|
|
|
+ List<Deployment> deployments = deploymentApi.getByCondition(K8sObjectRequest.builder().namespace(deploymentNamespace).labels(labelsMap).build());
|
|
|
+ List<V1Volume> volumes = new ArrayList<>();
|
|
|
+ List<Container.VolumeMount> volumeMounts = new ArrayList<>();
|
|
|
+ if (!CollectionUtils.isEmpty(configMap.getData())) {
|
|
|
+ volumes.add(new V1VolumeBuilder().withName(labelValue).withConfigMap(
|
|
|
new V1ConfigMapVolumeSourceBuilder().withName(labelValue).withItems(
|
|
|
configMap.getData() == null ? null :
|
|
|
- configMap.getData().keySet().stream().map(path -> new V1KeyToPathBuilder().withKey(path).withPath(path).build()).collect(Collectors.toList())
|
|
|
+ configMap.getData().keySet().stream()
|
|
|
+ .map(path -> {
|
|
|
+ String relativePath = path.replaceAll(ConfigVO.ConfigContent.PATH_DELIMITER, "/");
|
|
|
+ String[] arrs = relativePath.split("/");
|
|
|
+ return new V1KeyToPathBuilder()
|
|
|
+ .withKey(path)
|
|
|
+ .withPath(
|
|
|
+ arrs[arrs.length - 1]
|
|
|
+ )
|
|
|
+ .build();
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList())
|
|
|
).build()
|
|
|
- ).build()))
|
|
|
- .containers(Collections.singletonList(
|
|
|
- Container.builder()
|
|
|
- .env(configContent.getEnvs())
|
|
|
- .ports(
|
|
|
- Arrays.stream(ports).map(port ->
|
|
|
- ContainerPort.builder()
|
|
|
- .name(labelValue + "-" + port)
|
|
|
- .port(Integer.parseInt(port))
|
|
|
- .protocol("TCP")
|
|
|
- .build()).collect(Collectors.toSet())
|
|
|
- )
|
|
|
- .args(configContent.getRunArgs() == null ? null : Arrays.asList(configContent.getRunArgs().split(" ")))
|
|
|
- .command(configContent.getRunCommands() == null ? null : Arrays.asList(configContent.getRunCommands().split(" ")))
|
|
|
- .name(labelValue)
|
|
|
- .image(imageName)
|
|
|
- .volumeMounts(Collections.singletonList(Container.VolumeMount.builder()
|
|
|
- .name(labelValue)
|
|
|
- .mountPath("/")
|
|
|
- .build()))
|
|
|
- .build()))
|
|
|
- .build();
|
|
|
- deployment.setName(labelValue);
|
|
|
- deployment.setNamespace(deploymentNamespace);
|
|
|
- deployment.setLabel(labelKey, labelValue);
|
|
|
- if (CollectionUtils.isEmpty(deployments) || deployments.size() != 1) {
|
|
|
- deploymentApi.create(deployment);
|
|
|
- } else {
|
|
|
- deploymentApi.update(deployment);
|
|
|
+ ).build());
|
|
|
+ volumeMounts.addAll(configMap.getData().keySet().stream()
|
|
|
+ .map(path -> {
|
|
|
+ String relativePath = path.replaceAll(ConfigVO.ConfigContent.PATH_DELIMITER, "/");
|
|
|
+ String[] arrs = relativePath.split("/");
|
|
|
+ return Container.VolumeMount.builder()
|
|
|
+ .name(labelValue)
|
|
|
+ .mountPath(relativePath)
|
|
|
+ .subPath(arrs[arrs.length - 1])
|
|
|
+ .build();
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ if (!CollectionUtils.isEmpty(configContent.getHostPath())) {
|
|
|
+ for (Map.Entry<String, String> entry : configContent.getHostPath().entrySet()) {
|
|
|
+ String name = labelValue + "-" + entry.getKey().replaceAll("/", "-");
|
|
|
+ volumes.add(new V1VolumeBuilder().withName(name).withHostPath(
|
|
|
+ new V1HostPathVolumeSourceBuilder().withPath(entry.getKey()).build()
|
|
|
+ ).build());
|
|
|
+ volumeMounts.add(Container.VolumeMount.builder()
|
|
|
+ .name(name)
|
|
|
+ .mountPath(entry.getValue())
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Deployment deployment = Deployment.builder()
|
|
|
+ .imagePullSecrets(Collections.singletonList(DEFAULT_IMAGE_PULL_SECRET_NAME))
|
|
|
+ .timeout(Deployment.DEFAULT_PROGRESS_DEADLINE_SECONDS)
|
|
|
+ .revisionHistoryLimit(Deployment.DEFAULT_REVISION_HISTORY_LIMIT)
|
|
|
+ .replicas(configContent.getReplicas() == null ? 1 : configContent.getReplicas())
|
|
|
+ .volumes(volumes)
|
|
|
+ .containers(Collections.singletonList(
|
|
|
+ Container.builder()
|
|
|
+ .env(configContent.getEnvs())
|
|
|
+ .ports(
|
|
|
+ Arrays.stream(ports).map(port ->
|
|
|
+ ContainerPort.builder()
|
|
|
+ .name(application.getId() + "a" + result.getId() + "e" + port)
|
|
|
+ .port(Integer.parseInt(port))
|
|
|
+ .protocol("TCP")
|
|
|
+ .build()).collect(Collectors.toSet())
|
|
|
+ )
|
|
|
+ .args(configContent.getRunArgs() == null ? null : Arrays.asList(configContent.getRunArgs().split(" ")))
|
|
|
+ .command(configContent.getRunCommands() == null ? null : Arrays.asList(configContent.getRunCommands().split(" ")))
|
|
|
+ .name(labelValue)
|
|
|
+ .image(imageName)
|
|
|
+ .volumeMounts(volumeMounts)
|
|
|
+ .build()))
|
|
|
+ .build();
|
|
|
+ deployment.setName(labelValue);
|
|
|
+ deployment.setNamespace(deploymentNamespace);
|
|
|
+ deployment.setLabel(labelKey, labelValue);
|
|
|
+ if (CollectionUtils.isEmpty(deployments) || deployments.size() != 1) {
|
|
|
+ deploymentApi.create(deployment);
|
|
|
+ } else {
|
|
|
+ deploymentApi.update(deployment);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (result.getBuildStatus() == BuildStatus.BUILDING) {
|
|
|
+ result.setBuildStatus(BuildStatus.FAIL);
|
|
|
+ result.setBuildOutput(e.getLocalizedMessage());
|
|
|
+ }
|
|
|
+ if (result.getDeployStatus() == DeployStatus.DEPLOYING) {
|
|
|
+ result.setDeployStatus(DeployStatus.FAIL);
|
|
|
+ result.setDeployOutput(e.getLocalizedMessage());
|
|
|
+ }
|
|
|
+ environmentDAO.save(result);
|
|
|
+ LoggerUtil.error(logger, e, "流程失败!");
|
|
|
+ return;
|
|
|
}
|
|
|
}
|
|
|
}
|