# Bookstore Platform v2: Part 13 ch.06: the payments-gateway Deployment
# (PAYMENTS_MODE=gateway). The webhook-receiver variant uses the SAME image
# with PAYMENTS_MODE=webhook-receiver: see
# ../../payments/payments-webhook-receiver.yaml.
#
# The Stripe key comes from the stripe-api-key Secret that ESO writes from
# Vault (../../payments/stripe-eso-externalsecret.yaml). No literal Secret
# lives in this file.
#
# Apply:
#   kubectl apply -f examples/bookstore-platform/app/payments-gateway/deployment.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: payments-gateway
  namespace: bookstore-platform-payments
  labels:
    app.kubernetes.io/part-of: bookstore-platform
    app.kubernetes.io/component: payments-gateway
automountServiceAccountToken: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: payments-gateway
  namespace: bookstore-platform-payments
  labels:
    app: payments-gateway
    app.kubernetes.io/part-of: bookstore-platform
    app.kubernetes.io/component: payments-gateway
spec:
  replicas: 2
  selector:
    matchLabels:
      app: payments-gateway
  template:
    metadata:
      labels:
        app: payments-gateway
        app.kubernetes.io/part-of: bookstore-platform
    spec:
      serviceAccountName: payments-gateway
      automountServiceAccountToken: false
      securityContext:
        runAsNonRoot: true
        runAsUser: 65532
        runAsGroup: 65532
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: payments-gateway
          image: bookstore-platform/payments-gateway:dev
          imagePullPolicy: IfNotPresent
          env:
            - { name: PAYMENTS_MODE, value: "gateway" }
            - { name: PORT,          value: "8080" }
            # STRIPE_API_BASE stays empty against real Stripe. On the lab it
            # points at stripe-mock (payments/stripe-mock.yaml).
            - { name: STRIPE_API_BASE, value: "" }
            - name: STRIPE_KEY
              valueFrom:
                secretKeyRef:
                  name: stripe-api-key
                  key: api-key
          ports:
            - { containerPort: 8080, name: http }
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              memory: 128Mi
          livenessProbe:
            httpGet: { path: /healthz, port: 8080 }
            initialDelaySeconds: 5
            periodSeconds: 10
            failureThreshold: 3
          readinessProbe:
            httpGet: { path: /readyz, port: 8080 }
            initialDelaySeconds: 5
            periodSeconds: 10
            failureThreshold: 3
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: ["ALL"]
          volumeMounts:
            - name: tmp
              mountPath: /tmp
      volumes:
        - name: tmp
          emptyDir: {}
