From 1bca35d44477b764f6822a1642af69b38b37a1ab Mon Sep 17 00:00:00 2001
From: seanfredrickcruz <seanfredrick.cruz@stratpoint.com>
Date: Wed, 26 Mar 2025 15:19:39 +0800
Subject: [PATCH] Add task-app Helm chart as regular directory

---
 task-app/.helmignore                          | 23 +++++++++
 task-app/Chart.yaml                           | 24 +++++++++
 task-app/templates/backend-deployment.yaml    | 38 ++++++++++++++
 task-app/templates/backend-service.yaml       | 17 +++++++
 task-app/templates/database-deployment.yaml   | 50 +++++++++++++++++++
 .../templates/database-init-configmap.yaml    | 23 +++++++++
 task-app/templates/database-pvc.yaml          | 15 ++++++
 task-app/templates/database-service.yaml      | 19 +++++++
 task-app/templates/frontend-deployment.yaml   | 28 +++++++++++
 task-app/templates/frontend-service.yaml      | 17 +++++++
 task-app/values.yaml                          | 49 ++++++++++++++++++
 11 files changed, 303 insertions(+)
 create mode 100644 task-app/.helmignore
 create mode 100644 task-app/Chart.yaml
 create mode 100644 task-app/templates/backend-deployment.yaml
 create mode 100644 task-app/templates/backend-service.yaml
 create mode 100644 task-app/templates/database-deployment.yaml
 create mode 100644 task-app/templates/database-init-configmap.yaml
 create mode 100644 task-app/templates/database-pvc.yaml
 create mode 100644 task-app/templates/database-service.yaml
 create mode 100644 task-app/templates/frontend-deployment.yaml
 create mode 100644 task-app/templates/frontend-service.yaml
 create mode 100644 task-app/values.yaml

