|
|
@@ -10,15 +10,22 @@ pipeline {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Definición de variables de entorno
|
|
|
+ environment {
|
|
|
+ NOMBRE_APP = 'jugaralpadel'
|
|
|
+ }
|
|
|
+
|
|
|
+ // Definición de parámetros
|
|
|
parameters {
|
|
|
booleanParam(name: 'install', description: 'Instalar todo', defaultValue: false)
|
|
|
- booleanParam(name: 'clean', description: 'Borrar todo', defaultValue: false)
|
|
|
+ booleanParam(name: 'clean', description: 'Borrar todo', defaultValue: false)
|
|
|
booleanParam(name: 'claims', description: 'Crea PVC', defaultValue: false)
|
|
|
booleanParam(name: 'borraclaims', description: 'Borra PVC', defaultValue: false)
|
|
|
+ booleanParam(name: 'namespace', description: 'Crea namespace', defaultValue: false)
|
|
|
+ booleanParam(name: 'borranamespace', description: 'Borra namespace', defaultValue: false)
|
|
|
}
|
|
|
|
|
|
stages {
|
|
|
-
|
|
|
stage('Crea las PVC') {
|
|
|
when {
|
|
|
expression { params.claims}
|
|
|
@@ -26,8 +33,8 @@ pipeline {
|
|
|
steps {
|
|
|
echo "Creando las PVC..."
|
|
|
container('kubectl') {
|
|
|
- withCredentials([file(credentialsId: 'kubeconfig-imac', variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl create -f K8S/pvc-jugaralpadel.yaml'
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
+ sh 'kubectl create -f K8S/pvc-${NOMBRE_APP}.yaml'
|
|
|
sh 'kubectl create -f K8S/pvc-static.yaml'
|
|
|
sh 'kubectl create -f K8S/pvc-postgresql.yaml'
|
|
|
}
|
|
|
@@ -42,8 +49,9 @@ pipeline {
|
|
|
steps {
|
|
|
echo "Borrando las PVC..."
|
|
|
container('kubectl') {
|
|
|
- withCredentials([file(credentialsId: 'kubeconfig-imac', variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl delete -f K8S/pvc-jugaralpadel.yaml||true'
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
+ sh 'sh K8S/patchPVC.sh||true'
|
|
|
+ sh 'kubectl delete -f K8S/pvc-${NOMBRE_APP}.yaml||true'
|
|
|
sh 'kubectl delete -f K8S/pvc-static.yaml||true'
|
|
|
sh 'kubectl delete -f K8S/pvc-postgresql.yaml||true'
|
|
|
}
|
|
|
@@ -58,26 +66,59 @@ pipeline {
|
|
|
steps {
|
|
|
echo "Borrando todo..."
|
|
|
container('kubectl') {
|
|
|
- withCredentials([file(credentialsId: 'kubeconfig-imac', variable: 'KUBECONFIG')]) {
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
sh 'kubectl delete -f K8S/db-deployment.yaml||true'
|
|
|
sh 'kubectl delete -f K8S/db-service.yaml||true'
|
|
|
|
|
|
- sh 'kubectl delete -f K8S/jugaralpadel-jenkins-deployment.yaml||true'
|
|
|
- sh 'kubectl delete -f K8S/jugaralpadel-ingress.yaml||true'
|
|
|
+ sh 'kubectl delete -f K8S/${NOMBRE_APP}-deployment.yaml||true'
|
|
|
+ sh 'kubectl delete -f K8S/${NOMBRE_APP}-ingress.yaml||true'
|
|
|
|
|
|
sh 'kubectl delete -f K8S/reg-secret.yaml||true'
|
|
|
sh 'kubectl delete -f K8S/env-prod-configmap.yaml||true'
|
|
|
sh 'kubectl delete -f K8S/env-prod-db-configmap.yaml||true'
|
|
|
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ stage('Borra namespace') {
|
|
|
+ when {
|
|
|
+ expression { params.borranamespace }
|
|
|
+ }
|
|
|
+ steps {
|
|
|
+ echo "Borrando namespace..."
|
|
|
+ container('kubectl') {
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
sh 'kubectl delete -f K8S/namespace.yaml||true'
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- stage('Kaniko Build & Push Image') {
|
|
|
+ stage('Crea namespace') {
|
|
|
when {
|
|
|
- expression { !params.clean }
|
|
|
+ expression { params.namespace }
|
|
|
+ }
|
|
|
+ steps {
|
|
|
+ echo "Creando namespace..."
|
|
|
+ container('kubectl') {
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
+ sh 'kubectl apply -f K8S/namespace.yaml'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ stage('Construir image y subirla al registry con Kaniko') {
|
|
|
+ when {
|
|
|
+ allOf {
|
|
|
+ expression { !params.clean }
|
|
|
+ expression { !params.namespace }
|
|
|
+ expression { !params.borranamespace }
|
|
|
+ expression { !params.claims }
|
|
|
+ expression { !params.borraclaims }
|
|
|
+ }
|
|
|
}
|
|
|
steps {
|
|
|
container('kaniko') {
|
|
|
@@ -85,7 +126,7 @@ pipeline {
|
|
|
sh '''
|
|
|
/kaniko/executor --dockerfile `pwd`/Dockerfile \
|
|
|
--context `pwd` \
|
|
|
- --destination=registry.reymota.es/jugaralpadel:${BUILD_NUMBER}
|
|
|
+ --destination=registry.reymota.es/${NOMBRE_APP}:${BUILD_NUMBER}
|
|
|
'''
|
|
|
}
|
|
|
}
|
|
|
@@ -99,8 +140,7 @@ pipeline {
|
|
|
steps {
|
|
|
echo "Creando todo..."
|
|
|
container('kubectl') {
|
|
|
- withCredentials([file(credentialsId: 'kubeconfig-imac', variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl apply -f K8S/namespace.yaml'
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
sh 'kubectl create -f K8S/reg-secret.yaml'
|
|
|
sh 'kubectl create -f K8S/env-prod-configmap.yaml'
|
|
|
sh 'kubectl create -f K8S/env-prod-db-configmap.yaml'
|
|
|
@@ -108,25 +148,32 @@ pipeline {
|
|
|
sh 'kubectl create -f K8S/db-deployment.yaml'
|
|
|
sh 'kubectl create -f K8S/db-service.yaml'
|
|
|
|
|
|
- sh 'sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/jugaralpadel-jenkins-deployment.yaml'
|
|
|
- sh 'kubectl apply -f K8S/jugaralpadel-jenkins-deployment.yaml'
|
|
|
- sh 'kubectl create -f K8S/jugaralpadel-ingress.yaml'
|
|
|
+ sh 'sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
+ sh 'kubectl apply -f K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
+ sh 'kubectl create -f K8S/${NOMBRE_APP}-ingress.yaml'
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- stage('Deploy App to Kubernetes') {
|
|
|
+ stage('Despliega la aplicación en Kubernetes') {
|
|
|
when {
|
|
|
- expression { !params.clean }
|
|
|
+ allOf {
|
|
|
+ expression { !params.clean }
|
|
|
+ expression { !params.namespace }
|
|
|
+ expression { !params.borranamespace }
|
|
|
+ expression { !params.claims }
|
|
|
+ expression { !params.borraclaims }
|
|
|
+ expression { !params.install }
|
|
|
+ }
|
|
|
}
|
|
|
steps {
|
|
|
echo "Desplegando la aplicación"
|
|
|
container('kubectl') {
|
|
|
- withCredentials([file(credentialsId: 'kubeconfig-imac', variable: 'KUBECONFIG')]) {
|
|
|
- sh 'sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/jugaralpadel-jenkins-deployment.yaml'
|
|
|
- sh 'kubectl delete -f K8S/jugaralpadel-jenkins-deployment.yaml || true'
|
|
|
- sh 'kubectl apply -f K8S/jugaralpadel-jenkins-deployment.yaml'
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
+ sh 'sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
+ sh 'kubectl delete -f K8S/${NOMBRE_APP}-deployment.yaml || true'
|
|
|
+ sh 'kubectl apply -f K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
}
|
|
|
}
|
|
|
}
|