diff --git a/charts/dateme-chart/templates/backend-deployment.yaml b/charts/dateme-chart/templates/backend-deployment.yaml new file mode 100644 index 0000000..a9540ff --- /dev/null +++ b/charts/dateme-chart/templates/backend-deployment.yaml @@ -0,0 +1,82 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-{{ .Values.backend.name }} + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.backend.name }} + component: backend +spec: + replicas: {{ .Values.backend.replicaCount }} + selector: + matchLabels: + app: {{ .Release.Name }}-{{ .Values.backend.name }} + template: + metadata: + labels: + app: {{ .Release.Name }}-{{ .Values.backend.name }} + component: backend + spec: + initContainers: + - name: wait-for-postgres + image: postgres:16-alpine + command: + - /bin/sh + - -c + - | + until pg_isready -h {{ .Release.Name }}-{{ .Values.postgres.name }}-headless -p {{ .Values.postgres.port }}; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + echo "PostgreSQL is ready!" + containers: + - name: {{ .Values.backend.name }} + image: "{{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag }}" + imagePullPolicy: {{ .Values.backend.image.pullPolicy }} + ports: + - containerPort: {{ .Values.backend.service.targetPort }} + name: http + protocol: TCP + env: + {{- if .Values.backend.env }} + {{- range $key, $value := .Values.backend.env }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + {{- end }} + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ .Release.Name }}-db-credentials + key: DATABASE_URL + startupProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 15 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 30 + livenessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + readinessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 10 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 2 + resources: + requests: + cpu: {{ .Values.backend.resources.requests.cpu }} + memory: {{ .Values.backend.resources.requests.memory }} + limits: + cpu: {{ .Values.backend.resources.limits.cpu }} + memory: {{ .Values.backend.resources.limits.memory }} diff --git a/charts/dateme-chart/templates/backend-service.yaml b/charts/dateme-chart/templates/backend-service.yaml new file mode 100644 index 0000000..02639c1 --- /dev/null +++ b/charts/dateme-chart/templates/backend-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-{{ .Values.backend.name }} + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.backend.name }} + component: backend +spec: + type: {{ .Values.backend.service.type }} + selector: + app: {{ .Release.Name }}-{{ .Values.backend.name }} + ports: + - name: http + port: {{ .Values.backend.service.port }} + targetPort: {{ .Values.backend.service.targetPort }} + protocol: TCP diff --git a/charts/dateme-chart/templates/backend.yaml b/charts/dateme-chart/templates/backend.yaml deleted file mode 100644 index 83bdb36..0000000 --- a/charts/dateme-chart/templates/backend.yaml +++ /dev/null @@ -1,99 +0,0 @@ ---- -# PVC for Backend media storage -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: backend-media-pvc - namespace: dating-app -spec: - accessModes: - - ReadWriteMany - {{- if .Values.backend.persistence.storageClass }} - storageClassName: {{ .Values.backend.persistence.storageClass }} - {{- end }} - resources: - requests: - storage: {{ .Values.backend.persistence.size }} - ---- -# Backend Deployment -apiVersion: apps/v1 -kind: Deployment -metadata: - name: backend - namespace: dating-app - labels: - app: backend -spec: - replicas: {{ .Values.backend.replicas }} - selector: - matchLabels: - app: backend - template: - metadata: - labels: - app: backend - spec: - initContainers: - - name: db-init - image: postgres:15-alpine - command: ['sh', '-c', 'until pg_isready -h postgres.dating-app.svc.cluster.local -p {{ .Values.postgres.service.port }}; do echo waiting for db; sleep 2; done;'] - containers: - - name: backend - image: {{ .Values.backend.image.repository }}:{{ .Values.backend.image.tag }} - imagePullPolicy: {{ .Values.backend.image.pullPolicy }} - ports: - - containerPort: {{ .Values.backend.service.targetPort }} - name: http - envFrom: - - configMapRef: - name: backend-config - resources: - requests: - memory: {{ .Values.backend.resources.requests.memory }} - cpu: {{ .Values.backend.resources.requests.cpu }} - limits: - memory: {{ .Values.backend.resources.limits.memory }} - cpu: {{ .Values.backend.resources.limits.cpu }} - volumeMounts: - - name: media-storage - mountPath: {{ .Values.backend.persistence.mountPath }} - {{- if .Values.backend.probes.readiness.enabled }} - readinessProbe: - httpGet: - path: {{ .Values.backend.probes.readiness.path }} - port: {{ .Values.backend.service.targetPort }} - initialDelaySeconds: {{ .Values.backend.probes.readiness.initialDelaySeconds }} - periodSeconds: {{ .Values.backend.probes.readiness.periodSeconds }} - {{- end }} - {{- if .Values.backend.probes.liveness.enabled }} - livenessProbe: - httpGet: - path: {{ .Values.backend.probes.liveness.path }} - port: {{ .Values.backend.service.targetPort }} - initialDelaySeconds: {{ .Values.backend.probes.liveness.initialDelaySeconds }} - periodSeconds: {{ .Values.backend.probes.liveness.periodSeconds }} - {{- end }} - volumes: - - name: media-storage - persistentVolumeClaim: - claimName: backend-media-pvc - ---- -# Backend Service -apiVersion: v1 -kind: Service -metadata: - name: backend - namespace: dating-app - labels: - app: backend -spec: - type: {{ .Values.backend.service.type }} - selector: - app: backend - ports: - - port: {{ .Values.backend.service.port }} - targetPort: {{ .Values.backend.service.targetPort }} - protocol: TCP - name: http diff --git a/charts/dateme-chart/templates/configmap.yaml b/charts/dateme-chart/templates/configmap.yaml deleted file mode 100644 index e25d4d4..0000000 --- a/charts/dateme-chart/templates/configmap.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -# ConfigMap for backend configuration -apiVersion: v1 -kind: ConfigMap -metadata: - name: backend-config - namespace: dating-app -data: - JWT_SECRET: {{ .Values.backend.environment.JWT_SECRET | quote }} - JWT_EXPIRES_MINUTES: {{ .Values.backend.environment.JWT_EXPIRES_MINUTES | quote }} - MEDIA_DIR: {{ .Values.backend.environment.MEDIA_DIR | quote }} - CORS_ORIGINS: {{ .Values.backend.environment.CORS_ORIGINS | quote }} - DATABASE_URL: "postgresql://{{ .Values.postgres.credentials.username }}:{{ .Values.postgres.credentials.password }}@postgres.dating-app.svc.cluster.local:{{ .Values.postgres.service.port }}/{{ .Values.postgres.credentials.database }}" - ---- -# ConfigMap for frontend configuration -apiVersion: v1 -kind: ConfigMap -metadata: - name: frontend-config - namespace: dating-app -data: - VITE_API_URL: {{ .Values.frontend.environment.VITE_API_URL | quote }} diff --git a/charts/dateme-chart/templates/db-schema-configmap.yaml b/charts/dateme-chart/templates/db-schema-configmap.yaml new file mode 100644 index 0000000..f6f9d39 --- /dev/null +++ b/charts/dateme-chart/templates/db-schema-configmap.yaml @@ -0,0 +1,23 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ .Release.Name }}-db-schema + namespace: {{ .Values.global.namespace }} +data: + schema.sql: | + -- Create users table + CREATE TABLE IF NOT EXISTS users ( + id SERIAL PRIMARY KEY, + username TEXT UNIQUE NOT NULL, + email TEXT UNIQUE NOT NULL, + password_hash TEXT NOT NULL, + first_name TEXT, + last_name TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); + + CREATE INDEX IF NOT EXISTS idx_users_username ON users (username); + CREATE INDEX IF NOT EXISTS idx_users_email ON users (email); + + -- Placeholder for dateme-specific tables + -- Add your application schema here diff --git a/charts/dateme-chart/templates/db-secret.yaml b/charts/dateme-chart/templates/db-secret.yaml new file mode 100644 index 0000000..a6336e5 --- /dev/null +++ b/charts/dateme-chart/templates/db-secret.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Release.Name }}-db-credentials + namespace: {{ .Values.global.namespace }} +type: Opaque +stringData: + DATABASE_URL: postgresql://{{ .Values.postgres.user }}:{{ .Values.postgres.password }}@{{ .Release.Name }}-{{ .Values.postgres.name }}-headless.{{ .Values.global.namespace }}.svc.cluster.local:{{ .Values.postgres.port }}/{{ .Values.postgres.database }} + DB_HOST: {{ printf "%s-%s-headless.%s.svc.cluster.local" .Release.Name .Values.postgres.name .Values.global.namespace }} + DB_PORT: "{{ .Values.postgres.port }}" + DB_NAME: {{ .Values.postgres.database | quote }} + DB_USER: {{ .Values.postgres.user | quote }} + DB_PASSWORD: {{ .Values.postgres.password | quote }} diff --git a/charts/dateme-chart/templates/db-service.yaml b/charts/dateme-chart/templates/db-service.yaml new file mode 100644 index 0000000..efa516d --- /dev/null +++ b/charts/dateme-chart/templates/db-service.yaml @@ -0,0 +1,35 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-{{ .Values.postgres.name }}-headless + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + component: database +spec: + clusterIP: None + selector: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + ports: + - name: postgres + port: {{ .Values.postgres.port }} + targetPort: {{ .Values.postgres.port }} + protocol: TCP +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-{{ .Values.postgres.name }} + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + component: database +spec: + type: {{ .Values.postgres.service.type }} + selector: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + ports: + - name: postgres + port: {{ .Values.postgres.service.port }} + targetPort: {{ .Values.postgres.port }} + protocol: TCP diff --git a/charts/dateme-chart/templates/db-statefulset.yaml b/charts/dateme-chart/templates/db-statefulset.yaml new file mode 100644 index 0000000..237a3d5 --- /dev/null +++ b/charts/dateme-chart/templates/db-statefulset.yaml @@ -0,0 +1,84 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ .Release.Name }}-{{ .Values.postgres.name }} + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + component: database +spec: + serviceName: {{ .Release.Name }}-{{ .Values.postgres.name }}-headless + replicas: 1 + selector: + matchLabels: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + template: + metadata: + labels: + app: {{ .Release.Name }}-{{ .Values.postgres.name }} + component: database + spec: + containers: + - name: postgres + image: "{{ .Values.postgres.image.repository }}:{{ .Values.postgres.image.tag }}" + imagePullPolicy: {{ .Values.postgres.image.pullPolicy }} + ports: + - containerPort: {{ .Values.postgres.port }} + name: postgres + protocol: TCP + env: + - name: POSTGRES_USER + value: {{ .Values.postgres.user | quote }} + - name: POSTGRES_PASSWORD + value: {{ .Values.postgres.password | quote }} + - name: POSTGRES_DB + value: {{ .Values.postgres.database | quote }} + - name: PGDATA + value: /var/lib/postgresql/data/pgdata + volumeMounts: + - name: data + mountPath: /var/lib/postgresql/data + - name: init-sql + mountPath: /docker-entrypoint-initdb.d + livenessProbe: + exec: + command: + - /bin/sh + - -c + - pg_isready -U {{ .Values.postgres.user }} + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + readinessProbe: + exec: + command: + - /bin/sh + - -c + - pg_isready -U {{ .Values.postgres.user }} + initialDelaySeconds: 10 + periodSeconds: 5 + timeoutSeconds: 2 + failureThreshold: 3 + resources: + requests: + cpu: {{ .Values.postgres.resources.requests.cpu }} + memory: {{ .Values.postgres.resources.requests.memory }} + limits: + cpu: {{ .Values.postgres.resources.limits.cpu }} + memory: {{ .Values.postgres.resources.limits.memory }} + volumes: + - name: init-sql + configMap: + name: {{ .Release.Name }}-db-schema + defaultMode: 0755 + volumeClaimTemplates: + - metadata: + name: data + spec: + accessModes: + - {{ .Values.postgres.persistence.accessMode }} + storageClassName: {{ .Values.postgres.persistence.storageClass }} + resources: + requests: + storage: {{ .Values.postgres.persistence.size }} diff --git a/charts/dateme-chart/templates/frontend-deployment.yaml b/charts/dateme-chart/templates/frontend-deployment.yaml new file mode 100644 index 0000000..8973e53 --- /dev/null +++ b/charts/dateme-chart/templates/frontend-deployment.yaml @@ -0,0 +1,57 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Release.Name }}-{{ .Values.frontend.name }} + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.frontend.name }} + component: frontend +spec: + replicas: {{ .Values.frontend.replicaCount }} + selector: + matchLabels: + app: {{ .Release.Name }}-{{ .Values.frontend.name }} + template: + metadata: + labels: + app: {{ .Release.Name }}-{{ .Values.frontend.name }} + component: frontend + spec: + containers: + - name: {{ .Values.frontend.name }} + image: "{{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }}" + imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} + ports: + - containerPort: {{ .Values.frontend.service.targetPort }} + name: http + protocol: TCP + {{- with .Values.frontend.env }} + env: + {{- range $key, $value := . }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + {{- end }} + livenessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 10 + periodSeconds: 10 + timeoutSeconds: 5 + failureThreshold: 3 + readinessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 5 + periodSeconds: 5 + timeoutSeconds: 3 + failureThreshold: 2 + resources: + requests: + cpu: {{ .Values.frontend.resources.requests.cpu }} + memory: {{ .Values.frontend.resources.requests.memory }} + limits: + cpu: {{ .Values.frontend.resources.limits.cpu }} + memory: {{ .Values.frontend.resources.limits.memory }} diff --git a/charts/dateme-chart/templates/frontend-service.yaml b/charts/dateme-chart/templates/frontend-service.yaml new file mode 100644 index 0000000..e466b97 --- /dev/null +++ b/charts/dateme-chart/templates/frontend-service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ .Release.Name }}-{{ .Values.frontend.name }} + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-{{ .Values.frontend.name }} + component: frontend +spec: + type: {{ .Values.frontend.service.type }} + selector: + app: {{ .Release.Name }}-{{ .Values.frontend.name }} + ports: + - name: http + port: {{ .Values.frontend.service.port }} + targetPort: {{ .Values.frontend.service.targetPort }} + protocol: TCP diff --git a/charts/dateme-chart/templates/frontend.yaml b/charts/dateme-chart/templates/frontend.yaml deleted file mode 100644 index 23d0910..0000000 --- a/charts/dateme-chart/templates/frontend.yaml +++ /dev/null @@ -1,71 +0,0 @@ ---- -# Frontend Deployment -apiVersion: apps/v1 -kind: Deployment -metadata: - name: frontend - namespace: dating-app - labels: - app: frontend -spec: - replicas: {{ .Values.frontend.replicas }} - selector: - matchLabels: - app: frontend - template: - metadata: - labels: - app: frontend - spec: - containers: - - name: frontend - image: {{ .Values.frontend.image.repository }}:{{ .Values.frontend.image.tag }} - imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} - ports: - - containerPort: {{ .Values.frontend.service.targetPort }} - name: http - envFrom: - - configMapRef: - name: frontend-config - resources: - requests: - memory: {{ .Values.frontend.resources.requests.memory }} - cpu: {{ .Values.frontend.resources.requests.cpu }} - limits: - memory: {{ .Values.frontend.resources.limits.memory }} - cpu: {{ .Values.frontend.resources.limits.cpu }} - {{- if .Values.frontend.probes.readiness.enabled }} - readinessProbe: - httpGet: - path: {{ .Values.frontend.probes.readiness.path }} - port: {{ .Values.frontend.service.targetPort }} - initialDelaySeconds: {{ .Values.frontend.probes.readiness.initialDelaySeconds }} - periodSeconds: {{ .Values.frontend.probes.readiness.periodSeconds }} - {{- end }} - {{- if .Values.frontend.probes.liveness.enabled }} - livenessProbe: - httpGet: - path: {{ .Values.frontend.probes.liveness.path }} - port: {{ .Values.frontend.service.targetPort }} - initialDelaySeconds: {{ .Values.frontend.probes.liveness.initialDelaySeconds }} - periodSeconds: {{ .Values.frontend.probes.liveness.periodSeconds }} - {{- end }} - ---- -# Frontend Service -apiVersion: v1 -kind: Service -metadata: - name: frontend - namespace: dating-app - labels: - app: frontend -spec: - type: {{ .Values.frontend.service.type }} - selector: - app: frontend - ports: - - port: {{ .Values.frontend.service.port }} - targetPort: {{ .Values.frontend.service.targetPort }} - protocol: TCP - name: http diff --git a/charts/dateme-chart/templates/ingress.yaml b/charts/dateme-chart/templates/ingress.yaml index 3c68a6b..d106c59 100644 --- a/charts/dateme-chart/templates/ingress.yaml +++ b/charts/dateme-chart/templates/ingress.yaml @@ -1,51 +1,89 @@ -{{- if .Values.ingress.enabled }} ---- -# Ingress for Backend API +{{- if .Values.frontend.ingress.enabled }} apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: backend-ingress - namespace: dating-app + name: {{ .Release.Name }}-frontend + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-frontend + component: frontend + {{- with .Values.frontend.ingress.annotations }} annotations: - {{- range $key, $value := .Values.ingress.annotations }} - {{ $key }}: {{ $value | quote }} - {{- end }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: - ingressClassName: {{ .Values.ingress.className }} + {{- if .Values.frontend.ingress.className }} + ingressClassName: {{ .Values.frontend.ingress.className }} + {{- end }} rules: - - host: {{ .Values.backend.ingress.host }} - http: - paths: - - path: {{ .Values.backend.ingress.path }} - pathType: {{ .Values.backend.ingress.pathType }} - backend: - service: - name: backend - port: - number: {{ .Values.backend.service.port }} + {{- range .Values.frontend.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ $.Release.Name }}-{{ $.Values.frontend.name }} + port: + number: {{ $.Values.frontend.service.port }} + {{- end }} + {{- end }} + {{- if .Values.frontend.ingress.tls }} + tls: + {{- range .Values.frontend.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} +{{- end }} --- -# Ingress for Frontend + +{{- if .Values.backend.ingress.enabled }} apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: frontend-ingress - namespace: dating-app + name: {{ .Release.Name }}-backend + namespace: {{ .Values.global.namespace }} + labels: + app: {{ .Release.Name }}-backend + component: backend + {{- with .Values.backend.ingress.annotations }} annotations: - {{- range $key, $value := .Values.ingress.annotations }} - {{ $key }}: {{ $value | quote }} - {{- end }} + {{- toYaml . | nindent 4 }} + {{- end }} spec: - ingressClassName: {{ .Values.ingress.className }} + {{- if .Values.backend.ingress.className }} + ingressClassName: {{ .Values.backend.ingress.className }} + {{- end }} rules: - - host: {{ .Values.frontend.ingress.host }} - http: - paths: - - path: {{ .Values.frontend.ingress.path }} - pathType: {{ .Values.frontend.ingress.pathType }} - backend: - service: - name: frontend - port: - number: {{ .Values.frontend.service.port }} + {{- range .Values.backend.ingress.hosts }} + - host: {{ .host | quote }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ .pathType }} + backend: + service: + name: {{ $.Release.Name }}-{{ $.Values.backend.name }} + port: + number: {{ $.Values.backend.service.port }} + {{- end }} + {{- end }} + {{- if .Values.backend.ingress.tls }} + tls: + {{- range .Values.backend.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ .secretName }} + {{- end }} + {{- end }} {{- end }} diff --git a/charts/dateme-chart/templates/namespace.yaml b/charts/dateme-chart/templates/namespace.yaml deleted file mode 100644 index ab53699..0000000 --- a/charts/dateme-chart/templates/namespace.yaml +++ /dev/null @@ -1,6 +0,0 @@ ---- -# Namespace -apiVersion: v1 -kind: Namespace -metadata: - name: dating-app diff --git a/charts/dateme-chart/templates/postgres-init.yaml b/charts/dateme-chart/templates/postgres-init.yaml deleted file mode 100644 index 3026e6b..0000000 --- a/charts/dateme-chart/templates/postgres-init.yaml +++ /dev/null @@ -1,105 +0,0 @@ -{{- if .Values.postgres.enabled }} ---- -# ConfigMap for PostgreSQL initialization scripts -apiVersion: v1 -kind: ConfigMap -metadata: - name: postgres-init-scripts - namespace: dating-app -data: - 01-init-db.sh: | - #!/bin/bash - set -e - - # Create the application user if it doesn't exist - psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL - -- Create application user if not exists - DO \$do\$ BEGIN - CREATE ROLE {{ .Values.postgres.credentials.username }} WITH LOGIN PASSWORD '{{ .Values.postgres.credentials.password }}'; - EXCEPTION WHEN DUPLICATE_OBJECT THEN - RAISE NOTICE 'Role {{ .Values.postgres.credentials.username }} already exists'; - END - \$do\$; - - -- Grant privileges - GRANT ALL PRIVILEGES ON DATABASE {{ .Values.postgres.credentials.database }} TO {{ .Values.postgres.credentials.username }}; - GRANT ALL PRIVILEGES ON SCHEMA public TO {{ .Values.postgres.credentials.username }}; - ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO {{ .Values.postgres.credentials.username }}; - ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO {{ .Values.postgres.credentials.username }}; - EOSQL - - 02-create-tables.sql: | - -- Create tables for dating app - CREATE TABLE IF NOT EXISTS users ( - id SERIAL PRIMARY KEY, - email VARCHAR(255) UNIQUE NOT NULL, - hashed_password VARCHAR(255) NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ); - - CREATE TABLE IF NOT EXISTS profiles ( - id SERIAL PRIMARY KEY, - user_id INTEGER NOT NULL UNIQUE, - display_name VARCHAR(255) NOT NULL, - age INTEGER NOT NULL, - gender VARCHAR(50) NOT NULL, - location VARCHAR(255) NOT NULL, - bio TEXT, - interests JSONB DEFAULT '[]', - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE - ); - - CREATE TABLE IF NOT EXISTS photos ( - id SERIAL PRIMARY KEY, - profile_id INTEGER NOT NULL, - file_path VARCHAR(255) NOT NULL, - display_order INTEGER NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (profile_id) REFERENCES profiles(id) ON DELETE CASCADE - ); - - CREATE TABLE IF NOT EXISTS likes ( - id SERIAL PRIMARY KEY, - liker_id INTEGER NOT NULL, - liked_id INTEGER NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - UNIQUE(liker_id, liked_id), - FOREIGN KEY (liker_id) REFERENCES users(id) ON DELETE CASCADE, - FOREIGN KEY (liked_id) REFERENCES users(id) ON DELETE CASCADE - ); - - CREATE TABLE IF NOT EXISTS conversations ( - id SERIAL PRIMARY KEY, - user_id_1 INTEGER NOT NULL, - user_id_2 INTEGER NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - UNIQUE(user_id_1, user_id_2), - FOREIGN KEY (user_id_1) REFERENCES users(id) ON DELETE CASCADE, - FOREIGN KEY (user_id_2) REFERENCES users(id) ON DELETE CASCADE - ); - - CREATE TABLE IF NOT EXISTS messages ( - id SERIAL PRIMARY KEY, - conversation_id INTEGER NOT NULL, - sender_id INTEGER NOT NULL, - content TEXT NOT NULL, - created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - FOREIGN KEY (conversation_id) REFERENCES conversations(id) ON DELETE CASCADE, - FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE - ); - - -- Create indexes for performance - CREATE INDEX IF NOT EXISTS idx_users_email ON users(email); - CREATE INDEX IF NOT EXISTS idx_profiles_user_id ON profiles(user_id); - CREATE INDEX IF NOT EXISTS idx_photos_profile_id ON photos(profile_id); - CREATE INDEX IF NOT EXISTS idx_likes_liker_id ON likes(liker_id); - CREATE INDEX IF NOT EXISTS idx_likes_liked_id ON likes(liked_id); - CREATE INDEX IF NOT EXISTS idx_conversations_users ON conversations(user_id_1, user_id_2); - CREATE INDEX IF NOT EXISTS idx_messages_conversation_id ON messages(conversation_id); - CREATE INDEX IF NOT EXISTS idx_messages_created_at ON messages(created_at); - -{{- end }} diff --git a/charts/dateme-chart/templates/postgres.yaml b/charts/dateme-chart/templates/postgres.yaml deleted file mode 100644 index ab62ede..0000000 --- a/charts/dateme-chart/templates/postgres.yaml +++ /dev/null @@ -1,127 +0,0 @@ -{{- if .Values.postgres.enabled }} ---- -# Headless Service for StatefulSet -apiVersion: v1 -kind: Service -metadata: - name: postgres - namespace: dating-app - labels: - app: postgres -spec: - ports: - - port: {{ .Values.postgres.service.port }} - targetPort: {{ .Values.postgres.service.port }} - name: postgres - clusterIP: None # Headless service for StatefulSet - selector: - app: postgres - ---- -# PostgreSQL StatefulSet -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: postgres - namespace: dating-app - labels: - app: postgres -spec: - serviceName: postgres - replicas: {{ .Values.postgres.replicas }} - selector: - matchLabels: - app: postgres - template: - metadata: - labels: - app: postgres - spec: - securityContext: - fsGroup: 999 - containers: - - name: postgres - image: {{ .Values.postgres.image }} - imagePullPolicy: IfNotPresent - ports: - - containerPort: {{ .Values.postgres.service.port }} - name: postgres - env: - - name: POSTGRES_USER - valueFrom: - secretKeyRef: - name: postgres-credentials - key: username - - name: POSTGRES_PASSWORD - valueFrom: - secretKeyRef: - name: postgres-credentials - key: password - - name: POSTGRES_DB - valueFrom: - secretKeyRef: - name: postgres-credentials - key: database - - name: PGDATA - value: /var/lib/postgresql/data/pgdata - resources: - requests: - memory: {{ .Values.postgres.resources.requests.memory }} - cpu: {{ .Values.postgres.resources.requests.cpu }} - limits: - memory: {{ .Values.postgres.resources.limits.memory }} - cpu: {{ .Values.postgres.resources.limits.cpu }} - volumeMounts: - - name: postgres-storage - mountPath: /var/lib/postgresql/data - - name: init-scripts - mountPath: /docker-entrypoint-initdb.d - livenessProbe: - exec: - command: - - /bin/sh - - -c - - pg_isready -U $POSTGRES_USER - initialDelaySeconds: 30 - periodSeconds: 10 - timeoutSeconds: 5 - failureThreshold: 3 - readinessProbe: - exec: - command: - - /bin/sh - - -c - - pg_isready -U $POSTGRES_USER - initialDelaySeconds: 10 - periodSeconds: 5 - timeoutSeconds: 2 - failureThreshold: 3 - volumes: - - name: init-scripts - configMap: - name: postgres-init-scripts - defaultMode: 0755 - volumeClaimTemplates: - - metadata: - name: postgres-storage - spec: - accessModes: - - ReadWriteOnce - {{- if .Values.postgres.persistence.storageClass }} - storageClassName: {{ .Values.postgres.persistence.storageClass }} - {{- end }} - resources: - requests: - storage: {{ .Values.postgres.persistence.size }} - -{{- end }} -spec: - type: {{ .Values.postgres.service.type | default "ClusterIP" }} - selector: - app: postgres - ports: - - port: {{ .Values.postgres.service.port }} - targetPort: {{ .Values.postgres.service.port }} - protocol: TCP - name: postgres -{{- end }} diff --git a/charts/dateme-chart/templates/secret.yaml b/charts/dateme-chart/templates/secret.yaml deleted file mode 100644 index 7b74bcc..0000000 --- a/charts/dateme-chart/templates/secret.yaml +++ /dev/null @@ -1,12 +0,0 @@ ---- -# Secret for PostgreSQL credentials -apiVersion: v1 -kind: Secret -metadata: - name: postgres-credentials - namespace: dating-app -type: Opaque -data: - username: {{ .Values.postgres.credentials.username | b64enc }} - password: {{ .Values.postgres.credentials.password | b64enc }} - database: {{ .Values.postgres.credentials.database | b64enc }} diff --git a/charts/dateme-chart/values.yaml b/charts/dateme-chart/values.yaml index f0d703a..a192b93 100644 --- a/charts/dateme-chart/values.yaml +++ b/charts/dateme-chart/values.yaml @@ -1,127 +1,125 @@ -# Default values for dating-app Helm chart - -# Global settings +# Default values for dateme-chart global: - domain: example.com - -# PostgreSQL configuration -postgres: - enabled: true - image: postgres:15-alpine - replicas: 1 - resources: - requests: - memory: "256Mi" - cpu: "100m" - limits: - memory: "512Mi" - cpu: "500m" - persistence: - enabled: true - size: 10Gi - storageClass: "" - credentials: - username: dating_app_user - password: Aa123456 - database: dating_app - service: - port: 5432 + namespace: my-apps + imagePullSecrets: [] # Backend configuration backend: + name: backend + replicaCount: 1 image: - repository: dating-app-backend - tag: latest - pullPolicy: IfNotPresent - replicas: 2 - resources: - requests: - memory: "256Mi" - cpu: "100m" - limits: - memory: "512Mi" - cpu: "500m" + repository: harbor.dvirlabs.com/my-apps/dateme-backend + pullPolicy: Always + tag: develop-latest service: + type: ClusterIP port: 8000 targetPort: 8000 - type: ClusterIP + resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 500m + memory: 512Mi + env: + PYTHONUNBUFFERED: "1" ingress: enabled: true - className: nginx - host: api-dateme.dvirlabs.com - path: / - pathType: Prefix - environment: - JWT_SECRET: your-secret-key-change-in-production - JWT_EXPIRES_MINUTES: "1440" - MEDIA_DIR: /app/media - CORS_ORIGINS: "http://localhost:5173,http://localhost:3000,http://localhost,https://dateme.dvirlabs.com" - persistence: - enabled: true - size: 5Gi - storageClass: "" - mountPath: /app/media - probes: - readiness: - enabled: true - path: /health - initialDelaySeconds: 10 - periodSeconds: 10 - liveness: - enabled: true - path: /health - initialDelaySeconds: 30 - periodSeconds: 30 + className: "traefik" + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure + traefik.ingress.kubernetes.io/router.tls: "true" + cert-manager.io/cluster-issuer: "letsencrypt-prod" + hosts: + - host: api-dateme.dvirlabs.com + paths: + - path: / + pathType: Prefix + tls: + - secretName: api-dateme-tls + hosts: + - api-dateme.dvirlabs.com # Frontend configuration frontend: + name: frontend + replicaCount: 1 image: - repository: dating-app-frontend - tag: latest - pullPolicy: IfNotPresent - replicas: 2 - resources: - requests: - memory: "128Mi" - cpu: "50m" - limits: - memory: "256Mi" - cpu: "200m" + repository: harbor.dvirlabs.com/my-apps/dateme-frontend + pullPolicy: Always + tag: develop-latest service: + type: ClusterIP port: 80 targetPort: 80 - type: ClusterIP + env: + API_BASE: "https://api-dateme.dvirlabs.com" + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 200m + memory: 256Mi ingress: enabled: true - className: nginx - host: dateme.dvirlabs.com - path: / - pathType: Prefix - environment: - VITE_API_URL: "https://api-dateme.dvirlabs.com" - probes: - readiness: - enabled: true - path: /health - initialDelaySeconds: 5 - periodSeconds: 10 - liveness: - enabled: true - path: /health - initialDelaySeconds: 15 - periodSeconds: 30 + className: "traefik" + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure + traefik.ingress.kubernetes.io/router.tls: "true" + cert-manager.io/cluster-issuer: "letsencrypt-prod" + hosts: + - host: dateme.dvirlabs.com + paths: + - path: / + pathType: Prefix + tls: + - secretName: dateme-tls + hosts: + - dateme.dvirlabs.com + externalUrl: "https://dateme.dvirlabs.com" -# Ingress configuration +# PostgreSQL configuration +postgres: + name: db + image: + repository: postgres + tag: "16" + pullPolicy: IfNotPresent + user: dateme_user + password: dateme_password + database: dateme_db + port: 5432 + service: + type: ClusterIP + port: 5432 + targetPort: 5432 + persistence: + enabled: true + accessMode: ReadWriteOnce + storageClass: "nfs-client" + size: 10Gi + resources: + requests: + cpu: 100m + memory: 256Mi + limits: + cpu: 500m + memory: 512Mi + +# Ingress (top-level, disabled - use component-specific ingress instead) ingress: - enabled: true - className: nginx + enabled: false + className: "traefik" annotations: cert-manager.io/cluster-issuer: "letsencrypt-prod" - -# ConfigMap for shared configuration -configmap: - enabled: true - -# Secret for sensitive data (use external secrets in production) -secrets: - enabled: true + hosts: + - host: dateme.dvirlabs.com + paths: + - path: / + pathType: Prefix + tls: + - secretName: dateme-tls + hosts: + - dateme.dvirlabs.com