# =============================================================================
# WOOO TECH - Momo Pro System
# GCP Main Application Deployment
# 特點: 使用本地映像，不需要 Registry Pull
# =============================================================================
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: momo-data-pvc
  namespace: momo
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
  storageClassName: local-path
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: momo-app
  namespace: momo
  labels:
    app: momo-app
    env: production
spec:
  replicas: 1
  selector:
    matchLabels:
      app: momo-app
  template:
    metadata:
      labels:
        app: momo-app
    spec:
      # GCP 使用本地映像，不需要 initContainer 複製認證
      # 如需 Google Drive 功能，請另外配置
      containers:
        - name: momo-app
          # 使用本地構建的映像
          image: docker.io/library/momo-pro-system:latest
          # 關鍵: 設為 Never，使用本地映像
          imagePullPolicy: Never
          ports:
            - containerPort: 80
          envFrom:
            - configMapRef:
                name: momo-config
          env:
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: SECRET_KEY
            - name: LOGIN_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: LOGIN_PASSWORD
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: DATABASE_URL
            - name: POSTGRES_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: POSTGRES_PASSWORD
            - name: TELEGRAM_BOT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: TELEGRAM_BOT_TOKEN
            - name: LINE_CHANNEL_ACCESS_TOKEN
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: LINE_CHANNEL_ACCESS_TOKEN
            - name: GEMINI_API_KEY
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: GEMINI_API_KEY
          volumeMounts:
            - name: momo-data
              mountPath: /app/data
            - name: momo-logs
              mountPath: /app/logs
          resources:
            requests:
              memory: "1Gi"
              cpu: "200m"
            limits:
              memory: "4Gi"
              cpu: "2000m"
          livenessProbe:
            httpGet:
              path: /health
              port: 80
            initialDelaySeconds: 60
            periodSeconds: 30
            timeoutSeconds: 10
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /health
              port: 80
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
      volumes:
        - name: momo-data
          persistentVolumeClaim:
            claimName: momo-data-pvc
        - name: momo-logs
          emptyDir: {}
      # GCP 使用本地映像，不需要 imagePullSecrets
---
apiVersion: v1
kind: Service
metadata:
  name: momo-app
  namespace: momo
spec:
  selector:
    app: momo-app
  ports:
    - port: 80
      targetPort: 80
  type: ClusterIP
