apiVersion: apps/v1
kind: Deployment
metadata:
  name: flxn-app
  labels:
    app: flxn
    component: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flxn
      component: app
  template:
    metadata:
      labels:
        app: flxn
        component: app
    spec:
      containers:
      - name: flxn-app
        image: git.yohler.net/kyle/flxn-app:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 3000
          name: http
          protocol: TCP
        env:
        - name: VITE_API_DOMAIN
          valueFrom:
            configMapKeyRef:
              name: flxn-config
              key: vite_api_domain
        - name: VITE_WEBSITE_DOMAIN
          valueFrom:
            configMapKeyRef:
              name: flxn-config
              key: vite_website_domain
        - name: SUPERTOKENS_URI
          valueFrom:
            configMapKeyRef:
              name: flxn-config
              key: supertokens_uri
        - name: POCKETBASE_URL
          valueFrom:
            configMapKeyRef:
              name: flxn-config
              key: pocketbase_url
        - name: SUPERTOKENS_API_KEY
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: supertokens_api_key
        - name: PORT
          value: "3000"
        - name: NODE_ENV
          value: "production"

        - name: TWILIO_ACCOUNT_SID
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: twilio_account_sid
        - name: TWILIO_AUTH_TOKEN
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: twilio_auth_token
        - name: TWILIO_SERVICE_SID
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: twilio_service_sid
        - name: POCKETBASE_ADMIN_EMAIL
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: pocketbase_admin_email
        - name: POCKETBASE_ADMIN_PASSWORD
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: pocketbase_admin_password
        - name: VITE_SPOTIFY_CLIENT_ID
          valueFrom:
            configMapKeyRef:
              name: flxn-config
              key: vite_spotify_client_id
        - name: SPOTIFY_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: flxn-secrets
              key: spotify_client_secret
        - name: VITE_SPOTIFY_REDIRECT_URI
          valueFrom:
            configMapKeyRef:
              name: flxn-config
              key: vite_spotify_redirect_uri

        resources:
          requests:
            memory: "768Mi"
            cpu: "250m"
          limits:
            memory: "1536Mi"
            cpu: "1000m"

        livenessProbe:
          httpGet:
            path: /api/health
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 30
          timeoutSeconds: 5
          failureThreshold: 3

        readinessProbe:
          httpGet:
            path: /api/health
            port: 3000
          initialDelaySeconds: 10
          periodSeconds: 10
          timeoutSeconds: 3
          failureThreshold: 3
