apiVersion: apps/v1
kind: Deployment
metadata:
  name: rtc-backend
  labels:
    app: rtc-backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: rtc-backend
  template:
    metadata:
      labels:
        app: rtc-backend
    spec:
      containers:
      - name: rtc-backend
        image: ${CI_REGISTRY_IMAGE}/backend:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
        env:
        # Database
        - name: DB_HOST
          value: "rm-7xv1uaw910558p1788o.mysql.rds.aliyuncs.com"
        - name: DB_NAME
          value: "rtc"
        - name: DB_USER
          value: "rtc"
        - name: DB_PASSWORD
          value: "JogNQdtrd3WY8CBCAiYfYEGx"
        - name: DB_PORT
          value: "3306"

        # Redis
        - name: REDIS_URL
          value: "redis://:vAhRnAA6VMco@r-7xvat0vez5clwbzk5vpd.redis.rds.aliyuncs.com:6379/8"

        # Aliyun OSS
        - name: OSS_ACCESS_KEY_ID
          value: "LTAI5tBGAkR2rra2prTAX9yc"
        - name: OSS_ACCESS_KEY_SECRET
          value: "U1z3d0p5saPRD5sCxVooJYSjxSAmKB"
        - name: OSS_BUCKET_NAME
          value: "qy-rtc"
        - name: OSS_ENDPOINT
          value: "oss-cn-beijing.aliyuncs.com"
        - name: OSS_CUSTOM_DOMAIN
          value: ""

        # Aliyun Log (If used by app)
        - name: ALIYUN_LOG_PROJECT
          value: "toy"
        - name: ALIYUN_LOG_STORE
          value: "rtc"
        - name: ALIYUN_LOG_ENDPOINT
          value: "cn-guangzhou.log.aliyuncs.com"
        - name: ALIYUN_LOG_ACCESS_KEY_ID
          value: "LTAI5tBGAkR2rra2prTAX9yc"
        - name: ALIYUN_LOG_ACCESS_KEY_SECRET
          value: "U1z3d0p5saPRD5sCxVooJYSjxSAmKB"
          
        # Security & CORS
        - name: DJANGO_ALLOWED_HOSTS
          value: "*"
        - name: CORS_ALLOWED_ORIGINS
          value: "https://qiyuan-rtc-web.airlabs.art,https://qiyuan-rtc-dev-web.airlabs.art"
        - name: CSRF_TRUSTED_ORIGINS
          value: "https://qiyuan-rtc-web.airlabs.art,https://qiyuan-rtc-dev-web.airlabs.art,https://qiyuan-rtc-api.airlabs.art"

        # Log Center
        - name: ENVIRONMENT
          value: "production"
        - name: LOG_CENTER_URL
          value: "https://qiyuan-log-center-api.airlabs.art"
        - name: LOG_CENTER_ENABLED
          value: "true"
        livenessProbe:
          httpGet:
            path: /healthz/
            port: 8000
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /healthz/
            port: 8000
          initialDelaySeconds: 15
          periodSeconds: 5
          timeoutSeconds: 3
          failureThreshold: 3
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "1024Mi"
            cpu: "1000m"
---
apiVersion: v1
kind: Service
metadata:
  name: rtc-backend
spec:
  selector:
    app: rtc-backend
  ports:
    - protocol: TCP
      port: 8000
      targetPort: 8000
