apiVersion: apps/v1
kind: Deployment
metadata:
  name: composer-demucs
  labels:
    app: composer-demucs
spec:
  replicas: 1
  selector:
    matchLabels:
      app: composer-demucs
  template:
    metadata:
      labels:
        app: composer-demucs
    spec:
      serviceAccountName: composer-service-account
      terminationGracePeriodSeconds: 130
      nodeSelector:
        karpenter.k8s.aws/instance-family: g4dn
      containers:
      - name: composer
        image: 035363416972.dkr.ecr.us-east-1.amazonaws.com/minimal:latest
        command: [ "/opt/entrypoint.sh" ]
        env:
        - name: QUEUE_NAME
          value: composer_requests
        - name: MAX_RUNTIME
          value: "5000"
        - name: HEALTHCHECK_PATH
          value: "/composer_ready"
        - name: REDIS_HOST
          value: "prod-redis.redis.svc.cluster.local"
        - name: REDIS_PORT
          value: "26379"
        - name: REDIS_SENTINEL_NAME
          value: "wavtoolmaster"
        envFrom:
        - secretRef:
            name: redis-secret
        resources:
          limits:
            nvidia.com/gpu: 1
        readinessProbe:
          exec:
            command:
              - cat
              - /composer_ready
          periodSeconds: 5
          failureThreshold: 10
        volumeMounts:
        - name: persistent-storage
          mountPath: /opt
          subPath: composer_production_2024-05-05
        - name: memory-backed-temp
          mountPath: /tmp
          subPath: composer
        lifecycle:
          preStop:
            exec:
              command: [ "/bin/sleep", "120" ]
      - name: demucs
        image: 035363416972.dkr.ecr.us-east-1.amazonaws.com/minimal:latest
        command: [ "/opt/entrypoint.sh" ]
        env:
        - name: QUEUE_NAME
          value: "demucs_requests_beta_2"
        - name: MAX_RUNTIME
          value: "120000"
        - name: HEALTHCHECK_PATH
          value: "/demucs_ready"
        - name: REDIS_HOST
          value: "prod-redis.redis.svc.cluster.local"
        - name: REDIS_PORT
          value: "26379"
        - name: REDIS_SENTINEL_NAME
          value: "wavtoolmaster"
        - name: DEMUCS_S3_BUCKET
          value: "samples-test-1"
        - name: DEMUCS_MODEL
          value: "htdemucs"
        # XXX this is an awful hack that will break if we ever use a node with more than one gpu
        # XXX fix this once karpenter supports fractional or shared resources
        - name: NVIDIA_VISIBLE_DEVICES
          value: "all"
        envFrom:
        - secretRef:
            name: redis-secret
        readinessProbe:
          exec:
            command:
              - cat
              - /demucs_ready
          periodSeconds: 5
          failureThreshold: 10
        volumeMounts:
        - name: persistent-storage
          mountPath: /opt
          subPath: demucs_2024-05-16
        - name: memory-backed-temp
          mountPath: /tmp
          subPath: demucs
        lifecycle:
          preStop:
            exec:
              command: [ "/bin/sleep", "120" ]
      volumes:
      - name: persistent-storage
        persistentVolumeClaim:
          claimName: efs-claim
      - name: memory-backed-temp
        emptyDir:
          medium: Memory
          sizeLimit: 4Gi
