apiVersion: apps/v1
kind: Deployment
metadata:
  name: accounts-api
  namespace: accounts-api
spec:
  replicas: 1
  minReadySeconds: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  selector:
    matchLabels:
      app: accounts-api
  template:
    metadata:
      labels:
        app: accounts-api
    spec:
      containers:
        - name: server
          image: ghcr.io/httptoolkit/accounts-api:latest # GHA replaces :latest on build
          ports:
            - containerPort: 4000
          readinessProbe:
            httpGet:
              path: /api/health
              port: 4000
            initialDelaySeconds: 3
            periodSeconds: 3
            failureThreshold: 3
          env:
            - name: PORT
              value: "4000"
            - name: NODE_ENV
              value: "production"
            - name: LOGLEVEL
              value: "debug"
            - name: ORIGIN_REGEX
              value: ".*"

            - name: SIGNING_PRIVATE_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: SIGNING_PRIVATE_KEY

            # Database connection:
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: DATABASE_URL

            - name: DATABASE_CA_CERT
              value: |
                -----BEGIN CERTIFICATE-----
                MIIDYDCCAkigAwIBAgIUGd62Hg2Hs4McPZwuBc4/FjmwF7UwDQYJKoZIhvcNAQEL
                BQAwVjELMAkGA1UEBhMCRlIxDjAMBgNVBAgMBVBhcmlzMQ4wDAYDVQQHDAVQYXJp
                czERMA8GA1UECgwIU2NhbGV3YXkxFDASBgNVBAMMCzE3Mi4xNi40LjExMB4XDTI2
                MDEwODEwNTgwMloXDTM2MDEwNjEwNTgwMlowVjELMAkGA1UEBhMCRlIxDjAMBgNV
                BAgMBVBhcmlzMQ4wDAYDVQQHDAVQYXJpczERMA8GA1UECgwIU2NhbGV3YXkxFDAS
                BgNVBAMMCzE3Mi4xNi40LjExMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC
                AQEAsHSp4wUDJFqSO9gK9PgNsXk6zfp4hSQktYcwMHjWlB7qxiY5mP/v1jvDHbQB
                NfvwzVb1DQiVUqubJ9G6tG0v5Yl9dWvoKhpSJAxysb9S32Ynf4mTf8QeSzzw8i9s
                lf9A0+2fMQshjxbZUAfbp5SvHmIGMhs6wsZHN6WCMmTwaSpa9s+c7kKwHN+rmiPM
                fSl23IixMXglHUyi6lNNHvS5qEUI2CI5h5v/7KDtq6Tby+75M58NOSABnYENf/5g
                LO5QP6Q5aA6hn8ah2cqp3nNFssmjkl+FYa15cBTeyte+jaQ+c57H6Un8ITLLiTMD
                24gjanFkidO6CATYlrcQ/IcZGQIDAQABoyYwJDAiBgNVHREEGzAZggsxNzIuMTYu
                NC4xMYcEM55K1IcErBAECzANBgkqhkiG9w0BAQsFAAOCAQEAPgNRRwPIvn29/WkY
                Ki9qH+NfqBjoWQwr5IbSlZHffu3FYpcLFqA+8fUdExP6ENt71Um2zKV+qaNm2f0X
                gJ8xQJoOvVfDkBtW+b3XbLyFO+Av09GL+jrpgdsjqiYrJFwPP2gDNYmvy7CNDer3
                JmYFZsBdjvXlLGXlMo2u7xG7Op018uZjLd7IHSDD+FmAVSTsahoaYnaW/2ul2OgA
                XSytaOHUQtzOMQxEem+csezGA2Sm+wSAZETOUVBOnlX48YFvc8Kx+AqnUPH8HC8h
                6DYp59qvreqNlUsimyjCs/zMjDl6uiznHXip8uobUkpNFZYYOeyYIsuz6Uw+p6M2
                2ui4yw==
                -----END CERTIFICATE-----

            # Email setup:
            - name: CONTACT_FORM_DESTINATION
              value: "tim@httptoolkit.com"
            - name: SMTP_HOST
              value: smtp.tem.scaleway.com
            - name: SMTP_PORT
              value: "2465"
            - name: SMTP_USERNAME
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: SMTP_USERNAME
            - name: SMTP_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: SMTP_PASSWORD

            # Auth0:
            - name: AUTH0_DOMAIN
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: AUTH0_DOMAIN
            - name: AUTH0_APP_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: AUTH0_APP_CLIENT_ID
            - name: AUTH0_APP_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: AUTH0_APP_CLIENT_SECRET
            - name: AUTH0_MGMT_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: AUTH0_MGMT_CLIENT_ID
            - name: AUTH0_MGMT_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: AUTH0_MGMT_CLIENT_SECRET

            # Paddle
            - name: PADDLE_ID
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PADDLE_ID
            - name: PADDLE_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PADDLE_KEY
            - name: PADDLE_PUBLIC_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PADDLE_PUBLIC_KEY

            # PayPro
            - name: PAYPRO_ACCOUNT_ID
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PAYPRO_ACCOUNT_ID
            - name: PAYPRO_API_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PAYPRO_API_KEY
            - name: PAYPRO_IPN_VALIDATION_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PAYPRO_IPN_VALIDATION_KEY
            - name: PAYPRO_PARAM_IV
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PAYPRO_PARAM_IV
            - name: PAYPRO_PARAM_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PAYPRO_PARAM_KEY

            # Assorted external API keys:
            - name: EXCHANGE_RATE_API_TOKEN
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: EXCHANGE_RATE_API_TOKEN
            - name: IP_API_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: IP_API_KEY
            - name: POSTHOG_KEY
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: POSTHOG_KEY
            - name: SENTRY_DSN
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: SENTRY_DSN
            - name: PROFITWELL_PRIVATE_TOKEN
              valueFrom:
                secretKeyRef:
                  name: accounts-api-secrets
                  key: PROFITWELL_PRIVATE_TOKEN
