apiVersion: apps/v1
kind: Deployment
metadata:
  name: video-backend
  labels:
    app: video-backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: video-backend
  template:
    metadata:
      labels:
        app: video-backend
    spec:
      imagePullSecrets:
      - name: swr-secret
      containers:
      - name: video-backend
        image: ${CI_REGISTRY_IMAGE}/video-backend:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
        env:
        - name: USE_MYSQL
          value: "true"
        - name: DJANGO_DEBUG
          value: "False"
        - name: DJANGO_ALLOWED_HOSTS
          value: "*"
        - name: DJANGO_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: DJANGO_SECRET_KEY
        # Database (Aliyun RDS)
        - name: DB_HOST
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: DB_HOST
        - name: DB_NAME
          value: "video_auto"
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: DB_USER
        - name: DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: DB_PASSWORD
        - name: DB_PORT
          value: "3306"
        # CORS
        - name: CORS_ALLOWED_ORIGINS
          value: "https://airflow-studio.airlabs.art"
        # Log Center
        - name: LOG_CENTER_URL
          value: "https://qiyuan-log-center-api.airlabs.art"
        - name: LOG_CENTER_ENABLED
          value: "true"
        - name: ENVIRONMENT
          value: "production"
        # TOS (from Secret)
        - name: TOS_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: TOS_ACCESS_KEY
        - name: TOS_SECRET_KEY
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: TOS_SECRET_KEY
        - name: TOS_BUCKET
          value: "airdrama-media"
        - name: TOS_ENDPOINT
          value: "https://tos-cn-beijing.volces.com"
        - name: TOS_REGION
          value: "cn-beijing"
        - name: TOS_CDN_DOMAIN
          value: "https://airdrama-media.tos-cn-beijing.volces.com"
        # Seedance API (from Secret)
        - name: ARK_API_KEY
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: ARK_API_KEY
        - name: SEEDANCE_ENABLED
          value: "true"
        # Aliyun SMS
        - name: ALIYUN_SMS_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: ALIYUN_SMS_ACCESS_KEY
        - name: ALIYUN_SMS_ACCESS_SECRET
          valueFrom:
            secretKeyRef:
              name: video-backend-secrets
              key: ALIYUN_SMS_ACCESS_SECRET
        - name: ALIYUN_SMS_SIGN_NAME
          value: "广州气元科技"
        - name: ALIYUN_SMS_TEMPLATE_CODE
          value: "SMS_503445109"
        livenessProbe:
          httpGet:
            path: /healthz/
            port: 8000
            httpHeaders:
            - name: Host
              value: localhost
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          failureThreshold: 3
        readinessProbe:
          httpGet:
            path: /healthz/
            port: 8000
            httpHeaders:
            - name: Host
              value: localhost
          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: video-backend
spec:
  selector:
    app: video-backend
  ports:
    - protocol: TCP
      port: 8000
      targetPort: 8000
