From 78ecd63c50ccf82a136f522005286fbb50eac065 Mon Sep 17 00:00:00 2001
From: Jonathan Leech-Pepin <jonathan@leechpepin.com>
Date: Thu, 20 Feb 2025 20:03:21 -0500
Subject: [PATCH] Deploy dolibarr

---
 namespaces/apps/dolibarr/kustomization.yaml   | 94 +++++++++++++++++++
 .../apps/dolibarr/patches/deployment.yaml     | 47 ++++++++++
 namespaces/apps/dolibarr/patches/pvc.yaml     |  8 ++
 3 files changed, 149 insertions(+)
 create mode 100644 namespaces/apps/dolibarr/kustomization.yaml
 create mode 100644 namespaces/apps/dolibarr/patches/deployment.yaml
 create mode 100644 namespaces/apps/dolibarr/patches/pvc.yaml

diff --git a/namespaces/apps/dolibarr/kustomization.yaml b/namespaces/apps/dolibarr/kustomization.yaml
new file mode 100644
index 0000000..bd424c2
--- /dev/null
+++ b/namespaces/apps/dolibarr/kustomization.yaml
@@ -0,0 +1,94 @@
+apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+
+transformers:
+  - |-
+    apiVersion: builtin
+    kind: NamespaceTransformer
+    metadata:
+      name: notImportantHere
+      namespace: apps
+    unsetOnly: true
+
+namePrefix: dolibarr-
+resources:
+  - ../../../kustomize/public-oidc/
+
+replacements:
+  - source:
+      kind: Service
+      name: svc
+    targets:
+      - select:
+          kind: HTTPRoute
+        options:
+          create: true
+        fieldPaths:
+          - spec.rules.0.backendRefs.0.name
+  - source:
+      kind: Deployment
+      fieldPath: metadata.labels.[app.kubernetes.io/appName]
+    targets:
+      - select:
+          kind: HTTPRoute
+        options:
+          create: true
+          delimiter: "."
+          index: 0
+        fieldPaths:
+          - spec.hostnames.0
+      - select:
+          kind: InfisicalSecret
+        options:
+          delimiter: "-"
+          index: 0
+        fieldPaths:
+          - spec.managedSecretReference.secretName
+      - select:
+          kind: InfisicalSecret
+        options:
+          delimiter: "/"
+          index: 2
+        fieldPaths:
+          - spec.authentication.universalAuth.secretsScope.secretsPath
+      - select:
+          kind: Service
+        fieldPaths:
+          - spec.ports.0.name
+          - spec.ports.0.targetPort
+  - source:
+      kind: Deployment
+      fieldPath: metadata.labels.[app.kubernetes.io/appNamespace]
+    targets:
+      - select:
+          kind: InfisicalSecret
+        fieldPaths:
+          - spec.managedSecretReference.secretNamespace
+
+patches:
+  - path: patches/deployment.yaml
+    target:
+      kind: Deployment
+  - path: patches/pvc.yaml
+    target:
+      kind: PersistentVolumeClaim
+
+labels:
+  - includeSelectors: true
+    pairs:
+      app.kubernetes.io/appName: dolibarr
+  - pairs:
+      app.kubernetes.io/appNamespace: apps
+
+configMapGenerator:
+  - name: config
+    literals:
+      - PHP_INI_DATE_TIMEZONE=America/New_York
+      - DOLI_INSTALL_AUTO=0
+      - DOLI_DB_TYPE=pgsql
+      - DOLI_DB_HOST=postgres.core.svc.cluster.local
+      - DOLI_DB_HOST_PORT=5432
+      - DOLI_DB_USER=dolidbuser
+      - DOLI_COMPANY_NAME="JLP Tech Consulting, LLC"
+      - DOLI_COMPANY_COUNTRYCODE="US"
+      - DOLI_URL_ROOT=https://dolibarr.leechpepin.com
diff --git a/namespaces/apps/dolibarr/patches/deployment.yaml b/namespaces/apps/dolibarr/patches/deployment.yaml
new file mode 100644
index 0000000..ecaf65c
--- /dev/null
+++ b/namespaces/apps/dolibarr/patches/deployment.yaml
@@ -0,0 +1,47 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: app
+spec:
+  template:
+    spec:
+      containers:
+        - name: dolibarr
+          image: dolibarr/dolibarr:20
+          envFrom:
+            - configMapRef:
+                name: dolibarr-config
+          env:
+            - name: DOLI_DB_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: dolibarr-secrets
+                  key: DB_PASSWORD
+                  optional: false
+            - name: DOLI_ADMIN_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: dolibarr-secrets
+                  key: ADMIN_PASSWORD
+                  optional: false
+            - name: DOLI_INSTANCE_UNIQUE_ID
+              valueFrom:
+                secretKeyRef:
+                  name: dolibarr-secrets
+                  key: SECRET_KEY
+                  optional: false
+          ports:
+            - containerPort: 80
+              protocol: TCP
+              name: dolibarr
+          volumeMounts:
+            - mountPath: /var/www/documents
+              name: dolibarr
+              subPath: "documents"
+            - mountPath: /var/www/html/custom
+              name: dolibarr
+              subPath: html_custom
+      volumes:
+        - name: dolibarr
+          persistentVolumeClaim:
+            claimName: dolibarr-pvc
diff --git a/namespaces/apps/dolibarr/patches/pvc.yaml b/namespaces/apps/dolibarr/patches/pvc.yaml
new file mode 100644
index 0000000..06de8f1
--- /dev/null
+++ b/namespaces/apps/dolibarr/patches/pvc.yaml
@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: pvc
+spec:
+  resources:
+    requests:
+      storage: 10Gi