diff --git a/.github/workflows/continuous-delivery.yaml b/.github/workflows/continuous-delivery.yaml index 6fde278..705960a 100644 --- a/.github/workflows/continuous-delivery.yaml +++ b/.github/workflows/continuous-delivery.yaml @@ -8,8 +8,8 @@ on: branches: - main - testcicd - #tags: - # - "v*.*.*" + tags: + - "v*.*.*" paths-ignore: - "**.md" - ".gitignore" diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index 8d4d40a..8d5fb10 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -72,6 +72,7 @@ jobs: IMAGE_NAME: ${{ github.event.repository.name }} run: docker build . --file Dockerfile --tag $IMAGE_NAME - + - name: chk image + run: docker ps -a diff --git a/docker-compose.yaml b/docker-compose.yaml index bf80746..40862ba 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -8,7 +8,7 @@ networks: # jenkins - for workflow manager jenkins: image: jenkins/jenkins:jdk17 - container_name: jenkins + container_name: ape-jenkins platform: linux/amd64 networks: - internal_network @@ -58,11 +58,11 @@ networks: # application-manager mc-application-manager: - image: m-cmp/mc-application-manager + image: m-cmp/mc-application-manager:latest container_name: application-manager - build: - context: ./ - dockerfile: Dockerfile + #build: + #context: ./ + #dockerfile: Dockerfile networks: - external_network - external_network @@ -76,7 +76,7 @@ networks: - DDL_AUTO=create-drop - DB_USER=application - DB_PASS=application!23 - - SQL_DATA_INIT=always + - SQL_DATA_INIT=always # or never healthcheck: # for cb-application-manager test: ["CMD", "nc", "-vz", "localhost", "1324"] interval: 1m diff --git a/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java b/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java index ed58a77..96d76ba 100644 --- a/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java +++ b/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlGenerator.java @@ -20,7 +20,7 @@ @Component public class K8SDeployYamlGenerator { - +/* private V1Pod getPod(K8SPodDTO podDto) { V1Pod pod = new V1Pod(); @@ -72,6 +72,12 @@ public String getPodYaml(K8SPodDTO podDto) { String yaml = buffer.toString(); return yaml; } +*/ + + + + + private V1Deployment getDeployment(K8SDeploymentDTO deploy) { @@ -118,7 +124,7 @@ private V1PodTemplateSpec getPodTemplateSpec(K8SDeploymentDTO deploy){ podTemplateSpec.setMetadata(metadata); K8SPodDTO podDto = deploy.getPodDto(); - V1PodSpec podSpec = getPodSpec(podDto); + //V1PodSpec podSpec = getPodSpec(podDto); /* // add imagepullsecrets if (StringUtils.isNotEmpty(deploy.getImagePullSecret())) { @@ -129,7 +135,7 @@ private V1PodTemplateSpec getPodTemplateSpec(K8SDeploymentDTO deploy){ podSpec.setImagePullSecrets(imagePullSecretsList); } */ - podTemplateSpec.setSpec(podSpec); + //podTemplateSpec.setSpec(podSpec); /* @@ -152,7 +158,7 @@ private V1PodTemplateSpec getPodTemplateSpec(K8SDeploymentDTO deploy){ */ // template.spec.container.volumeMounts - setVolumeMounts(podSpec.getContainers().get(0), deploy.getVolumes()); + //setVolumeMounts(podSpec.getContainers().get(0), deploy.getVolumes()); // template.spec.container.resources //setResource(container, deploy.getResource()); @@ -262,13 +268,13 @@ public String getHpaYaml(K8SHPADTO hpaDto){ } - private V1Service getSvc(K8SServiceDTO svcDto){ - return null; - } - - public String getSvcYaml(K8SServiceDTO svcDto){ - return ""; - } +// private V1Service getSvc(K8SServiceDTO svcDto){ +// return null; +// } +// +// public String getSvcYaml(K8SServiceDTO svcDto){ +// return ""; +// } private V1ObjectMeta getMetadata(String name, String namespace) { diff --git a/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlService.java b/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlService.java deleted file mode 100644 index f276bc3..0000000 --- a/src/main/java/kr/co/mcmp/manifest/K8SDeployYamlService.java +++ /dev/null @@ -1,56 +0,0 @@ -package kr.co.mcmp.manifest; - -//import kr.co.mcmp.devops.service.RepositoryService; -//import org.gitlab.api.models.GitlabProject; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.stereotype.Service; -// -//import java.io.IOException; - -//@Service -public class K8SDeployYamlService { - - /* - - private static Logger log = LoggerFactory.getLogger(K8SDeployYamlService.class); - - - @Autowired - private RepositoryService gitlabService; - - public boolean createK8SYaml(String groupName, String projectName, String projectPath, String deployName, String branch, String yamlContents) throws IOException { - GitlabProject project = gitlabService.getProject(groupName, projectName); - String path = ""; - if(projectPath != null) { - path = convertPath(projectPath); - } - String pathYaml = String.format("%sdevops/k8s/%s/deploy.yaml", path, deployName); - if(project != null){ - boolean existYaml = gitlabService.isExistRespositoryFile(project, pathYaml, branch); - if(!existYaml){ - return gitlabService.createRepositoryFile(project, pathYaml, yamlContents, branch, RepositoryService.DEFAULT_COMMIT_MESSAGE); - }else { - log.info("[K8SBuildDeploy-Creation] deploy.yaml 파일이 이미 존재 합니다. 파일을 update 합니다. project name : {}",project.getName()); - return gitlabService.createRepositoryFile(project, pathYaml, yamlContents, branch, RepositoryService.DEFAULT_COMMIT_MESSAGE); - } - } - return false; - } - - - private String convertPath(String path) { - if(path.equals(".")) { - return ""; - } - if(path.startsWith("/")) { - path = path.substring(1, path.length()); - } - if(!path.endsWith("/")) { - path = path + "/"; - } - return path; - } -*/ -} diff --git a/src/main/java/kr/co/mcmp/manifest/K8SServiceDTO.java b/src/main/java/kr/co/mcmp/manifest/K8SServiceDTO.java deleted file mode 100644 index bcaddf7..0000000 --- a/src/main/java/kr/co/mcmp/manifest/K8SServiceDTO.java +++ /dev/null @@ -1,14 +0,0 @@ -package kr.co.mcmp.manifest; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class K8SServiceDTO { - - - - - -} diff --git a/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java b/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java index 924e49a..6ffd7b5 100644 --- a/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java +++ b/src/main/java/kr/co/mcmp/manifest/YamlGenerateController.java @@ -23,7 +23,10 @@ public class YamlGenerateController { @Operation(summary = "yaml generate for pod") @PostMapping("/pod") public String generatePodYaml(K8SPodDTO k8sPodDto){ - return yamlGenSvc.generatePodYaml(k8sPodDto); + //System.out.println("==================================" + k8sPodDto.toString()); + System.out.println("=================================="); + return ""; + //return yamlGenSvc.generatePodYaml(k8sPodDto); } @Operation(summary = "yaml generate for deployment") diff --git a/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java b/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java index ce98e65..d5ca77e 100644 --- a/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java +++ b/src/main/java/kr/co/mcmp/manifest/YamlGenerateService.java @@ -1,26 +1,32 @@ package kr.co.mcmp.manifest; -import io.kubernetes.client.openapi.models.V1Pod; +import io.kubernetes.client.openapi.models.*; +import io.kubernetes.client.util.Yaml; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + @Service public class YamlGenerateService { Logger logger = LoggerFactory.getLogger(YamlGenerateService.class); - @Autowired - K8SDeployYamlGenerator yamlGen; +// @Autowired +// K8SDeployYamlGenerator yamlGen; public String generatePodYaml(K8SPodDTO podContents){ - return yamlGen.getPodYaml(podContents); + //return yamlGen.getPodYaml(podContents); + return getPodYaml(podContents); } public String generateDeploymentYaml(K8SDeploymentDTO deploy){ - return yamlGen.getDeploymentYaml(deploy); + //return yamlGen.getDeploymentYaml(deploy); + return ""; } public String generateConfigmapYaml(){ @@ -28,7 +34,8 @@ public String generateConfigmapYaml(){ } public String generateHPAYaml(K8SHPADTO hpaDto){ - return yamlGen.getHpaYaml(hpaDto); + //return yamlGen.getHpaYaml(hpaDto); + return ""; } public String generateServiceYaml(){ @@ -36,4 +43,62 @@ public String generateServiceYaml(){ } + + + + private V1Pod getPod(K8SPodDTO podDto) { + + V1Pod pod = new V1Pod(); + pod.setApiVersion(K8S.Controller.Pod.getApiVersion()); + pod.setKind("Pod"); + + V1ObjectMeta metadata = new V1ObjectMeta(); + metadata.setName(podDto.getPodName()); + metadata.setNamespace(podDto.getNamespace()); + metadata.setLabels(podDto.getLabels()); + pod.setMetadata(metadata); + + V1PodSpec podSpec = getPodSpec(podDto); + pod.setSpec(podSpec); + + return pod; + } + + private V1PodSpec getPodSpec(K8SPodDTO podDto){ + V1PodSpec podSpec = new V1PodSpec(); + List containerList = new ArrayList<>(); //podDto.getContainers(); + for(K8SPodDTO.Container cont: podDto.getContainers()){ + V1Container container = new V1Container(); + container.setName(cont.getContainerName()); + container.setImage(cont.getContainerImage()); + List portList = new ArrayList<>(); + for(K8SPodDTO.Port pt: cont.getPorts()) { + V1ContainerPort port = new V1ContainerPort(); + port.setProtocol(pt.getProtocol()); + port.setProtocol(pt.getName()); + port.setContainerPort(pt.getContainerPort()); + portList.add(port); + } + //V1ResourceRequirements resourceReq = new V1ResourceRequirements(); + //resourceReq.setLimits(); + container.setPorts(portList); + containerList.add(container); + } + podSpec.setContainers(containerList); + podSpec.setRestartPolicy(podDto.getRestartPolicy()); + return podSpec; + } + + + public String getPodYaml(K8SPodDTO podDto) { + V1Pod pod = getPod(podDto); + StringBuffer buffer = new StringBuffer(); + buffer.append(Yaml.dump(pod)); + String yaml = buffer.toString(); + return yaml; + } + + + + } diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index b0ce6d4..1c4996a 100755 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -27,7 +27,7 @@ spring: defer-datasopurce-initalization: true generate-ddl: true hibernate: - ddl-auto: ${DDL_AUTO:create-drop} # ${DDL_AUTO:none} + ddl-auto: ${DDL_AUTO:update} # ${DDL_AUTO:none} # ddl-auto: create # 실행할 때에 테이블을 자동으로 생성시킬것인지 #create-drop, update, validate, none # create : SessionFactory 시작시 스키마를 삭제하고 다시 생성 # create-drop : SessionFactory 종료 시 스키마를 삭제 @@ -49,7 +49,7 @@ spring: sql: init: data-locations: classpath:./import.sql - mode: ${SQL_DATA_INIT:always} # ${SQL_DATA_INIT:never} + mode: ${SQL_DATA_INIT:never} #${SQL_DATA_INIT:always} # ${SQL_DATA_INIT:never} platform: h2 #schema-locations: classpath:ddl.sql