diff --git a/task-app/.helmignore b/task-app/.helmignore
new file mode 100644
index 0000000..0e8a0eb
--- /dev/null
+++ b/task-app/.helmignore
@@ -0,0 +1,23 @@
+# Patterns to ignore when building packages.
+# This supports shell glob matching, relative path matching, and
+# negation (prefixed with !). Only one pattern per line.
+.DS_Store
+# Common VCS dirs
+.git/
+.gitignore
+.bzr/
+.bzrignore
+.hg/
+.hgignore
+.svn/
+# Common backup files
+*.swp
+*.bak
+*.tmp
+*.orig
+*~
+# Various IDEs
+.project
+.idea/
+*.tmproj
+.vscode/
diff --git a/task-app/Chart.yaml b/task-app/Chart.yaml
new file mode 100644
index 0000000..3fd2755
--- /dev/null
+++ b/task-app/Chart.yaml
@@ -0,0 +1,24 @@
+apiVersion: v2
+name: task-app
+description: Task Management Application
+
+# A chart can be either an 'application' or a 'library' chart.
+#
+# Application charts are a collection of templates that can be packaged into versioned archives
+# to be deployed.
+#
+# Library charts provide useful utilities or functions for the chart developer. They're included as
+# a dependency of application charts to inject those utilities and functions into the rendering
+# pipeline. Library charts do not define any templates and therefore cannot be deployed.
+type: application
+
+# This is the chart version. This version number should be incremented each time you make changes
+# to the chart and its templates, including the app version.
+# Versions are expected to follow Semantic Versioning (https://semver.org/)
+version: 0.1.0
+
+# This is the version number of the application being deployed. This version number should be
+# incremented each time you make changes to the application. Versions are not expected to
+# follow Semantic Versioning. They should reflect the version the application is using.
+# It is recommended to use it with quotes.
+appVersion: "1.0.0"
diff --git a/task-app/templates/backend-deployment.yaml b/task-app/templates/backend-deployment.yaml
new file mode 100644
index 0000000..8546614
--- /dev/null
+++ b/task-app/templates/backend-deployment.yaml
@@ -0,0 +1,38 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Release.Name }}-backend
+  labels:
+    app: backend
+    release: {{ .Release.Name }}
+spec:
+  replicas: {{ .Values.backend.replicaCount }}
+  selector:
+    matchLabels:
+      app: backend
+      release: {{ .Release.Name }}
+  template:
+    metadata:
+      labels:
+        app: backend
+        release: {{ .Release.Name }}
+    spec:
+      containers:
+      - name: backend
+        image: "{{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag }}"
+        imagePullPolicy: {{ .Values.backend.image.pullPolicy | default "IfNotPresent" }}
+        ports:
+        - containerPort: 3000
+        env:
+        - name: NODE_ENV
+          value: {{ .Values.backend.env.NODE_ENV }}
+        - name: DB_HOST
+          value: {{ .Release.Name }}-database
+        - name: DB_PORT
+          value: "{{ .Values.database.service.port }}"
+        - name: DB_NAME
+          value: {{ .Values.backend.env.DB_NAME }}
+        - name: DB_USER
+          value: {{ .Values.backend.env.DB_USER }}
+        - name: DB_PASSWORD
+          value: {{ .Values.backend.env.DB_PASSWORD }}
\ No newline at end of file
diff --git a/task-app/templates/backend-service.yaml b/task-app/templates/backend-service.yaml
new file mode 100644
index 0000000..4a927e5
--- /dev/null
+++ b/task-app/templates/backend-service.yaml
@@ -0,0 +1,17 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Release.Name }}-backend
+  labels:
+    app: backend
+    release: {{ .Release.Name }}
+spec:
+  type: {{ .Values.backend.service.type }}
+  ports:
+  - port: {{ .Values.backend.service.port }}
+    targetPort: 3000
+    protocol: TCP
+    name: http
+  selector:
+    app: backend
+    release: {{ .Release.Name }}
\ No newline at end of file
diff --git a/task-app/templates/database-deployment.yaml b/task-app/templates/database-deployment.yaml
new file mode 100644
index 0000000..0bf484e
--- /dev/null
+++ b/task-app/templates/database-deployment.yaml
@@ -0,0 +1,50 @@
+{{- if .Values.database.enabled }}
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Release.Name }}-database
+  labels:
+    app: database
+    release: {{ .Release.Name }}
+spec:
+  replicas: 1  # Database typically has only one replica
+  selector:
+    matchLabels:
+      app: database
+      release: {{ .Release.Name }}
+  template:
+    metadata:
+      labels:
+        app: database
+        release: {{ .Release.Name }}
+    spec:
+      containers:
+      - name: database
+        image: "{{ .Values.database.image.repository }}:{{ .Values.database.image.tag }}"
+        ports:
+        - containerPort: 5432
+        env:
+        - name: POSTGRES_DB
+          value: {{ .Values.database.env.POSTGRES_DB }}
+        - name: POSTGRES_USER
+          value: {{ .Values.database.env.POSTGRES_USER }}
+        - name: POSTGRES_PASSWORD
+          value: {{ .Values.database.env.POSTGRES_PASSWORD }}
+        volumeMounts:
+        - name: data
+          mountPath: /var/lib/postgresql/data
+        - name: init-script
+          mountPath: /docker-entrypoint-initdb.d
+
+      volumes:
+      - name: data
+        {{- if .Values.database.persistence.enabled }}
+        persistentVolumeClaim:
+          claimName: {{ .Release.Name }}-database-pvc
+      - name: init-script
+        configMap:
+          name: {{ .Release.Name }}-db-init    
+        {{- else }}
+        emptyDir: {}
+        {{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/task-app/templates/database-init-configmap.yaml b/task-app/templates/database-init-configmap.yaml
new file mode 100644
index 0000000..80ec84c
--- /dev/null
+++ b/task-app/templates/database-init-configmap.yaml
@@ -0,0 +1,23 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ .Release.Name }}-db-init
+  labels:
+    app: database
+    release: {{ .Release.Name }}
+data:
+  init.sql: |
+    CREATE TABLE IF NOT EXISTS tasks (
+      id SERIAL PRIMARY KEY,
+      title VARCHAR(255) NOT NULL,
+      description TEXT,
+      status VARCHAR(50) DEFAULT 'Todo',
+      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+    );
+    
+    -- Add some initial tasks
+    INSERT INTO tasks (title, description, status) VALUES
+    ('Set up database', 'Configure PostgreSQL', 'Done'),
+    ('Write API endpoints', 'Create REST API with Express', 'Todo'),
+    ('Complete frontend', 'Implement React components', 'In Progress');
\ No newline at end of file
diff --git a/task-app/templates/database-pvc.yaml b/task-app/templates/database-pvc.yaml
new file mode 100644
index 0000000..e7dcdf8
--- /dev/null
+++ b/task-app/templates/database-pvc.yaml
@@ -0,0 +1,15 @@
+{{- if and .Values.database.enabled .Values.database.persistence.enabled }}
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  name: {{ .Release.Name }}-database-pvc
+  labels:
+    app: database
+    release: {{ .Release.Name }}
+spec:
+  accessModes:
+  - ReadWriteOnce
+  resources:
+    requests:
+      storage: {{ .Values.database.persistence.size }}
+{{- end }}
\ No newline at end of file
diff --git a/task-app/templates/database-service.yaml b/task-app/templates/database-service.yaml
new file mode 100644
index 0000000..2fb0f49
--- /dev/null
+++ b/task-app/templates/database-service.yaml
@@ -0,0 +1,19 @@
+{{- if .Values.database.enabled }}
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Release.Name }}-database
+  labels:
+    app: database
+    release: {{ .Release.Name }}
+spec:
+  type: ClusterIP
+  ports:
+  - port: {{ .Values.database.service.port }}
+    targetPort: 5432
+    protocol: TCP
+    name: postgresql
+  selector:
+    app: database
+    release: {{ .Release.Name }}
+{{- end }}
\ No newline at end of file
diff --git a/task-app/templates/frontend-deployment.yaml b/task-app/templates/frontend-deployment.yaml
new file mode 100644
index 0000000..8dedb30
--- /dev/null
+++ b/task-app/templates/frontend-deployment.yaml
@@ -0,0 +1,28 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ .Release.Name }}-frontend
+  labels:
+    app: frontend
+    release: {{ .Release.Name }}
+spec:
+  replicas: {{ .Values.frontend.replicaCount }}
+  selector:
+    matchLabels:
+      app: frontend
+      release: {{ .Release.Name }}
+  template:
+    metadata:
+      labels:
+        app: frontend
+        release: {{ .Release.Name }}
+    spec:
+      containers:
+      - name: frontend
+        image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}"
+        imagePullPolicy: {{ .Values.frontend.image.pullPolicy | default "IfNotPresent" }}
+        ports:
+        - containerPort: 3000
+        env:
+        - name: REACT_APP_API_URL
+          value: "http://localhost:3001/api"
\ No newline at end of file
diff --git a/task-app/templates/frontend-service.yaml b/task-app/templates/frontend-service.yaml
new file mode 100644
index 0000000..64b035c
--- /dev/null
+++ b/task-app/templates/frontend-service.yaml
@@ -0,0 +1,17 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ .Release.Name }}-frontend
+  labels:
+    app: frontend
+    release: {{ .Release.Name }}
+spec:
+  type: {{ .Values.frontend.service.type }}
+  ports:
+  - port: {{ .Values.frontend.service.port }}
+    targetPort: 3000
+    protocol: TCP
+    name: http
+  selector:
+    app: frontend
+    release: {{ .Release.Name }}
\ No newline at end of file
diff --git a/task-app/values.yaml b/task-app/values.yaml
new file mode 100644
index 0000000..128fdaf
--- /dev/null
+++ b/task-app/values.yaml
@@ -0,0 +1,49 @@
+# Global settings
+global:
+  environment: development
+
+# Frontend configuration
+frontend:
+  replicaCount: 1
+  image:
+    repository: frontend
+    tag: latest
+    pullPolicy: Never
+  service:
+    type: ClusterIP
+    port: 3000  # Using React's dev server port
+
+# Backend configuration
+backend:
+  replicaCount: 1
+  image:
+    repository: backend
+    tag: latest
+    pullPolicy: Never
+  service:
+    type: ClusterIP
+    port: 3000
+  env:
+    NODE_ENV: development
+    DB_HOST: database
+    DB_PORT: 5432
+    DB_NAME: taskdb
+    DB_USER: postgres
+    DB_PASSWORD: postgres
+
+
+# Database configuration
+database:
+  enabled: true
+  image:
+    repository: postgres
+    tag: "13-alpine"
+  service:
+    port: 5432
+  persistence:
+    enabled: true
+    size: 1Gi
+  env:
+    POSTGRES_DB: taskdb
+    POSTGRES_USER: postgres
+    POSTGRES_PASSWORD: postgres
\ No newline at end of file
-- 
GitLab