From 42f5dc379febb3a09dcd4ba54220afce72497ced Mon Sep 17 00:00:00 2001
From: Bensidhoum Wissem <wbensidhoum@takima.fr>
Date: Wed, 2 Aug 2023 16:11:33 +0200
Subject: [PATCH] adding api & db with helm template

---
 dist/cdb/templates/api-config.yaml          |  8 +++
 dist/cdb/templates/api-deployment.yaml      | 68 +++++++++++++++++++++
 dist/cdb/templates/api-ingress.yaml         | 20 ++++++
 dist/cdb/templates/api-service.yaml         | 13 ++++
 dist/cdb/templates/front-config.yaml        |  8 +++
 dist/cdb/templates/front-deployment.yaml    | 68 +++++++++++++++++++++
 dist/cdb/templates/front-ingress.yaml       | 20 ++++++
 dist/cdb/templates/front-service.yaml       | 13 ++++
 dist/cdb/templates/pg-config.yaml           |  9 +++
 dist/cdb/templates/pg-credentials.yaml      | 10 +++
 dist/cdb/templates/pg-deployment.yaml       | 58 ++++++++++++++++++
 dist/cdb/templates/pg-service.yaml          | 13 ++++
 templates/_helpers.tpl                      | 53 ++++++++++++++++
 templates/api/api-config.yaml               |  6 ++
 templates/api/api-deployment.yaml           | 68 +++++++++++++++++++++
 templates/api/api-ingress.yaml              | 24 ++++++++
 templates/api/api-service.yaml              | 11 ++++
 templates/{ => front}/front-config.yaml     |  2 +-
 templates/{ => front}/front-deployment.yaml |  6 +-
 templates/{ => front}/front-ingress.yaml    |  4 +-
 templates/{ => front}/front-service.yaml    |  2 +-
 templates/pg/pg-config.yaml                 |  7 +++
 templates/pg/pg-credentials.yaml            |  8 +++
 templates/pg/pg-deployment.yaml             | 56 +++++++++++++++++
 templates/pg/pg-service.yaml                | 11 ++++
 values-preprod.yaml                         | 20 ++++++
 values-prod.yaml                            | 20 ++++++
 values.yaml                                 |  8 +--
 28 files changed, 604 insertions(+), 10 deletions(-)
 create mode 100644 dist/cdb/templates/api-config.yaml
 create mode 100644 dist/cdb/templates/api-deployment.yaml
 create mode 100644 dist/cdb/templates/api-ingress.yaml
 create mode 100644 dist/cdb/templates/api-service.yaml
 create mode 100644 dist/cdb/templates/front-config.yaml
 create mode 100644 dist/cdb/templates/front-deployment.yaml
 create mode 100644 dist/cdb/templates/front-ingress.yaml
 create mode 100644 dist/cdb/templates/front-service.yaml
 create mode 100644 dist/cdb/templates/pg-config.yaml
 create mode 100644 dist/cdb/templates/pg-credentials.yaml
 create mode 100644 dist/cdb/templates/pg-deployment.yaml
 create mode 100644 dist/cdb/templates/pg-service.yaml
 create mode 100644 templates/_helpers.tpl
 create mode 100644 templates/api/api-config.yaml
 create mode 100644 templates/api/api-deployment.yaml
 create mode 100644 templates/api/api-ingress.yaml
 create mode 100644 templates/api/api-service.yaml
 rename templates/{ => front}/front-config.yaml (87%)
 rename templates/{ => front}/front-deployment.yaml (86%)
 rename templates/{ => front}/front-ingress.yaml (82%)
 rename templates/{ => front}/front-service.yaml (78%)
 create mode 100644 templates/pg/pg-config.yaml
 create mode 100644 templates/pg/pg-credentials.yaml
 create mode 100644 templates/pg/pg-deployment.yaml
 create mode 100644 templates/pg/pg-service.yaml
 create mode 100644 values-preprod.yaml
 create mode 100644 values-prod.yaml

