Browse Source

Añado Jenkinsfile

Celestino Rey 11 months ago
parent
commit
6365ab5b3e
2 changed files with 164 additions and 0 deletions
  1. 42 0
      Jenkinsfile
  2. 122 0
      K8S/jugaralpadel-jenkins-deployment.yaml

+ 42 - 0
Jenkinsfile

@@ -0,0 +1,42 @@
+pipeline {
+
+  options {
+    ansiColor('xterm')
+  }
+
+  agent {
+    kubernetes {
+      yamlFile 'builder.yaml'
+    }
+  }
+
+  stages {
+
+    stage('Kaniko Build & Push Image') {
+      steps {
+        container('kaniko') {
+          script {
+            sh '''
+            /kaniko/executor --dockerfile `pwd`/Dockerfile \
+                             --context `pwd` \
+                             --destination=registry.reymota.es/jugaralpadel:${BUILD_NUMBER}
+            '''
+          }
+        }
+      }
+    }
+
+    stage('Deploy App to Kubernetes') {
+      steps {
+        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'          
+            sh 'kubectl apply -f K8S/jugaralpadel-jenkins-deployment.yaml'          
+          }
+        }
+      }
+    }
+
+  }
+}

+ 122 - 0
K8S/jugaralpadel-jenkins-deployment.yaml

@@ -0,0 +1,122 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: jugaralpadel
+  namespace: jugaralpadel
+spec:
+  type: NodePort
+  ports:
+    - name: "8080"
+      port: 8080
+      nodePort: 30343
+      targetPort: 8080
+  selector:
+    app: jugaralpadel
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: jugaralpadel
+  namespace: jugaralpadel
+  labels:
+    app: jugaralpadel
+    app.kubernetes.io/part-of: jugaralpadel
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: jugaralpadel
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      labels:
+        app: jugaralpadel
+    spec:
+      containers:
+      - name: jugaralpadel
+        image: registry.reymota.es/jugaralpadel:<TAG>
+        env:
+        - name: IMG_VERSION
+          value: "Jenkins"
+        - name: DEBUG
+          valueFrom:
+            configMapKeyRef:
+              key: DEBUG
+              name: env-prod
+        - name: APP_VERSION
+          valueFrom:
+            configMapKeyRef:
+              key: APP_VERSION
+              name: env-prod
+        - name: MES_COMIENZO_TEMPORADA
+          valueFrom:
+            configMapKeyRef:
+              key: MES_COMIENZO_TEMPORADA
+              name: env-prod
+        - name: DATABASE
+          valueFrom:
+            configMapKeyRef:
+              key: DATABASE
+              name: env-prod
+        - name: SQL_HOST
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_HOST
+              name: env-prod
+        - name: SQL_PORT
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_PORT
+              name: env-prod
+        - name: SQL_ENGINE
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_ENGINE
+              name: env-prod
+        - name: SQL_DATABASE
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_DATABASE
+              name: env-prod
+        - name: SQL_USER
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_USER
+              name: env-prod
+        - name: SQL_PASSWORD
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_PASSWORD
+              name: env-prod
+        ports:
+        - containerPort: 8000
+          protocol: TCP
+        volumeMounts:
+        - mountPath: /app/gestion_reservas/mediafiles
+          name: jugaralpadel-media
+
+        - mountPath: /app/gestion_reservas/eventos/migrations
+          name: jugaralpadel-eventos-migrations
+        - mountPath: /app/gestion_reservas/reymotausers/migrations
+          name: jugaralpadel-reymotausers-migrations
+
+        - mountPath: /app/gestion_reservas/staticfiles
+          name: static-volume
+      imagePullSecrets:
+      - name: myregistrykey
+      restartPolicy: Always
+      volumes:
+      - name: jugaralpadel-media
+        persistentVolumeClaim:
+          claimName: jugaralpadel-media
+      - name: jugaralpadel-eventos-migrations
+        persistentVolumeClaim:
+          claimName: jugaralpadel-eventos-migrations
+      - name: jugaralpadel-reymotausers-migrations
+        persistentVolumeClaim:
+          claimName: jugaralpadel-reymotausers-migrations
+      - name: static-volume
+        persistentVolumeClaim:
+          claimName: static-volume
+status: {}