apiVersion: apps/v1
kind: Deployment
metadata:
  name: tiro-tts-deployment
  labels:
    app: tiro-tts
spec:
  replicas: 3
  selector:
    matchLabels:
      app: tiro-tts
  template:
    metadata:
      labels:
        app: tiro-tts
    spec:
      volumes:
      - name: models
        emptyDir: {}
      - name: gcs-creds
        secret:
          secretName: gcs-read-service-account-secret
      initContainers:
      - name: fetch-models
        image: google/cloud-sdk:latest
        command:
        - bash
        - -xeu
        - -c
        - |
          mkdir -p /models/
          gcloud auth activate-service-account --key-file=/creds/keyfile.json

          ALFUR_FASTSPEECH=gs://models-talgreinir-is/tts/fastspeech2/v2021-01-01/checkpoint_490000_jit_quant_fbgemm_v2.pt
          ALFUR_MELGAN=gs://models-talgreinir-is/tts/fastspeech2/v2021-01-01/vocoder_aca5990_3350_jit_v2.pt

          DILJA_FASTSPEECH=gs://models-talgreinir-is/tts/fastspeech2/dilja/v2021-07-26/checkpoint_380000_jit_quant_fbgemm_v2.pt
          DILJA_MELGAN=gs://models-talgreinir-is/tts/fastspeech2/dilja/v2021-07-26/dilja_aca5990_4550_jit_v2.pt

          SEQUITUR=gs://models-talgreinir-is/g2p/is-IS.ipd_clean_slt2018.mdl

          LEXICON=gs://models-talgreinir-is/g2p/iceprondict/version_21.06/ice_pron_dict_standard_clear.csv#1624979739994321

          SEQUITUR_FAIL_EN=gs://models-talgreinir-is/g2p/en-IS.cmudict_frobv1.20200305.mdl

          gsutil cp $ALFUR_FASTSPEECH /models/alfur/fastspeech_jit.pt
          gsutil cp $ALFUR_MELGAN /models/alfur/melgan_jit.pt

          gsutil cp $DILJA_FASTSPEECH /models/dilja/fastspeech_jit.pt
          gsutil cp $DILJA_MELGAN /models/dilja/melgan_jit.pt

          gsutil cp $SEQUITUR /models/sequitur.mdl
          gsutil cp $LEXICON /models/lexicon.txt
          gsutil cp $SEQUITUR_FAIL_EN /models/sequitur_fail_en.mdl

          exit 0
        volumeMounts:
        - name: models
          mountPath: /models
          readOnly: false
        - name: gcs-creds
          mountPath: /creds
          readOnly: true
      containers:
      - name: tts-frontend-service
        image: eu.gcr.io/talgreining-is/tts-frontend-service:git05add43
        ports:
        - containerPort: 8080
          protocol: TCP
      - name: tiro-tts
        image: tiro-tts
        imagePullPolicy: Always
        ports:
        - containerPort: 8000
          protocol: TCP
        volumeMounts:
        - name: models
          mountPath: /models
          readOnly: true
        resources:
          requests:
            memory: "2000Mi"
            cpu: "1000m"
        env:
        - name: TIRO_TTS_AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: dev-aws-secret
              key: aws_access_key_id
        - name: TIRO_TTS_AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: dev-aws-secret
              key: aws_secret_access_key
        - name: TIRO_TTS_SYNTHESIS_SET_PB
          value: conf/synthesis_set.pbtxt
