Skip to content

Commit

Permalink
Merge pull request #82 from hyun357123/main
Browse files Browse the repository at this point in the history
update k8s piepeline
  • Loading branch information
hyun357123 authored Oct 15, 2024
2 parents 5899282 + 9f7e1e4 commit 347d1cf
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 106 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Once the services are up, you can access the following endpoints:
- Repository UI : `http://<Public_IP>:8081`
- Application Manager UI: `http://<Public_IP>:18084/web`
- OSS Management: `http://<Public_IP>:18084/web/oss/list`
- Application Catalog Management: `http://<Public_IP>:18084/web/catalog/list`
- Application Catalog Management: `http://<Public_IP>:18084/web/softwareCatalog/list`
- Repository Management: `http://<Public_IP>:18084/web/repository/list`
- Yaml Generator: `http://<Public_IP>:18084/web/generate/yaml`

Expand Down
90 changes: 46 additions & 44 deletions src/main/java/kr/co/mcmp/repository/RepositoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,53 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kotlin.Deprecated;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@Tag(name="repository create, update, etc...", description="repository(현재는 nexus)관련 폴더생성, 변경 등")
@RestController
@RequestMapping("/repository")
public class RepositoryController {

Logger logger = LoggerFactory.getLogger(RepositoryController.class);

@Operation(summary = "get repository list")
@GetMapping("/")
public boolean getRepositoryList(){
return false;
}

@Operation(summary = "get repository details")
@GetMapping("/{repositoryName}")
public boolean getRepository(@PathVariable String repositoryName){
return false;
}

@Operation(summary = "create repository")
@PostMapping("/")
public boolean createRepository(){
return false;
}

@Operation(summary = "repository delete")
@DeleteMapping("/")
public boolean deleteRepository(){
return false;
}

@Operation(summary = "update repository")
@PutMapping("/")
public boolean updateRepository(){
return false;
}

@Operation(summary = "insert file")
@PostMapping("/{repositoryName}")
public boolean insertRepository(){
return false;
}

}
// @Tag(name="repository create, update, etc...", description="repository(현재는 nexus)관련 폴더생성, 변경 등")
// @RestController
// @RequestMapping("/repository")
// public class RepositoryController {

// Logger logger = LoggerFactory.getLogger(RepositoryController.class);

// @Operation(summary = "get repository list")
// @GetMapping("/")
// public boolean getRepositoryList(){
// return false;
// }

// @Operation(summary = "get repository details")
// @GetMapping("/{repositoryName}")
// public boolean getRepository(@PathVariable String repositoryName){
// return false;
// }

// @Operation(summary = "create repository")
// @PostMapping("/")
// public boolean createRepository(){
// return false;
// }

// @Operation(summary = "repository delete")
// @DeleteMapping("/")
// public boolean deleteRepository(){
// return false;
// }

// @Operation(summary = "update repository")
// @PutMapping("/")
// public boolean updateRepository(){
// return false;
// }

// @Operation(summary = "insert file")
// @PostMapping("/{repositoryName}")
// public boolean insertRepository(){
// return false;
// }

