|
@@ -13,6 +13,7 @@ pipeline {
|
|
|
// Definición de variables de entorno
|
|
// Definición de variables de entorno
|
|
|
environment {
|
|
environment {
|
|
|
NOMBRE_APP = 'jugaralpadel'
|
|
NOMBRE_APP = 'jugaralpadel'
|
|
|
|
|
+ REGISTRO = 'harbor.reymota.es/jugaralpadel'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Definición de parámetros
|
|
// Definición de parámetros
|
|
@@ -23,6 +24,8 @@ pipeline {
|
|
|
booleanParam(name: 'borraclaims', description: 'Borra PVC', defaultValue: false)
|
|
booleanParam(name: 'borraclaims', description: 'Borra PVC', defaultValue: false)
|
|
|
booleanParam(name: 'namespace', description: 'Crea namespace', defaultValue: false)
|
|
booleanParam(name: 'namespace', description: 'Crea namespace', defaultValue: false)
|
|
|
booleanParam(name: 'borranamespace', description: 'Borra namespace', defaultValue: false)
|
|
booleanParam(name: 'borranamespace', description: 'Borra namespace', defaultValue: false)
|
|
|
|
|
+ booleanParam(name: 'creadb', description: 'Crea el objeto para crear la DB en el cúster', defaultValue: false)
|
|
|
|
|
+ booleanParam(name: 'borradb', description: 'Borra el objeto que creó la DB, no la DB', defaultValue: false)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
stages {
|
|
stages {
|
|
@@ -34,9 +37,10 @@ pipeline {
|
|
|
echo "Creando las PVC..."
|
|
echo "Creando las PVC..."
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/pvc-${NOMBRE_APP}.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/pvc-static.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/pvc-postgresql.yaml'
|
|
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ cat K8S/pvc-${NOMBRE_APP}.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
|
|
|
|
|
+ cat K8S/pvc-static.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -50,15 +54,47 @@ pipeline {
|
|
|
echo "Borrando las PVC..."
|
|
echo "Borrando las PVC..."
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
- sh 'sh K8S/patchPVC.sh||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/pvc-${NOMBRE_APP}.yaml||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/pvc-static.yaml||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/pvc-postgresql.yaml||true'
|
|
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ cat K8S/pvc-${NOMBRE_APP}.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f -
|
|
|
|
|
+ cat K8S/pvc-static.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f -
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ stage('Crea el objeto para crear la DB') {
|
|
|
|
|
+ when {
|
|
|
|
|
+ expression { params.creadb}
|
|
|
|
|
+ }
|
|
|
|
|
+ steps {
|
|
|
|
|
+ echo "Creando el objeto que crea la DB..."
|
|
|
|
|
+ container('kubectl') {
|
|
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ kubectl create -f K8S/${NOMBRE_APP}-db.yaml
|
|
|
|
|
+ """
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ stage('Borra el objeto que creó la DB, no la DB') {
|
|
|
|
|
+ when {
|
|
|
|
|
+ expression { params.borradb}
|
|
|
|
|
+ }
|
|
|
|
|
+ steps {
|
|
|
|
|
+ echo "Borrando el objeto que creó la DB..."
|
|
|
|
|
+ container('kubectl') {
|
|
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ kubectl delete -f K8S/${NOMBRE_APP}-db.yaml
|
|
|
|
|
+ """
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
stage('Borra todo') {
|
|
stage('Borra todo') {
|
|
|
when {
|
|
when {
|
|
|
expression { params.clean }
|
|
expression { params.clean }
|
|
@@ -67,16 +103,21 @@ pipeline {
|
|
|
echo "Borrando todo..."
|
|
echo "Borrando todo..."
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/db-deployment.yaml||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/db-service.yaml||true'
|
|
|
|
|
-
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/${NOMBRE_APP}-deployment.yaml||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/${NOMBRE_APP}-ingress.yaml||true'
|
|
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ sed -i 's|<REGISTRO>|${REGISTRO}|' K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-ingress.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/reg-secret.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/secreto-db.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/env-prod-configmap.yaml
|
|
|
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/reg-secret.yaml||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/env-prod-configmap.yaml||true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/env-prod-db-configmap.yaml||true'
|
|
|
|
|
|
|
+ kubectl delete -f K8S/${NOMBRE_APP}-deployment.yaml||true
|
|
|
|
|
+ kubectl delete -f K8S/${NOMBRE_APP}-ingress.yaml||true
|
|
|
|
|
|
|
|
|
|
+ kubectl delete -f K8S/secreto-db.yaml||true
|
|
|
|
|
+ kubectl delete -f K8S/reg-secret.yaml||true
|
|
|
|
|
+ kubectl delete -f K8S/env-prod-configmap.yaml||true
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -90,7 +131,9 @@ pipeline {
|
|
|
echo "Borrando namespace..."
|
|
echo "Borrando namespace..."
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/namespace.yaml||true'
|
|
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ cat K8S/namespace.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f -
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -104,7 +147,9 @@ pipeline {
|
|
|
echo "Creando namespace..."
|
|
echo "Creando namespace..."
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
- sh 'kubectl --insecure-skip-tls-verify apply -f K8S/namespace.yaml'
|
|
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ cat K8S/namespace.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -126,7 +171,7 @@ pipeline {
|
|
|
sh '''
|
|
sh '''
|
|
|
/kaniko/executor --dockerfile `pwd`/Dockerfile \
|
|
/kaniko/executor --dockerfile `pwd`/Dockerfile \
|
|
|
--context `pwd` \
|
|
--context `pwd` \
|
|
|
- --destination=registry.reymota.es/${NOMBRE_APP}:${BUILD_NUMBER}
|
|
|
|
|
|
|
+ --destination=${REGISTRO}/${NOMBRE_APP}:${BUILD_NUMBER}
|
|
|
'''
|
|
'''
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -140,17 +185,23 @@ pipeline {
|
|
|
steps {
|
|
steps {
|
|
|
echo "Creando todo..."
|
|
echo "Creando todo..."
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
- withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/reg-secret.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/env-prod-configmap.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/env-prod-db-configmap.yaml'
|
|
|
|
|
|
|
+ withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ sed -i 's|<REGISTRO>|${REGISTRO}|' K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-ingress.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/reg-secret.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/secreto-db.yaml
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/env-prod-configmap.yaml
|
|
|
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/db-deployment.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/db-service.yaml'
|
|
|
|
|
|
|
+ kubectl create -f K8S/reg-secret.yaml||true
|
|
|
|
|
+ kubectl create -f K8S/secreto-db.yaml||true
|
|
|
|
|
+ kubectl apply -f K8S/env-prod-configmap.yaml
|
|
|
|
|
|
|
|
- sh 'sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify apply -f K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify create -f K8S/${NOMBRE_APP}-ingress.yaml'
|
|
|
|
|
|
|
+ sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ kubectl apply -f K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ kubectl create -f K8S/${NOMBRE_APP}-ingress.yaml||true
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -164,22 +215,25 @@ pipeline {
|
|
|
expression { !params.borranamespace }
|
|
expression { !params.borranamespace }
|
|
|
expression { !params.claims }
|
|
expression { !params.claims }
|
|
|
expression { !params.borraclaims }
|
|
expression { !params.borraclaims }
|
|
|
- expression { !params.install }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
steps {
|
|
steps {
|
|
|
echo "Desplegando la aplicación"
|
|
echo "Desplegando la aplicación"
|
|
|
container('kubectl') {
|
|
container('kubectl') {
|
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
|
|
|
- sh 'sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify delete -f K8S/${NOMBRE_APP}-deployment.yaml || true'
|
|
|
|
|
- sh 'kubectl --insecure-skip-tls-verify apply -f K8S/${NOMBRE_APP}-deployment.yaml'
|
|
|
|
|
|
|
+ sh """#!/bin/bash
|
|
|
|
|
+ sed -i 's|<NS>|"${NAMESPACE}"|' K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ sed -i 's|<REGISTRO>|${REGISTRO}|' K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ sed -i "s/<TAG>/${BUILD_NUMBER}/" K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ kubectl delete -f K8S/${NOMBRE_APP}-deployment.yaml || true
|
|
|
|
|
+ kubectl apply -f K8S/${NOMBRE_APP}-deployment.yaml
|
|
|
|
|
+ """
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- /*
|
|
|
|
|
|
|
+
|
|
|
post {
|
|
post {
|
|
|
always {
|
|
always {
|
|
|
mail to: 'creylopez@yahoo.es',
|
|
mail to: 'creylopez@yahoo.es',
|
|
@@ -209,5 +263,4 @@ pipeline {
|
|
|
mimeType: 'text/html'
|
|
mimeType: 'text/html'
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- */
|
|
|
|
|
}
|
|
}
|