apiVersion: apps/v1
kind: Deployment
metadata:
  name: sources-twilio-webhook
  namespace: default
  labels:
    app: sources-twilio-webhook
    type: sources-twilio
spec:
  replicas: 0
  selector:
    matchLabels:
      app: sources-twilio-webhook
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: sources-twilio-webhook
    spec:
      containers:
        - name: app
          image: "{{ .Values.global.containerRegistry}}/{{ .Values.image }}:{{ .Values.global.appImageTag }}"
          imagePullPolicy: Always
          env:
            - name: KAFKA_BROKERS
              valueFrom:
                configMapKeyRef:
                  name: kafka-config
                  key: KAFKA_BROKERS
            - name: KAFKA_SCHEMA_REGISTRY_URL
              valueFrom:
                configMapKeyRef:
                  name: kafka-config
                  key: KAFKA_SCHEMA_REGISTRY_URL
            - name: SERVICE_NAME
              value: sources-twilio-webhook
            - name: TWILIO_AUTH_TOKEN
              valueFrom:
                configMapKeyRef:
                  name: sources-config
                  key: TWILIO_AUTH_TOKEN
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 8080
              httpHeaders:
                - name: Health-Check
                  value: health-check
            initialDelaySeconds: 60
            periodSeconds: 10
            failureThreshold: 3

        - name: ngrok
          command:
            - /bin/bash
            - -c
            - /usr/local/bin/ngrok -config=/etc/ngrok/config.yml -log=stdout -subdomain="$WEBHOOK_SUBDOMAIN" 8080
          image: ghcr.io/airyhq/infrastructure/ngrok-client:latest
          env:
            - name: WEBHOOK_SUBDOMAIN
              valueFrom:
                configMapKeyRef:
                  name: sources-config
                  key: TWILIO_WEBHOOK_PUBLIC_URL
          imagePullPolicy: Always
          resources:
            limits:
              cpu: 50m
              memory: 64Mi
          volumeMounts:
            - mountPath: /etc/ngrok
              name: ngrok-client-config
      volumes:
        - name: ngrok-client-config
          configMap:
            name: ngrok-client-config
