apiVersion: v1
kind: Service
metadata:
  labels:
    app: bigtable-emulator
  name: bigtable-emulator
spec:
  ports:
  - name: clients
    port: 8086
    targetPort: clients
    protocol: TCP
  selector:
    app: bigtable-emulator
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: bigtable-emulator
  name: bigtable-emulator
spec:
  serviceName: bigtable-emulator
  replicas: 1
  selector:
    matchLabels:
      app: bigtable-emulator
  template:
    metadata:
      labels:
        app: bigtable-emulator
    spec:
      containers:
        - name: bigtable-emulator
          image: google/cloud-sdk:353.0.0-alpine@sha256:594278737ce111f7922afa8722b4b526c19938e74b9ab931d23c4d2755802d3a
          env:
            - name: BIGTABLE_EMULATOR_HOST
              value: localhost:8086
          command:
            - /bin/sh
            - -c
            - |
              echo project = local-dev > ~/.cbtrc
              echo instance = wormhole >> ~/.cbtrc
              gcloud --quiet components install beta cbt bigtable
              gcloud --quiet beta emulators bigtable start --host-port=0.0.0.0:8086 &
              sleep 3
              cbt createtable v2Events "families=MessagePublication,QuorumState,TokenTransferPayload,AssetMetaPayload,NFTTransferPayload,TokenTransferDetails,ChainDetails"
              nc -lkp 2000 0.0.0.0

          readinessProbe:
            periodSeconds: 2
            failureThreshold: 300
            tcpSocket:
              port: 2000
          ports:
            - containerPort: 8086
              name: clients
              protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: pubsub-emulator
  name: pubsub-emulator
spec:
  ports:
  - name: listeners
    port: 8085
    targetPort: listeners
    protocol: TCP
  selector:
    app: pubsub-emulator
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: pubsub-emulator
  name: pubsub-emulator
spec:
  serviceName: pubsub-emulator
  replicas: 1
  selector:
    matchLabels:
      app: pubsub-emulator
  template:
    metadata:
      labels:
        app: pubsub-emulator
    spec:
      containers:
        - name: pubsub-emulator
          image: gcr.io/google.com/cloudsdktool/cloud-sdk@sha256:d7748afac2e3dc3768bfd0db16d26a7c538821146e433874acff0eb1cfd853ba
          env:
            - name: PUBSUB_EMULATOR_HOST
              value: localhost:8085
            - name: PUBSUB_PROJECT_ID
              value: local-dev
          command:
            - /bin/sh
            - -c
            - |
              gcloud --quiet components install beta pubsub-emulator
              gcloud --quiet beta emulators pubsub start --host-port=0.0.0.0:8085
          readinessProbe:
            periodSeconds: 2
            failureThreshold: 300
            tcpSocket:
              port: 8085
          ports:
            - containerPort: 8085
              name: listeners
              protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: bigtable-functions
  name: bigtable-functions
spec:
  ports:
  - name: functions
    port: 8090
    targetPort: functions
    protocol: TCP
  selector:
    app: bigtable-functions
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: cloud-functions
  name: cloud-functions
spec:
  serviceName: cloud-functions
  replicas: 1
  selector:
    matchLabels:
      app: cloud-functions
  template:
    metadata:
      labels:
        app: cloud-functions
    spec:
      containers:
        - name: cloud-functions
          image: cloud-functions
          env:
            - name: BIGTABLE_EMULATOR_HOST
              value: bigtable-emulator:8086
            - name: PUBSUB_EMULATOR_HOST
              value: pubsub-emulator:8085
            - name: GCP_PROJECT
              value: local-dev
            - name: BIGTABLE_INSTANCE
              value: wormhole
            - name: PUBSUB_NEW_VAA_TOPIC
              value: new-vaa-devnet
            - name: PUBSUB_NEW_VAA_SUBSCRIPTION
              value: extract-payload-devnet
            - name: PUBSUB_TOKEN_TRANSFER_DETAILS_TOPIC
              value: create-token-transfer-details-devnet
            - name: PUBSUB_TOKEN_TRANSFER_DETAILS_SUBSCRIPTION
              value: calculate-transfer-data-devnet
          ports:
            - containerPort: 8080
              name: functions
              protocol: TCP
          readinessProbe:
            httpGet:
              port: 8080
              path: /readyz