diff --git a/dist/cdb/templates/api-config.yaml b/dist/cdb/templates/api-config.yaml
new file mode 100644
index 0000000..3d39595
--- /dev/null
+++ b/dist/cdb/templates/api-config.yaml
@@ -0,0 +1,8 @@
+---
+# Source: cdb/templates/api-config.yaml
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: api-config
+data:
+  db-endpoint: pg-service:5432
diff --git a/dist/cdb/templates/api-deployment.yaml b/dist/cdb/templates/api-deployment.yaml
new file mode 100644
index 0000000..2cafec3
--- /dev/null
+++ b/dist/cdb/templates/api-deployment.yaml
@@ -0,0 +1,68 @@
+---
+# Source: cdb/templates/api-deployment.yaml
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: api
+  labels:
+    app: api
+spec:
+  #replicas: 1
+  selector:
+    matchLabels:
+      app: api
+  template:
+    metadata:
+      labels:
+        app: api
+    spec:
+      securityContext:
+        runAsUser: 1001
+        runAsGroup: 1001
+      containers:
+        - name: api
+          image: registry.gitlab.com/takima-school/images/cdb/api:latest
+          ports:
+            - containerPort: 80
+          env:
+            - name: DB_ENDPOINT
+              valueFrom:
+                configMapKeyRef:
+                  name: api-config
+                  key: db-endpoint
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: pg-config
+                  key: db-name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: user
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: password
+          resources:
+            limits:
+              memory: "256Mi"
+              cpu: "1"
+            requests:
+              memory: "192Mi"
+              cpu: "100m"
+          livenessProbe:
+            httpGet:
+              path: /actuator/health/liveness # Endpoint à vérifier pour la sonde
+              port: 8080 # Port sur lequel le conteneur écoute
+            initialDelaySeconds: 30 # Délai avant de démarrer la première sonde après le démarrage du conteneur
+            periodSeconds: 10 # Période entre chaque sondage
+          readinessProbe:
+            httpGet:
+              path: /actuator/health/readiness
+              port: 8080
+            initialDelaySeconds: 10
+            periodSeconds: 5
+      imagePullSecrets:
+        - name: takima-school-registry
diff --git a/dist/cdb/templates/api-ingress.yaml b/dist/cdb/templates/api-ingress.yaml
new file mode 100644
index 0000000..e0065bb
--- /dev/null
+++ b/dist/cdb/templates/api-ingress.yaml
@@ -0,0 +1,20 @@
+---
+# Source: cdb/templates/api-ingress.yaml
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: nginx
+  name: api-ingress
+spec:
+  rules:
+    - host: api.wbensidhoum.takima.school
+      http:
+        paths:
+          - backend:
+              service:
+                name: api-service
+                port:
+                  number: 80
+            path: /
+            pathType: Prefix
diff --git a/dist/cdb/templates/api-service.yaml b/dist/cdb/templates/api-service.yaml
new file mode 100644
index 0000000..1cc3a89
--- /dev/null
+++ b/dist/cdb/templates/api-service.yaml
@@ -0,0 +1,13 @@
+---
+# Source: cdb/templates/api-service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: api-service
+spec:
+  selector:
+    app: api
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
diff --git a/dist/cdb/templates/front-config.yaml b/dist/cdb/templates/front-config.yaml
new file mode 100644
index 0000000..8e19226
--- /dev/null
+++ b/dist/cdb/templates/front-config.yaml
@@ -0,0 +1,8 @@
+---
+# Source: cdb/templates/front-config.yaml
+apiVersion: v1  
+kind: ConfigMap  
+metadata:  
+  name: cdb-front  
+data:  
+  API_URL: "http://api.wbensidhoum.takima.school"
diff --git a/dist/cdb/templates/front-deployment.yaml b/dist/cdb/templates/front-deployment.yaml
new file mode 100644
index 0000000..86edd8a
--- /dev/null
+++ b/dist/cdb/templates/front-deployment.yaml
@@ -0,0 +1,68 @@
+---
+# Source: cdb/templates/front-deployment.yaml
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: cdb-front
+  labels:
+    app: front
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: front
+  template:
+    metadata:
+      labels:
+        app: front
+    spec:
+      imagePullSecrets:
+        - name: takima-school-registry
+      securityContext:
+        runAsUser: 101
+        runAsGroup: 101
+
+      containers:
+      - name: front
+        image: registry.gitlab.com/takima-school/images/cdb/www:latest
+        imagePullPolicy: Always
+        ports:
+          - containerPort: 8080
+        resources:
+          requests:
+            memory: "32M"
+            cpu: "0.1"
+          limits:
+            memory: "128M"
+            cpu: "1"
+        startupProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          initialDelaySeconds: 3
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+        livenessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 3
+          successThreshold: 1
+          failureThreshold: 3
+        readinessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 3
+        securityContext:
+          allowPrivilegeEscalation: false
+        
+        env: 
+          - name: API_URL
+            valueFrom:
+              configMapKeyRef:
+                name: cdb-front
+                key: API_URL
diff --git a/dist/cdb/templates/front-ingress.yaml b/dist/cdb/templates/front-ingress.yaml
new file mode 100644
index 0000000..edd7da1
--- /dev/null
+++ b/dist/cdb/templates/front-ingress.yaml
@@ -0,0 +1,20 @@
+---
+# Source: cdb/templates/front-ingress.yaml
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+   kubernetes.io/ingress.class: nginx
+ name: cdb-front
+spec:
+  rules:
+  - host: www.wbensidhoum.takima.school
+    http:
+      paths:
+      - backend:
+          service:
+            name: cdb-front
+            port:
+              number: 80
+        path: /
+        pathType: Prefix
diff --git a/dist/cdb/templates/front-service.yaml b/dist/cdb/templates/front-service.yaml
new file mode 100644
index 0000000..eb70755
--- /dev/null
+++ b/dist/cdb/templates/front-service.yaml
@@ -0,0 +1,13 @@
+---
+# Source: cdb/templates/front-service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: cdb-front
+spec:
+  selector:
+    app: front
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
diff --git a/dist/cdb/templates/pg-config.yaml b/dist/cdb/templates/pg-config.yaml
new file mode 100644
index 0000000..d43b488
--- /dev/null
+++ b/dist/cdb/templates/pg-config.yaml
@@ -0,0 +1,9 @@
+---
+# Source: cdb/templates/pg-config.yaml
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: pg-config
+data:
+  db-name: cdb-db
+  db_path: "/var/lib/postgresql/data/pgdata"
diff --git a/dist/cdb/templates/pg-credentials.yaml b/dist/cdb/templates/pg-credentials.yaml
new file mode 100644
index 0000000..58be43e
--- /dev/null
+++ b/dist/cdb/templates/pg-credentials.yaml
@@ -0,0 +1,10 @@
+---
+# Source: cdb/templates/pg-credentials.yaml
+apiVersion: v1
+kind: Secret
+metadata:
+  name: pg-credentials
+type: Opaque
+data:
+  user: d2lzc2Vt
+  password: d2lzc2Vt
diff --git a/dist/cdb/templates/pg-deployment.yaml b/dist/cdb/templates/pg-deployment.yaml
new file mode 100644
index 0000000..d73cee2
--- /dev/null
+++ b/dist/cdb/templates/pg-deployment.yaml
@@ -0,0 +1,58 @@
+---
+# Source: cdb/templates/pg-deployment.yaml
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  name: pg
+  labels:
+    app: pg
+spec:
+  volumeClaimTemplates:
+    - metadata:
+        name: pg-data
+      spec:
+        accessModes: ["ReadWriteOnce"]
+        resources:
+          requests:
+            storage: 1Gi
+  replicas: 3
+  serviceName: pg-service
+  selector:
+    matchLabels:
+      app: pg
+  template:
+    metadata:
+      labels:
+        app: pg
+    spec:
+      containers:
+        - name: pg
+          image: registry.takima.io/school/proxy/postgres:latest
+          ports:
+            - containerPort: 5432
+          env:
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: pg-config
+                  key: db-name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: user
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: password
+            - name: PGDATA
+              valueFrom:
+                configMapKeyRef:
+                  name: pg-config # Nom du configmap
+                  key: db_path # nom de la clef dans le configMap contenant path ou installer la db dans le volume persistant
+          volumeMounts:
+            - mountPath: /var/lib/postgresql/data
+              name: pg-data
+      imagePullSecrets:
+        - name: takima-school-registry
diff --git a/dist/cdb/templates/pg-service.yaml b/dist/cdb/templates/pg-service.yaml
new file mode 100644
index 0000000..b0067de
--- /dev/null
+++ b/dist/cdb/templates/pg-service.yaml
@@ -0,0 +1,13 @@
+---
+# Source: cdb/templates/pg-service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: pg-service
+spec:
+  selector:
+    app: pg
+  ports:
+    - port: 5432
+      targetPort: 5432
+      protocol: TCP
diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl
new file mode 100644
index 0000000..e27fd56
--- /dev/null
+++ b/templates/_helpers.tpl
@@ -0,0 +1,53 @@
+{{/*
+Expand the name of the chart.
+*/}}
+{{- define "MyAppCtx.name" -}}
+{{- default .Chart.Name | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+
+{{/*
+Application image tag
+We select by default the Chart appVersion or an override in values
+*/}}
+{{- define "MyAppCtx.imageTag" }}
+{{- $name := default .Chart.AppVersion .Values.image.tag }}
+{{- printf "%s" $name }}
+{{- end }}
+
+
+{{/*
+Create a default fully qualified app name.
+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
+*/}}
+{{- define "MyAppCtx.fullname" }}
+{{- $name := default .Chart.Name .Values.nameOverride -}}
+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-"}}
+{{- end }}
+
+{{/*
+Create chart name and version as used by the chart label.
+*/}}
+{{- define "MyAppCtx.chart" -}}
+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
+{{- end }}
+
+{{/*
+Common labels
+*/}}
+{{- define "MyAppCtx.labels" -}}
+helm.sh/chart: {{ include "MyAppCtx.chart" . }}
+{{ include "MyAppCtx.selectorLabels" . }}
+{{- if .Chart.AppVersion }}
+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
+{{- end }}
+app.kubernetes.io/managed-by: {{ .Release.Service }}
+{{- end }}
+
+{{/*
+Selector labels
+*/}}
+{{- define "MyAppCtx.selectorLabels" -}}
+app.kubernetes.io/name: {{ include "MyAppCtx.name" . }}
+app.kubernetes.io/instance: {{ .Release.Name }}
+{{- end }}
diff --git a/templates/api/api-config.yaml b/templates/api/api-config.yaml
new file mode 100644
index 0000000..1bae132
--- /dev/null
+++ b/templates/api/api-config.yaml
@@ -0,0 +1,6 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-api
+data:
+  db-endpoint: {{ include "MyAppCtx.fullname" . }}-pg:5432
diff --git a/templates/api/api-deployment.yaml b/templates/api/api-deployment.yaml
new file mode 100644
index 0000000..a4e126c
--- /dev/null
+++ b/templates/api/api-deployment.yaml
@@ -0,0 +1,68 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-api
+  labels:
+    app: api
+spec:
+  #replicas: 1
+  selector:
+    matchLabels:
+      app: api
+  template:
+    metadata:
+      annotations:
+        checksum/config: {{ include (print $.Template.BasePath "/api/api-config.yaml") . | sha256sum }}
+      labels:
+        app: api
+    spec:
+      securityContext:
+        runAsUser: 1001
+        runAsGroup: 1001
+      containers:
+        - name: api
+          image: registry.gitlab.com/takima-school/images/cdb/api:latest
+          ports:
+            - containerPort: 80
+          env:
+            - name: DB_ENDPOINT
+              valueFrom:
+                configMapKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-api
+                  key: db-endpoint
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-config
+                  key: db-name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-credentials
+                  key: user
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-credentials
+                  key: password
+          resources:
+            limits:
+              memory: "256Mi"
+              cpu: "1"
+            requests:
+              memory: "192Mi"
+              cpu: "100m"
+          livenessProbe:
+            httpGet:
+              path: /actuator/health/liveness # Endpoint à vérifier pour la sonde
+              port: 8080 # Port sur lequel le conteneur écoute
+            initialDelaySeconds: 30 # Délai avant de démarrer la première sonde après le démarrage du conteneur
+            periodSeconds: 10 # Période entre chaque sondage
+          readinessProbe:
+            httpGet:
+              path: /actuator/health/readiness
+              port: 8080
+            initialDelaySeconds: 10
+            periodSeconds: 5
+      imagePullSecrets:
+        - name: takima-school-registry
diff --git a/templates/api/api-ingress.yaml b/templates/api/api-ingress.yaml
new file mode 100644
index 0000000..44bf8b6
--- /dev/null
+++ b/templates/api/api-ingress.yaml
@@ -0,0 +1,24 @@
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: nginx
+  name: {{ include "MyAppCtx.fullname" . }}-api
+spec:
+  rules:
+    - host: {{ .Values.api.ingress.host }}
+      http:
+        paths:
+          - backend:
+              service:
+                name: {{ include "MyAppCtx.fullname" . }}-api
+                port:
+                  number: 80
+            path: /
+            pathType: Prefix
+  {{- if .Values.api.ingress.tlsEnabled }}  
+  tls:
+    - hosts:
+        - {{ .Values.api.ingress.host }}
+      secretName: app-wildcard
+  {{- end }}
diff --git a/templates/api/api-service.yaml b/templates/api/api-service.yaml
new file mode 100644
index 0000000..6228ae7
--- /dev/null
+++ b/templates/api/api-service.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-api
+spec:
+  selector:
+    app: api
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
diff --git a/templates/front-config.yaml b/templates/front/front-config.yaml
similarity index 87%
rename from templates/front-config.yaml
rename to templates/front/front-config.yaml
index da89df7..fde4af8 100644
--- a/templates/front-config.yaml
+++ b/templates/front/front-config.yaml
@@ -8,7 +8,7 @@
 apiVersion: v1  
 kind: ConfigMap  
 metadata:  
-  name: {{ .Values.name }}-front  
+  name: {{ include "MyAppCtx.fullname" . }}-front  
 data:  
   API_URL: {{ $apiUrl }}  
 {{- end }}
\ No newline at end of file
diff --git a/templates/front-deployment.yaml b/templates/front/front-deployment.yaml
similarity index 86%
rename from templates/front-deployment.yaml
rename to templates/front/front-deployment.yaml
index fa7c697..7dac6ae 100644
--- a/templates/front-deployment.yaml
+++ b/templates/front/front-deployment.yaml
@@ -2,7 +2,7 @@
 apiVersion: apps/v1
 kind: Deployment
 metadata:
-  name: {{ .Values.name }}-front
+  name: {{ include "MyAppCtx.fullname" . }}-front
   labels:
     app: front
 spec:
@@ -12,6 +12,8 @@ spec:
       app: front
   template:
     metadata:
+      annotations:
+        checksum/config: {{ include (print $.Template.BasePath "/front/front-config.yaml") . | sha256sum }}
       labels:
         app: front
     spec:
@@ -63,6 +65,6 @@ spec:
           - name: API_URL
             valueFrom:
               configMapKeyRef:
-                name: {{ .Values.name }}-front
+                name: {{ include "MyAppCtx.fullname" . }}-front
                 key: API_URL
 {{- end }}
\ No newline at end of file
diff --git a/templates/front-ingress.yaml b/templates/front/front-ingress.yaml
similarity index 82%
rename from templates/front-ingress.yaml
rename to templates/front/front-ingress.yaml
index 8513bb5..4a3bb59 100644
--- a/templates/front-ingress.yaml
+++ b/templates/front/front-ingress.yaml
@@ -4,7 +4,7 @@ kind: Ingress
 metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
- name: {{ .Values.name }}-front
+ name: {{ include "MyAppCtx.fullname" . }}-front
 spec:
   rules:
   - host: {{ .Values.front.ingress.host }}
@@ -12,7 +12,7 @@ spec:
       paths:
       - backend:
           service:
-            name: {{ .Values.name }}-front
+            name: {{ include "MyAppCtx.fullname" . }}-front
             port:
               number: 80
         path: /
diff --git a/templates/front-service.yaml b/templates/front/front-service.yaml
similarity index 78%
rename from templates/front-service.yaml
rename to templates/front/front-service.yaml
index 8031d1a..a07b193 100644
--- a/templates/front-service.yaml
+++ b/templates/front/front-service.yaml
@@ -2,7 +2,7 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: {{ .Values.name }}-front
+  name: {{ include "MyAppCtx.fullname" . }}-front
 spec:
   selector:
     app: front
diff --git a/templates/pg/pg-config.yaml b/templates/pg/pg-config.yaml
new file mode 100644
index 0000000..e513d0d
--- /dev/null
+++ b/templates/pg/pg-config.yaml
@@ -0,0 +1,7 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-pg-config
+data:
+  db-name: {{ include "MyAppCtx.fullname" . }}-db
+  db_path: "/var/lib/postgresql/data/pgdata"
diff --git a/templates/pg/pg-credentials.yaml b/templates/pg/pg-credentials.yaml
new file mode 100644
index 0000000..bc95c2d
--- /dev/null
+++ b/templates/pg/pg-credentials.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-pg-credentials
+type: Opaque
+data:
+  user: d2lzc2Vt
+  password: d2lzc2Vt
diff --git a/templates/pg/pg-deployment.yaml b/templates/pg/pg-deployment.yaml
new file mode 100644
index 0000000..8349752
--- /dev/null
+++ b/templates/pg/pg-deployment.yaml
@@ -0,0 +1,56 @@
+apiVersion: apps/v1
+kind: StatefulSet
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-pg
+  labels:
+    app: pg
+spec:
+  volumeClaimTemplates:
+    - metadata:
+        name: {{ include "MyAppCtx.fullname" . }}-pg-data
+      spec:
+        accessModes: ["ReadWriteOnce"]
+        resources:
+          requests:
+            storage: 1Gi
+  replicas: 1
+  serviceName: {{ include "MyAppCtx.fullname" . }}-pg
+  selector:
+    matchLabels:
+      app: pg
+  template:
+    metadata:
+      labels:
+        app: pg
+    spec:
+      containers:
+        - name: pg
+          image: registry.takima.io/school/proxy/postgres:latest
+          ports:
+            - containerPort: 5432
+          env:
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-config
+                  key: db-name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-credentials
+                  key: user
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-credentials
+                  key: password
+            - name: PGDATA
+              valueFrom:
+                configMapKeyRef:
+                  name: {{ include "MyAppCtx.fullname" . }}-pg-config # Nom du configmap
+                  key: db_path # nom de la clef dans le configMap contenant path ou installer la db dans le volume persistant
+          volumeMounts:
+            - mountPath: /var/lib/postgresql/data
+              name: {{ include "MyAppCtx.fullname" . }}-pg-data
+      imagePullSecrets:
+        - name: takima-school-registry
diff --git a/templates/pg/pg-service.yaml b/templates/pg/pg-service.yaml
new file mode 100644
index 0000000..45be0df
--- /dev/null
+++ b/templates/pg/pg-service.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ include "MyAppCtx.fullname" . }}-pg
+spec:
+  selector:
+    app: pg
+  ports:
+    - port: 5432
+      targetPort: 5432
+      protocol: TCP
diff --git a/values-preprod.yaml b/values-preprod.yaml
new file mode 100644
index 0000000..52e6c9f
--- /dev/null
+++ b/values-preprod.yaml
@@ -0,0 +1,20 @@
+# Default values for CDB app.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# We have only done front for now
+name: cdb
+
+api:
+  ingress:
+    tlsEnabled: true
+    host: api.preprod.wbensidhoum.takima.school
+
+front:
+  enabled: true
+  image:
+    repository: registry.gitlab.com/takima-school/images/cdb/www
+    tag: latest
+  replicaCount: 1
+  ingress:
+    tlsEnabled: true
+    host: www.preprod.wbensidhoum.takima.school
diff --git a/values-prod.yaml b/values-prod.yaml
new file mode 100644
index 0000000..bc761b0
--- /dev/null
+++ b/values-prod.yaml
@@ -0,0 +1,20 @@
+# Default values for CDB app.
+# This is a YAML-formatted file.
+# Declare variables to be passed into your templates.
+# We have only done front for now
+name: cdb
+
+api:
+  ingress:
+    tlsEnabled: true
+    host: api.prod.wbensidhoum.takima.school
+
+front:
+  enabled: true
+  image:
+    repository: registry.gitlab.com/takima-school/images/cdb/www
+    tag: latest
+  replicaCount: 1
+  ingress:
+    tlsEnabled: true
+    host: www.prod.wbensidhoum.takima.school
diff --git a/values.yaml b/values.yaml
index 9ab42ef..5f6aa14 100644
--- a/values.yaml
+++ b/values.yaml
@@ -6,8 +6,8 @@ name: cdb
 
 api:
   ingress:
-    tlsEnabled: false
-    host: api.to-replace.takima.school
+    tlsEnabled: true
+    host: api.staging.wbensidhoum.takima.school
 
 front:
   enabled: true
@@ -16,5 +16,5 @@ front:
     tag: latest
   replicaCount: 1
   ingress:
-    tlsEnabled: false
-    host: www.to-replace.takima.school
\ No newline at end of file
+    tlsEnabled: true
+    host: www.staging.wbensidhoum.takima.school
-- 
GitLab