// }
40 changes: 20 additions & 20 deletions src/main/java/kr/co/mcmp/repository/RepositoryFileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@Tag(name="repository file upload, download", description="repository(현재는 nexus)관련 파일 업로드, 다운로드 등")
@RestController
@RequestMapping("/repository/file")
public class RepositoryFileController {
// @Tag(name="repository file upload, download", description="repository(현재는 nexus)관련 파일 업로드, 다운로드 등")
// @RestController
// @RequestMapping("/repository/file")
// public class RepositoryFileController {

Logger logger = LoggerFactory.getLogger(RepositoryFileController.class);
// Logger logger = LoggerFactory.getLogger(RepositoryFileController.class);

@ApiOperation(value="file upload", notes="file upload")
@PostMapping("/")
public String uploadFiles(){
// 이미 존재하는 파일이라면 기존껀 파일명 바꿔서 백업하고 신규파일 업로드
return null;
}
// @ApiOperation(value="file upload", notes="file upload")
// @PostMapping("/")
// public String uploadFiles(){
// // 이미 존재하는 파일이라면 기존껀 파일명 바꿔서 백업하고 신규파일 업로드
// return null;
// }

@GetMapping("/{filename}") // or packageName
public String getRepositoryFile(@PathVariable String filename){
return null;
}
// @GetMapping("/{filename}") // or packageName
// public String getRepositoryFile(@PathVariable String filename){
// return null;
// }

@DeleteMapping("/{filename}") // or packageName
public String deleteRepositoryFile(@PathVariable String filename){
return null;
}
// @DeleteMapping("/{filename}") // or packageName
// public String deleteRepositoryFile(@PathVariable String filename){
// return null;
// }



}
// }
12 changes: 5 additions & 7 deletions src/main/resources/jenkins/kubernetes_helm_install_pipeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<hudson.model.StringParameterDefinition>
<name>HELM_CHARTS</name>
<description>Helm Charts to Install (comma-separated)</description>
<defaultValue>nginx,grafana,prometheus,tomcat,redis</defaultValue>
<defaultValue>nginx,grafana,prometheus,tomcat,redis,mariadb</defaultValue>
<trim>true</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
Expand All @@ -64,8 +64,6 @@ pipeline {
}
stages {
stage('Check and Install kubectl and Helm') {
steps {
script {
Expand All @@ -92,7 +90,6 @@ pipeline {
'''
env.PATH = "${env.HOME}/bin:${env.PATH}"
env.HELM_INSTALLED = true
}
sh "helm version"
}
Expand Down Expand Up @@ -151,9 +148,10 @@ pipeline {
'grafana': "helm repo add grafana https://grafana.github.io/helm-charts && helm repo update && helm upgrade --install grafana-release grafana/grafana",
'prometheus': "helm repo add prometheus-community https://prometheus-community.github.io/helm-charts && helm repo update && helm upgrade --install prometheus-release prometheus-community/prometheus",
'tomcat': "helm upgrade --install tomcat-release oci://registry-1.docker.io/bitnamicharts/tomcat",
'redis': "helm upgrade --install redis-release oci://registry-1.docker.io/bitnamicharts/redis"
'redis': "helm upgrade --install redis-release oci://registry-1.docker.io/bitnamicharts/redis",
'mariadb': "helm repo add bitnami https://charts.bitnami.com/bitnami && helm repo update && helm upgrade --install mariadb-release bitnami/mariadb --set auth.rootPassword=rootpassword --set auth.database=mydb --set auth.username=myuser --set auth.password=mypassword"
]
def charts = params.HELM_CHARTS.split(',')
charts.each { chart ->
Expand Down Expand Up @@ -212,7 +210,7 @@ pipeline {
echo "Removed kubectl"
}
if (env.HELM_INSTALLED == 'true') {
sh "rm -f /usr/local/bin/helm"
sh "rm -f $HOME/bin/helm"
echo "Removed Helm"
}
}
Expand Down
90 changes: 56 additions & 34 deletions src/main/resources/jenkins/kubernetes_helm_uninstall_pipeline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<description>Tumblebug User Password</description>
<defaultValue>default</defaultValue>
</hudson.model.PasswordParameterDefinition>
<hudson.model.StringParameterDefinition>
<name>HELM_CHARTS</name>
<description>Helm Charts to Uninstall (comma-separated)</description>
<defaultValue>nginx,grafana,prometheus,tomcat,redis</defaultValue>
<trim>true</trim>
</hudson.model.StringParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
Expand All @@ -53,37 +59,43 @@ pipeline {
environment {
PATH = "${env.HOME}/bin:${env.PATH}"
HELM_INSTALLED = false
KUBECTL_INSTALLED = false
}
stages {
stage('Check and Install Tools') {
stage('Check and Install kubectl and Helm') {
steps {
script {
// Check and install kubectl if not present
def kubectlInstalled = sh(script: 'command -v kubectl', returnStatus: true) == 0
if (!kubectlInstalled) {
// Check and install kubectl
if (sh(script: "command -v kubectl", returnStatus: true) != 0) {
sh '''
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
mkdir -p $HOME/bin
mv kubectl $HOME/bin/
'''
env.PATH = "${env.HOME}/bin:${env.PATH}"
env.KUBECTL_INSTALLED = true
}
sh 'kubectl version --client'
sh "kubectl version --client"
// Check and install Helm if not present
def helmInstalled = sh(script: 'command -v helm', returnStatus: true) == 0
if (!helmInstalled) {
// Check and install Helm
if (sh(script: "command -v helm", returnStatus: true) != 0) {
sh '''
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
HELM_INSTALL_DIR=$HOME/bin ./get_helm.sh --no-sudo
rm get_helm.sh
'''
env.PATH = "${env.HOME}/bin:${env.PATH}"
env.HELM_INSTALLED = true
}
sh 'helm version'
sh "helm version"
}
}
}
}
stage('Check Tumblebug Connection') {
steps {
script {
Expand All @@ -92,6 +104,7 @@ pipeline {
--user '${params.TUMBLEBUG_USERID}:${params.TUMBLEBUG_PASSWORD}' \
-H 'accept: application/json'
""", returnStdout: true).trim()
echo "Tumblebug Response: ${response}"
def json = new JsonSlurper().parseText(response)
if (json.message != "CB-Tumblebug is ready") {
error "Tumblebug is not ready: ${json.message}"
Expand All @@ -117,7 +130,6 @@ pipeline {
writeFile file: 'kubeconfig', text: kubeconfig
sh "chmod 600 kubeconfig"
def fileExists = fileExists 'kubeconfig'
if (!fileExists) {
error "Failed to save kubeconfig"
Expand All @@ -131,27 +143,26 @@ pipeline {
stage('Uninstall Helm Charts') {
steps {
script {
def applications = ['nginx', 'tomcat', 'redis', 'grafana', 'prometheus', 'mariadb']
def charts = params.HELM_CHARTS.split(',')
applications.each { app ->
echo "Uninstalling ${app}..."
try {
def releases = sh(script: """
export KUBECONFIG=${WORKSPACE}/kubeconfig
helm list --all-namespaces | grep ${app} | awk '{print \$1}'
""", returnStdout: true).trim().split("\n")
releases.each { release ->
if (release) {
sh """
export KUBECONFIG=${WORKSPACE}/kubeconfig
helm uninstall ${release} --namespace default
"""
echo "${release} uninstalled successfully"
}
charts.each { chart ->
chart = chart.trim()
def releaseName = "${chart}-release"
echo "Checking if ${chart} is installed..."
def isInstalled = sh(script: "helm list --kubeconfig ${WORKSPACE}/kubeconfig | grep ${releaseName}", returnStatus: true) == 0
if (isInstalled) {
echo "Uninstalling ${chart}..."
try {
sh """
export KUBECONFIG=${WORKSPACE}/kubeconfig
helm uninstall ${releaseName}
"""
echo "${chart} uninstalled successfully"
} catch (Exception e) {
echo "Failed to uninstall ${chart}: ${e.message}"
}
} catch (Exception e) {
echo "Failed to uninstall ${app}: ${e.message}"
} else {
echo "${chart} is not installed. Skipping."
}
}
}
Expand All @@ -164,8 +175,8 @@ pipeline {
try {
sh """
export KUBECONFIG=${WORKSPACE}/kubeconfig
helm list --all-namespaces
kubectl get pods,services --all-namespaces
helm list --all-namespaces
"""
} catch (Exception e) {
echo "Failed to verify uninstallations: ${e.message}"
Expand All @@ -179,6 +190,17 @@ pipeline {
always {
sh "rm -f ${WORKSPACE}/kubeconfig"
echo "Removed kubeconfig file"
script {
if (env.KUBECTL_INSTALLED == 'true') {
sh "rm -f $HOME/bin/kubectl"
echo "Removed kubectl"
}
if (env.HELM_INSTALLED == 'true') {
sh "rm -f /usr/local/bin/helm"
echo "Removed Helm"
}
}
}
success {
echo "Helm charts uninstallation and verification completed successfully!"
Expand Down

0 comments on commit 347d1cf

Please sign in to comment.