Explorar o código

Base de datos propia

Celestino Rey hai 6 meses
pai
achega
b11f0f435b
Modificáronse 4 ficheiros con 52 adicións e 5 borrados
  1. 34 0
      Jenkinsfile
  2. 3 0
      K8S/Makefile
  3. 10 0
      K8S/reymota-db.yaml
  4. 5 5
      src/reymota/settings.py

+ 34 - 0
Jenkinsfile

@@ -24,6 +24,8 @@ pipeline {
     booleanParam(name: 'namespace', description: 'Crea namespace', defaultValue: false)
     booleanParam(name: 'borranamespace', description: 'Borra namespace', defaultValue: false)
     booleanParam(name: 'helm', description: 'Instala helm', 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 {
@@ -69,6 +71,38 @@ pipeline {
       }     
     }
 
+    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/peritajes-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/peritajes-db.yaml 
+            """
+          }
+        }
+      }      
+    }
+
     stage('Borra todo') {
       when {
         expression { params.clean }

+ 3 - 0
K8S/Makefile

@@ -15,6 +15,7 @@ install:
 	-cat reg-secret.yaml| sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
 	-cat env-prod-configmap.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
 
+
 	-cat reymota-deployment.yaml | sed -e "s/<NS>/${NAMESPACE}/" | sed -e "s/<TAG>/${IMG_VERSION}/" | kubectl create -f -
 	-cat reymota-ingress.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f -
 
@@ -42,3 +43,5 @@ app:
 	-cat reymota-deployment.yaml | sed -e "s/<NS>/${NAMESPACE}/" | sed -e "s/<TAG>/${IMG_VERSION}/" | kubectl delete -f -
 	-cat reymota-deployment.yaml | sed -e "s/<NS>/${NAMESPACE}/" | sed -e "s/<TAG>/${IMG_VERSION}/" | kubectl create -f -
 
+db:
+	-kubectl create -f reymota-db.yaml

+ 10 - 0
K8S/reymota-db.yaml

@@ -0,0 +1,10 @@
+apiVersion: postgresql.cnpg.io/v1
+kind: Database
+metadata:
+  name: reymota-db
+  namespace: reymota-pg-cluster
+spec:
+  name: reymota
+  owner: creylopez
+  cluster:
+    name: postgres-cluster

+ 5 - 5
src/reymota/settings.py

@@ -98,14 +98,14 @@ WSGI_APPLICATION = 'reymota.wsgi.application'
 DATABASES = {
     "default": {
         "ENGINE": "django.db.backends.postgresql",
-        "NAME": "reymotadb",
+        "NAME": "reymota",
         "USER": "creylopez",
         "PASSWORD": "Dsa-0213",
-        "HOST": "postgres-cluster-rw.reymota-pg-cluster.svc.cluster.local",
+        "HOST": os.environ.get('SQL_HOST','postgres-cluster-rw.reymota-pg-cluster.svc.cluster.local'),
         "PORT": "5432",
-        "OPTIONS": {
-            "options": "-c search_path=reymota,public"
-        }
+        #"OPTIONS": {
+            #"options": "-c search_path=reymota,public"
+        #}
     }
 }